As with nearly all of my posts, this one too starts with a really cheap eBay buy (£1.25, example: http://goo.gl/oLn3pG – Link will expire!). The HD44780 LCD (Datasheet: http://goo.gl/zQDnLh) is a pretty versatile component supporting 16 characters and 2 rows, implementing some cool functions like display shift and text scrolling. It uses an 8bit or 4bit parallel interface and is pretty slow so works with nearly any microcontroller. It has its own inbuilt CGRAM (character generation RAM) which contains all standard characters plus a few more Chinese characters. It is possible to write your own characters to the CGRAM though I haven’t included this in my example and for most applications, it isn’t needed.
In my simple application, I’m initializing the screen and writing a string to the screen. I’ve also got a “Demo” function which causes the string “Hello World!” to bounce from left to right and back on the top row. Obviously a completely useless function, though somewhat cool!
The code for the LCD can be found on my github and I’ll link to that at the bottom of the page.
With regards to wiring, I merely soldered a standard pin header to my LCD and wired it up using a bread board! I need to implement a capacitive voltage inverter in the near future as the LCD doesn’t have enough contrast running at 3v. My solution to this was to run it at 5v as the LCD is currently only being used in read only mode anyway!
I’ve added a 120 ohm resistor in series with the backlight LED just in case it doesn’t have internal current limiting. The brightness could be controlled using a PWM module in the STM32F0, along potentially controlling the contrast too! To set the contrast, I use a 3.3k ohm resistor from the “Vo” terminal to ground. The rest is pretty simple wiring.
Talking of which, the wiring goes:
LCD Vss – Gnd
LCD Vdd – 5v
LCD Vo – Gnd through a 3.3k resistor
LCD Rs – GPIOA, Pin 0
LCD RW – Gnd
LCD En – GPIOA, Pin 1
LCD D4 – GPIOA, Pin 2
LCD D5 – GPIOA, Pin 3
LCD D6 – GPIOA, Pin 4
LCD D7 – GPIOA, Pin 5
A (LED anode) – 5v through a 120 ohm resistor
K (LED cathode) – Gnd
My github containing the Coocox project is: https://github.com/pyrohaz/STM32F0-HD44780LCD
In the future, I’ll probably be adding a capacitive voltage inverter using an STM32F0 GPIO pin and potentially upgrading to a 3 pin interface using a shift register!