HD44780 LC Display

Hardware

Many LC displays used today are based on a HD44780 (or compatible) controller. See AVR Thermometer for example. They can easily be interfaced to a microcontroller because of their simple parallel interface. They can display letters, numbers and a few special characters in 5 × 7 pixels. Additionally you can program 8 characters by yourself.

I/O Pins

The following is an overview of the i/o-pins of the display. The pin names are the ones often used in the displays datasheets.

D0 - D7  bidirectional data

RS       select data or instruction register

         low: instruction register if writing, busy flag and address counter
         when reading

         high: data register to read and write display contents

R/W      select data direction, i.e. read or write

         high: read out the selected register

         low: Write to the selected register

E        This pin is used to clock the data transfer

         low → high: if reading the state of the RS and R/W-Line are taken over,
         if writing the state of the data lines is taken over

         high → low: if reading the data on the data lines is correct until this
         transition occurs

VCC      Supply, often 5V

GND      Ground

VEE      Contrast. It is often controlled by a potentiometer between VCC and GND
         with its middle pin connected to VEE. Attention: There are also
         displays which need a negative contrast voltage on this pin

Display Control

The display can be controlled over a 4- or 8-bit data bus (pin D4 - D7) and 3 status lines (RS, E, R/W). The width of the data bus can be selected during the initialization of the display by the mcu . So it is possible to save a few i/o-pins and control the display with only 7 i/o pins. In 4 bit mode every character needs 2 clock cycles so the display is a little bit slower than in 8 bit mode. But in most circumstances that does not matter.

To transmit data in 8 bit mode the data lines are set according to the bit pattern of the character or command, R/W is set to low and RS according to the right register. Now the level of E is brought from low to high and back to low. The data is taken over to the display with the falling edge of the E signal. For reading data it is the same procedure with the E signal but the R/W signal must be set high. In 4 bit mode it is quite the same as in 8 bit mode but at first the high nibble (bit 4-7) is transmitted and then the lower nibble (bit 0-3) in a second clock cycle.

Command Set

Apart from the codes to control the display contents there are a few commands to control the display mode. These are commands to switch the display on or off, to position the cursor, etc.

A 1 at a pin means a high level, i.e. a 5 volts signal, a 0 stands for low. The level of a pin marked with * stands for "don't care". A function of a pin marked with a character is described in the text of this command.

Clear Display and Reset

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  0  0  0  0  0  0  1

The content of the display is erased and the cursor is set back to the first character in the first row.

Set Cursor to Start Position

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  0  0  0  0  0  1  *

The Cursor is set to the first character position in the first row. If the display contents are shifted, the shifting function is switched off.

Cursor Direction and Display Shift

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  0  0  0  0  1  CD S

This command sets the moving direction of the cursor (CD=0: move to the left, CD=1: move to the right) and the display shift (S=0: no shift, S=1: display contents are shifted). Display shift means that the whole display content is moved by one character.

Display Mode

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  0  0  0  1  P  C  B

With this command the display can be switched on or off (P=0: display off, P=1: display on), the cursor can be displayed (C=0: cursor off, C=1: cursor on) and the cursor can be set to blinking (B=0: cursor always visible, B=1: blinking cursor).

Cursor Function

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  0  0  1  M  SD *  *

This command can be used to select whether the cursor should be moved after ever character written to the display or whether the display contents are shifted (M=0: move cursor, M=1: shift display) and which direction to shift the display (SD=0: shift to the left, SD=1: shift to the right).

Display Settings

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  0  1  BW N  F  *  *

It is possible to select if the data bus width is 4 bit or 8 bit (BW=0: 4 bit bus, BW=1: 8 bit bus), how much rows the display can show (N=0: 1 row, N=2: 2 rows) und what font should be used (F=0: 5 × 7 pixel, F=1: 5 × 10 pixel)

Address for Character Generator Memory

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   0  1  A5 A4 A3 A2 A1 A0

The address for the byte written next to character generator memory is selected (for creating user defined character).

Address in Data Memory

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  0   1  A6 A5 A4 A3 A2 A1 A0

The address for the byte written next to data generator memory is selected (for writing characters to the display).

Read Busy-Flag and Address Counter

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
0  1   BF A6 A5 A4 A3 A2 A1 A0

The busy flag (BF=0: display can process the next command) BF=1: display is busy) and the address counter of the recently used memory locationis returned.

Write Memory

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
1  0   D7 D6 D5 D4 D3 D2 D1 D0

The attached data is written to the at last selected memory.

Read Memory

RS R/W D7 D6 D5 D4 D3 D2 D1 D0 
1  1   D7 D6 D5 D4 D3 D2 D1 D0

The data of the memory selected before is returned.

Timing

Nearly all commands transmitted to the display need 40us for execution. Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position" These commands need 1,64ms for execution. These timings are valid for all displays working with an internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you can use the busy flag to test if the display is ready to accept the next command.

User Defined Characters

It is possible to define 8 characters by yourself. The pixel data of these characters is written to the character generator memory. Each character needs 8 byte but only the bits 0 to 4 of each byte are used to define the 5 pixels in every row. The first byte stands for the topmost row, the last one for the bottom row.

Initialization of the Display

After attaching the supply voltage or after a reset you should bring the display to a defined state. This can be done with the following procedure:

  • After attaching supply voltage wait approximately 15 ms until the display is ready to execute commands
  • Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now). The display is in 8 bit mode, so if you have only connected 4 data pins you should only transmit the higher nibble of each command.
  • If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now.
  • Execute the "clear display" command

Character Set

The character set of these displays corresponds for letters and numbers to the ASCII character set. So the digits '0' - '9' are between 0x30 and 0x39, the upper case letters 'A' - 'Z' between 0x41 and 0x5A and lower case letters 'a' - 'z' between 0x61 and 0x7A. The other character codes can differ between producers and should be looked up in the datasheet of the controller chip or display used.

LinkedIn logo mail logo