You are viewing an older revision! See the latest version

Text LCD

A driver code library for Text LCD panels using the 4-bit HD44780 lcd display driver.

/media/uploads/simon/textlcd-helloworld.jpg

Hello World!

Import program

00001 // Hello World! for the TextLCD
00002 
00003 #include "mbed.h"
00004 #include "TextLCD.h"
00005 
00006 TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
00007 
00008 int main() {
00009     lcd.printf("Hello World!\n");
00010 }
Pin numberTextLCD pinsmbed pins
1GND0V
2VCC3.3V
3VO0V, via 1k resistor
4RSp15
5RW0V
6Ep16
7D0not connected
8D1not connected
9D2not connected
10D3not connected
11D4p17
12D5p18
13D6p19
14D7p20

Warning

The contrast VO pin seems to have different behaviour on different displays, so you may need to experiment for your display to see anything. I think I've seen some work tied to 0V, some to 3.3V, or with a different resistor.

Adjustable contrast can be achieved with a 10k trim-pot in a voltage divider configuration: one side to Vcc, other side to GND, wiper to VO. Adjust until you see a line of solid squares, then back off until they just disappear.

Some displays need a negative voltage at VO. One side of the trimpot is connected to the negative voltage instead of GND in that case. F.i. a Maxim MAX1044 can be used to generate the negative voltage.

Text LCD Library

Import library

Public Types

enum LCDType { LCD16x2 , LCD16x2B , LCD20x2 , LCD20x4 }

LCD panel format.

More...

Public Member Functions

TextLCD (PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type=LCD16x2)
Create a TextLCD interface.
int putc (int c)
Write a character to the LCD.
int printf (const char *format,...)
Write a formated string to the LCD.
void locate (int column, int row)
Locate to a screen column and row.
void cls ()
Clear the screen and locate to 0,0.

Different LCD Panel Sizes

Setting the type field int the TextLCD constructor allows configuration for the different display panel sizes:

TextLCD::LCD16x2     16x2 LCD panel (default) 
TextLCD::LCD16x2B    16x2 LCD panel alternate addressing 
TextLCD::LCD20x2     20x2 LCD panel 
TextLCD::LCD20x4     20x4 LCD panel 

Note: There is now support for
LCD8x1   8x1 LCD panel
LCD8x2   8x2 LCD panel
LCD16x4  16x4 LCD panel
LCD24x2  24x2 LCD panel
LCD40x2  40x2 LCD panel
You can find the new lib here: http://mbed.org/users/wim/code/TextLCD/

For example:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7

int main() {
    lcd.printf("Hello World!\n");
}

Reference

The underlying HD44780 chip is a driver used in many LCD character displays. It might sometimes be referred to as Hitachi HD44780U. There are also several compatible clones of this chip in use.


All wikipages