Get Adobe Flash player
FacebookTwitterGoogle+
English Arabic French German Italian Portuguese Russian Spanish

Did you know?

An electric oven uses one kilowatt-hour of electricity in about 20 minutes, but one kilowatt-hour will power a TV for 3 hours, run a 100-watt bulb for 12 hours, and keep an electric clock ticking for 3 months.
 

Help us stay online:

small donate

lcdMore microcontroller devices are using 'smart LCD' displays to output visual information. The following discussion covers the connection of a Hitachi LCD display to a PIC microcontroller. LCD displays designed around Hitachi's LCD HD44780 module, are inexpensive, easy to use, and it is even possible to produce a readout using the 8 x 80 pixels of the display. Hitachi LCD displays have a standard ASCII set of characters plus Japanese, Greek and mathematical symbols.

For a 8-bit data bus, the display requires a +5V supply plus 11 I/O lines. For a 4-bit data bus it only requires the supply lines plus seven extra lines. When the LCD display is not enabled, data lines are tri-state which means they are in a state of high impendance (as though they are disconnected) and this means they do not interfere with the operation of the microcontroller when the display is not being addressed. 


The LCD also requires 3 "control" lines from the microcontroller.

Enable (E) This  line allows access to the display through R/W and RS lines. When this line is low, the LCD is disabled and ignores signals from R/W and RS. When (E) line is high, the LCD checks the state of the two control lines and responds accordingly.
Read/Write (R/W) This line determines the direction of data between the LCD and microcontroller. When it is low, data is written to the LCD. When it is high, data is read from the LCD.
Register select (RS) With the help of this line, the LCD interprets the type of data on data lines. When it is low, an instruction is being written to the LCD. When it is high, a character is being written to the LCD.

Logic status on control lines:



E     0 Access to LCD disabled
       1 Access to LCD enabled

R/W 0 Writing data to LCD
       1 Reading data from LCD

RS    0 Instruction
       1 Character

Pin assignment

The pin assignment shown in Table 1. is the industry standard for character LCD-modules with a maximum of 80 characters.

To be sure always check the manufacturers datasheet!
To locate pin 1 on a module check the manufacturers datasheet!

Table 1., Pin assignment for <= 80 character displays
Pin numberSymbolLevelI/OFunction
1 Vss - - Power supply (GND)
2 Vcc - - Power supply (+5V)
3 Vee - - Contrast adjust
4 RS 0/1 I 0 = Instruction input
1 = Data input
5 R/W 0/1 I 0 = Write to LCD module
1 = Read from LCD module
6 E 1, 1-->0 I Enable signal
7 DB0 0/1 I/O Data bus line 0 (LSB)
8 DB1 0/1 I/O Data bus line 1
9 DB2 0/1 I/O Data bus line 2
10 DB3 0/1 I/O Data bus line 3
11 DB4 0/1 I/O Data bus line 4
12 DB5 0/1 I/O Data bus line 5
13 DB6 0/1 I/O Data bus line 6
14 DB7 0/1 I/O Data bus line 7 (MSB)
15 LED + - - LED +
16 LED - - - LED -

Note: check LED background polarity. On some displays it is reversed. (LED+ and LED- are switched)

 

Below is provided block diagram of how to connect LCD display to microcontroller. Do not forget to connect Vee pin for contrast adjustment to potentiometer or else you will see no data on screen.

 

2x16 LCD conection

Instruction set

Table 2. HD44780 instruction set
InstructionCodeDescriptionExecution time**
RSR/WDB7DB6DB5DB4DB3DB2DB1DB0
Clear display 0 0 0 0 0 0 0 0 0 1 Clears display and returns cursor to the home position (address 0). 1.64mS
Cursor home 0 0 0 0 0 0 0 0 1 * Returns cursor to home position (address 0). Also returns display being shifted to the original position. DDRAM contents remains unchanged. 1.64mS
Entry mode set 0 0 0 0 0 0 0 1 I/D S Sets cursor move direction (I/D), specifies to shift the display (S). These operations are performed during data read/write. 40uS
Display On/Off control 0 0 0 0 0 0 1 D C B Sets On/Off of all display (D), cursor On/Off (C) and blink of cursor position character (B). 40uS
Cursor/display shift 0 0 0 0 0 1 S/C R/L * * Sets cursor-move or display-shift (S/C), shift direction (R/L). DDRAM contents remains unchanged. 40uS
Function set 0 0 0 0 1 DL N F * * Sets interface data length (DL), number of display line (N) and character font(F). 40uS
Set CGRAM address 0 0 0 1 CGRAM address Sets the CGRAM address. CGRAM data is sent and received after this setting. 40uS
Set DDRAM address 0 0 1 DDRAM address Sets the DDRAM address. DDRAM data is sent and received after this setting. 40uS
Read busy-flag and address counter 0 1 BF CGRAM / DDRAM address Reads Busy-flag (BF) indicating internal operation is being performed and reads CGRAM or DDRAM address counter contents (depending on previous instruction). 0uS
Write to CGRAM or DDRAM 1 0 write data Writes data to CGRAM or DDRAM. 40uS
Read from CGRAM or DDRAM 1 1 read data Reads data from CGRAM or DDRAM. 40uS

Remarks:
- DDRAM = Display Data RAM.
- CGRAM = Character Generator RAM.
- DDRAM address corresponds to cursor position.
- * = Don't care.
- ** = Based on Fosc = 250KHz.

Table 3. Bit names
Bit nameSettings
I/D 0 = Decrement cursor position 1 = Increment cursor position
S 0 = No display shift 1 = Display shift
D 0 = Display off 1 = Display on
C 0 = Cursor off 1 = Cursor on
B 0 = Cursor blink off 1 = Cursor blink on
S/C 0 = Move cursor 1 = Shift display
R/L 0 = Shift left 1 = Shift right
DL 0 = 4-bit interface 1 = 8-bit interface
N 0 = 1/8 or 1/11 Duty (1 line) 1 = 1/16 Duty (2 lines)
F 0 = 5x7 dots 1 = 5x10 dots
BF 0 = Can accept instruction 1 = Internal operation in progress

1-line displays

Shown after reset (with N=0).

Table 4. DDRAM address usage for a 1-line LCD
Display sizeVisible
Character positionsDDRAM addresses
1*8 00..07 00h..07h
1*16 00..15 [1] [2] [3] 00h..0Fh
1*20 00..19 00h..13h
1*24 00..23 00h..17h
1*32 00..31 00h..1Fh
1*40 00..39 00h..27h

 

[1] Peter Bozzay:
Found DDRAM addresses 00h..07h + 40h..47h to be functional for a 1*16 display size.
Make/model: not mentioned / SC1601AS*B.
[2] Hendrik Abma:
Found DDRAM addresses 00h..07h + 40h..47h to be functional for a 1*16 display size.
Make/model: Samtron / KP-03.
[3] Luigi Candurro:
Found DDRAM addresses 00h..07h + 40h..47h to be functional for a 1*16 display size.
CMC116-01.

 

2-line displays

Shown after reset (with N=1).

Table 5. DDRAM address usage for a 2-line LCD
Display sizeVisible
Character positionsDDRAM addresses
2*16 00..15 [1] 00h..0Fh + 40h..4Fh
2*20 00..19 00h..13h + 40h..53h
2*24 00..23 00h..17h + 40h..57h
2*32 00..31 00h..1Fh + 40h..5Fh
2*40 00..39 00h..27h + 40h..67h

 

[1] Author:
According to their datasheets DDRAM addresses 80h..8Fh + C0h..CFh are used.
Make/model: Emerging Display Technologies/ EW162G0YMY
Make/model: Mitsutech EW162G0YMY

4-line displays

Shown after reset (with N=1).

Table 6. DDRAM address usage for a 4-line LCD
Display sizeVisible
Character positionsDDRAM addresses
4*16 00..15 [1] [2] 00h..0Fh + 40h..4Fh + 14h..23h + 54h..63h
4*20 00..19 00h..13h + 40h..53h + 14h..27h + 54h..67h
4*40 (00..39) on 1st controller and
(00..39) on 2nd
(00h..27h + 40h..67h) on 1st controller and
(00h..27h + 40h..67h) on 2nd


[1] Rick Mann:
Found DDRAM addresses 00h..0Fh + 40h..4Fh + 10h..1Fh + 50h..5Fh to be functional for a 4*16 display size.
Make/model: Optrex / DMC16433.
[2] Tushar Rane:
Found DDRAM addresses 00h..0Fh + 40h..4Fh + 10h..1Fh + 50h..5Fh to be functional for a 4*16 display size.
Make/model: not mentioned / not mentioned.

For proper initialization follow recommended routine.
Here are these routines for 8 and 4 bit mode

8-bit mode

lcd 2x16 8-bit init

4-bit mode

lcd 2x16 4-bit init

 

Writing of data to LCD custom characters space and usage of character display as graphic display is possible, but we will not discuss it here because it is rarely used and standard graphic LCD displays give much better results. Graphic 128x64 pixels LCD displays will be discussed in one of the next articles.

 

These are basic information that will help you understand how 2x16 character displays work and in next article we will give detailed example for microcontroller interface with character 2x16 LCD display written in Codevision C compiler. It has modular design which allows easy adaptation for any microcontroller family usage.

 

For proper initialization follow recommended routine.

Here are these routines for 8 and 4 bit mode