AVR library for lc7981

The information on this page is only for the DataVision DG-16080-11 lcd.
It may apply to your lcd, as well but this may not be the case.
If it doesn't work for your display, I am not going to make it work for you. That's your job.

Be sure your read this page completely. It contains information about setting up the hardware which are not covered in the sourcecode documentation.
Especially the paragraph that is entitled with Wiring stuff up.
Also make sure you have read the datasheet of your display and the datasheet for the lc7981.
I won't answer any more questions that can be resolved by reading this text, or the datasheets I mentioned above.

If you still want to ask me something, provide all your code and a proper schematic of your setup.
Otherwise I'll simply ignore you.
Ask your questions via email to ed.etis-snaitsabes@naitsabes.

If you think that was rude and unfriendly, I'll tell you something :
I've been working weeks on this library and you can have it for FREE.
All I ask of you now is to do your homework properly,
before telling me I'd have to fix the things I gave you for free.
In fact I don't even have to listen to you.

For those who didn't notice the mail address is reversed.

This page is kept in English to make it available to an international audience.


After discovering a quite cheap touchscreen lcd on the Roboternetz website,
I decided that such a display might be a useful addition to some of my projects.

Therefore I bought some of them and started to write a C-library to use them with an ATmega32.
All the other librarys available missed some of the features I needed or they had some inefficient code. (just my personal Opinion)


The result was a small and quite flexible library for the lc7981-chip which is used by this display.

Features :

  • Textmode with scrolling (just like a on linux console)
  • Graphicmode
  • Plotting bitmaps of any size anywhere you want
  • Plotting Text useing any Font you like anywhere
  • Setting and clearing single Pixels (the killerfature)

I can hear you say now : 'That's just like any other library out there. So where's the point in using yours ?'
The lc7981 has to ways of setting Pixels.
The first is using it's set pixel command.
The advantage of plotting a bitmap with this command is that you get a simple short sourcecode,
and it is easy to place a bitmap anywhere you like on the screen.
A big disadvantage of doing it this way is that you'll need to transfer 2byte per pixel.
Plotting a 10x10px bitmap will result in 200 bytes of data being send.
The other approach is to transfer a byte directly into the display memory.
One byte represents 8 pixel of a display row.
Using this approach, transferring the 10x10 bitmap will require 4 bytes per row,
which results in 40 bytes in total.
The major disadvantage is that it is difficult to place a bitmap on an X-coordinate
that isn't a multiple of 8.

My library uses the second approach in combination with some tricky bit shift operations
to be able to plot a bitmap fast and at every X-ccordinate.
It needs some more computing time, but I thinks it's a good trade-off.

Wiring stuff up

My primary aim was the use the DataVision DG-16080-11 lcd,
therefore I'll provide some info how I wired it up here.
Using a plain lc7981 with some other lcd would be beyond the scope of this document.
See the datasheet here for the display pinout.

Connect each one of RS, RW and EN to a free pin of your controller.
You'll have to specify the pins used in the lc7981.h.
RES (Reset) has to be high and CS has to be low, so they have to be connected to Vcc and Gnd.
The DB0-DB7 pins must be connect to one port of the AVR. Like for example PortB.
Connect DB0 to PB0, DB1 to PB1 and so on.

The Display supply voltage (pin 3) has to be connected to pin 17 and Gnd using a potentiometer.
The potentiometer will be used to adjust the contrast.
Just like it is done in this schematic by Flash2over.

I'll try to provide an own schematic as soon as possible.


The Versions below 0.6 beta were released under GPL.
All newer versions including 0.6 and above are/will be realeased under MPL.
I won't support the old GPLed versions anymore.

You may ask why I changed my license.
The answer is rather simple:
I used GPL since it wanted my library to profit from bugs that get fixed and features that get written
by other people who use it.
What I did not think about was the following scenario :
Somebody uses my lib in an automated garden irrigation for his carrots.
He does not change anything or adds any feature.
He just uses my work, but he has to publish his source under GPL.
(Just in case he wants to publish it.)
I don't see any advantages in that.
(Not that I don't like gardening or carrots, but I can't see a relation to my work here.)
So I cause additional work for this poor guy and take away his freedom to chose an own license
without any advantages for me, my work or him and his work.

This is simply not what I intended to do in the first place.

Okay, you might complain that I could have used LGPL instead of MPL.
But it's terms are rather unclear to me and the rule of thumb with dynamic and static linking stuff
is ridiculous when you use a mircocontroller where you have to use static linking.

Therefore I use MPL so I still can profit from changes made to my code,
but other can use it how they want as long as they don't change it.


All the files can be obtained here : https://github.com/LongHairedHacker/avr-lc7981/archive/master.zip
The documentation can be found here

If you need the (not supported and not maintained) GPL Version or the latest development version use git to clone https://github.com/LongHairedHacker/avr-lc7981
I would not recommend using the GPL version..

If you have any questions feel free to ask using my mail adress, that can be found in the source code.

Have fun with your display

First published : 12.4.2010 16:47:49 Last edit : 12.4.2010 16:47:49 Viewed by 26698 visitors.


Edmundo: (29.8.2011 9:44:48) permalink
Thanks, I´m professor in the "INSTITUO POLITECNICO NACIONAL" at MEXICO, just all the info my students needs to start. Very grateful.

Good information , very complete.

Thanks again

Jesus Palomo: (11.9.2011 2:15:54) permalink
Hi, I am student in the "Instituto Tecnologico de Toluca" at Mexico, you program and library very well, I compile in AVR Studio and worked well, Thanks for you info and post...Greetings from México

Dumitru Haivazu: (30.10.2011 17:46:59) permalink
Good job!!!
look in the lc7981 file and setup PORTS and DDR according to your schematics. Because in the image they are wrong... And don't forget to tie CS pin to GND. RESET you can leave unconnected.
Actually this library is the best from i have tried over the net. If someone knows something better, don't forget to share with us.

Thanks again to the author for his beautiful creation!!!

Sebastian: (30.10.2011 19:44:56) permalink

Please read the text above completely before complaining.
I clearly stated that the schematic is only example for wiring up the contrast voltage.

Please refer to lc7981.h or the text above the link for wiring up the rest.


hariz: (15.11.2011 20:13:21) permalink
I have a problem... i have used your library and display shows only one blinking line(if display contrast is increased everything starts "waving"...). i have double-checked my wiring and everything is ok.
I'm using Atmega16 with 16mhz clock and PG192128-B display (http://www.datasheetcatalog.org/datasheets/105/39854_DS.pdf)
I have grounded CS and left RST unconnected as Dumitru Haivazu said(coz i didn't found any information about them in your library )

i hope you could help me :)
i thank you in advance.

Sebastian: (15.11.2011 21:04:57) permalink
First of all :
That's an entirely different display module.
Mine has 160x80px where as yours has 192x128,
this means a lot of stuff for the initialization is different.
I've never tested this on any other display, so you'll have to read the datasheet an modify it yourself.

Second : I'm only going to say this ONE MORE TIME.
Read the paragraph about wiring stuff up in the above page.
Connect the pins like I explain it there.
Use the schematic only for connecting the contrast voltage.
I clearly stated there that RES (Reset) has to be high.
Leaving it unconnected can lead to random behavior.
Read that datasheet for the lc7981 if you don't believe me.


hariz: (15.11.2011 22:38:22) permalink
I'm sorry, i have overlooked your information about Reset.
I just fixed that and waving disappeared and nothing is displayed now.
But still i dont get it.. both lcd's have the same LSI driver, the materialization should be the same.. just parameters like H/V pixel count and text lines should be different. Am i wrong?

#define LCD_TEXT 0
#define LCD_TEXT_LINES 16

#define LCD_GRAPHIC 1

Sebastian: (15.11.2011 22:51:35) permalink
I'm afraid to tell you, but you are totally wrong.

Your display has more pixels hence is using a different memory chip.
Simply chancing the define-macros might work in a few cases, but mostly you'll need to change the parameters send to the display in lcd_init().
See the datasheet I mentioned above.