Controlling graphical 128×64 LCD based on KS0108
-->HQM1286404 is pretty old graphical LCD module but it is still popular. This LCD is controlled by KS0108 lcd controller via two segment drivers. LCD backlight color is yellow-green. I think this is good choice for many projects where graphical information needed because of several reasons – you can find libraries around the internet to start working in just a few minutes, also there are several tools that can be used to generate character arrays and graphics.


Hardest thing for me was to find correct wiring as datasheet I have was for next PCB revision (HQM1286405) as mine are HQM1286404 so dont be mistaken as I did. Here is the correct pin-out of LCD:
1 Vcc
2 GND
3 VCON
4-11 DB0-DB7
12 CS2
13 CS1
14 RESET
15 R/W
16 D/I
17 EN
18 Vee out
19 LED Anode
20 LED Kathode
And circuit part how it is connected to my Atmega8:
You can see that Chip select pins are in reverse order, so if halves of screen are swapped, then you have to swap wires. At VEE pin should be negative voltage near -4.9V. Potentiometer through VCON pin controls LCD contrast. Reset pin can be connected directly to microcontrollers reset circuit. In my case it is separate. Backlight LED can also be adjusted with another potentiometer – is not included here too.
When circuit is ready, it is time to give a try. For this I recommend to download KS0108 Library which can be found in the internet. I tried several, and only one was working correctly. Without digging to deep use it for now. Library is written pretty some time ago by Fabian Maximilian Thiele. As his site link is dead you can download it from here: KS0108 Library.
Good thing with this library is that it is easy to add new characters. Just download GLCDFontCreator2 and with this java program you can fetch fonts from you windows system and automatically convert them to character arrays and save them in .h format ready to include to project. Simple examples you will find in library. I added simple bitmap display function to it which allows to display 128×64 graphics. I convert bmp files to character arrays with fastlcd.zip program. This program exports to .bas file, but it is easy to change to c compatible data – simply open generated file with notepad and select replace &h to 0x, then you can copy array data to c program.

Here is my example which displays simple graphics on LCD: Bitmap dispalay demo program is ready to be compiled with latest WinAVR and flashed to Atmega8 via avrdude.
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
| New on WinAVR Tutorial | New on WinARM Tutorial |

August 2nd, 2007 at 6:47 am
I tried compiling your code with latest version of WinAVR, but I am getting following error.
/usr/bin/sh: avr-sizex: command not found
make.exe: *** [sizeafter] Error 127
> Process Exit Code: 2
> Time Taken: 00:01
How do I solve it?
August 2nd, 2007 at 11:46 am
This error pops after compilation. This means that compilation was successful. I have updated Makefile with newer version;, where this error doesn’t show up.
September 10th, 2007 at 11:44 pm
[...] graphical 128×64 LCD based on KS0108 – [Link] Filed in Mcu, Interface, [...]
September 11th, 2007 at 7:47 am
Great article. I am working on a very simular display with the Arduino. I was just starting to work on the character display funcitons. Your article will help me greatly. Thanks!
April 13th, 2008 at 7:27 pm
[...] After a little compile/test/run/compile, I remember an old post on a website about KS108 chips. I find it back, it’s on the science prog [...]
April 14th, 2008 at 7:27 pm
It seems your pinout for CS1/CS2 is wrong way, the signals are inverted
April 15th, 2008 at 12:42 pm
No CS1/CS2 is connected correctly. Check out my board where same order is used:
http://www.scienceprog.com/diy-avr-graphical-lcd-test-board/
April 15th, 2008 at 6:15 pm
I tested again and I’m pretty sure pin12 is CS1, pin13 CS2. They are active low. You possibly dont see a difference if you change connection and handle them as active high. You see the difference when you activate _both_ signals so that both half sides of the display will be controlled together.
May 17th, 2008 at 2:08 pm
Hello All,
I tried to print messages on the lcd screen using ks108 library but not working . Can you please tell me how i can do that. i also tried test example of this library still not working. How i can convert colored bmp image into hex file so that i can get display it onto the display in monochrome.
mukesh
July 5th, 2008 at 4:53 pm
[...] Incredibile article and code library. [...]
July 21st, 2008 at 12:52 pm
Nice article, it helps me more on shifting 8051 to AVR.
September 2nd, 2008 at 7:29 am
Guys i’m working on a 122*32 graphical lcd.(18 pins).
i’ve got all my hardware and initializing correct but still i’m unable to get even a pixel on. I’m using Freescale MC9S08DN60 controller.
can someone help me with the exact sequence of initialization and yes better if with the writing a command or reading it from lcd.
May 27th, 2009 at 9:04 am
Hi,
Is there a way to get the complete code for this project and I’m trying to cut on development time. I need to use at least an atmega32 so I will have to have access to edit the source of the object files.
TIA
Vic
June 4th, 2009 at 12:18 am
I’m using ATmega8, connection is triple checked, and it’s not working! I’m using Lumex LCD module.
July 30th, 2009 at 12:28 pm
Iam using LGM12864B display and atmega16 controller. can any one help me please
thank you
January 23rd, 2010 at 1:16 pm
thanks man, your article had help me a lot much.