Connecting and using an LCD module

This is the set of commands for all LCD panels which are driven with the HITACHI HD44780 controller, just check your panel for the chip.

The LCD panels can driven by 4 or 8 bits. There is also 3 control lines - EN (Enable), D/I (Data/Instruction) and R/W (Read/Write).
To connect with a minimum of wires you need 4+3 I/O lines in 4 bit mode.

Sequence for signals is as follows

               1st         2nd
               ____        ____
EN        ____|    |______|    |_____
              ____        ____
Data      ___|____|______|____|______
(4bit mode)   d4-d7        d3-d0


The LCD panel is drived by a HITACHI controller HD44780 (panel ref: LM054, LM016L, LM020L, LM041L, LM032L, LM044L, LM243A, LM027, LM23A, LM017L, LM018L, etc ...).

Commands can be sent in frames of 4 or 8 bits. A reset puts the panel in 8 bit mode. 4 bit mode uses only bits B4 - B7.

LCD Commands:


Exec.   DI RW b7 b6 b5 b4 b3 b2 b1 b0
1,52ms  0  0  0  0  0  0  0  0  0  1  Reset LCD Panel, Erase RAM
1,52ms  0  0  0  0  0  0  0  0  1  -  Cursor + AC=0, Display in origin position
37us    0  0  0  0  0  0  0  1 I/D S  Define cursor movment and shift display
37us    0  0  0  0  0  0  1  D  C  S  Display ON/OFF(D), cursor(C) and blonk
at                                       cursor position(B)
37us    0  0  0  0  0  1 S/L R/L-  -  Move the cursor and shift display
37us    0  0  0  0  1  DL N  F  -  -  Define bus length (DL), number of
line,                                         matrix font used (5x8 or 5x10)
37us    0  0  0  1  CG RAM Address    Define CG RAM Address
37us    0  0  1     DD RAM Address    Define DD RAM Address
0us     0  1  BF  Address counter AC  Read busy Flag & AC
37us    1  0     Write DATA           Write DATA into DD or CG RAM
37us    1  1     Read DATA            Read DATA from DD or CG RAM

Legend:

I/D = 1: Increment, I/D = 0 : Decrement
S = 1: Shift display
R/L = 1: Shift to the right; R/L = 0 : Shift to the left
DL = 1: 8 Bits; DL = 0 : 4 Bits
N = 1: 2 or 4 lines; N = 0 : 1 line
F = 1: 5x10 matrix; F = 0 : 5x8 matrix
BF = 1: Busy; BF = 0 : free, can receive an instruction
DD Ram: Data Display RAM
CG Ram: Character Generator RAM

Execution time is given for a 270khz clock frequency (250-270Khz seems to be the average value for current LCD panel).

RAM is not continuous, the mapping depends how many characters and lines there are in the panel. You can also define your own characters (CG RAM), only 8 can be defined:

for 16x1:
1st line: 00h 01h ... 27h


for 16x2:
1st line: 00h 01h ... 27h
2nd line 40h 41h ... 67h


Plain text version of this page.

Click here for a working piece of 8 bit LCD driver code. When run it should display
mwr  0000

and then start counting up. The code demostrates a lookup table for the text, the handshaking routine for writing to the display and indirect addressing to display the digits. To connect up the display, refer to the declarations in the header.