Beruflich Dokumente
Kultur Dokumente
The Hitachi HD44780 is an LCD screen controller used to control small alphanumeric LCD
displays. Many cheaper displays don't actually use the HD44780 IC. However, they use the same
pin-out and control scheme, and therefore can be operated in the same manner.
1. Ground
2. Power (Normally 5V)
3. Contrast adjust (Connect to the wiper of a 10kOhm potentiometer from V CC to GND)
4. Register select (For a command RS = 0. For data RS = 1)
5. Read/Write (To write to the display = R/W = 0. To read = R/W = 1)
6. Enable
7. Data bit 0 (DB0)
8. Data bit 1 (DB1)
9. Data bit 2 (DB2)
10. Data bit 3 (DB3)
11. Data bit 4 (DB4)
12. Data bit 5 (DB5)
13. Data bit 6 (DB6)
14. Data bit 7 (DB7)
15. Backlight +
16. Backlight The screen has 3 main control lines. RS, R/W, and Enable. The RS and R/W lines determine the operation of the
screen, as shown in the table below.
RS
0
R/W
0
Operation
Write a command to the display. E.g. Clear display
Read the busy flag (Data bit 7) and the address counter (Data bits 0 to
6)
Write data to the display
The Enable line acts like a clock signal. To clock data in or out of the display the enable line
should be set high for 1uS. The enable signal is registered on the falling edge.
The screen has 8 data lines which are used to both read and write data to and from the display.
The screen can also operate with 4 data lines, where only DB4, DB5, DB6, and DB7 are used. In
this case DB0 to DB3 can be left unconnected. This article will only cover operation of the
display using all 8 data lines.
Setting up the display
Once the display is connected to the microcontroller, it needs to be correctly configured before it can be used. There
are several settings that configure how the display operates; these are set by issuing commands to the LCD.
To send a command to the LCD the microcontroller must first check if the screen is busy. If the screen is busy it will
ignore any commands sent to it. The pseudo code below shows how to check if the screen is busy.
Set data lines as inputs
Set R/W = 1
Set RS = 0
Set enable high
Wait 1uS
Set enable low
Read DB7
If DB7 is high then LCD busy, else if DB7 is low then LCD ready
Once the LCD is ready the microcontroller can send a command to the screen. The pseudo code
below shows how this is done.
Wait until the screen is not busy
Set data lines to outputs
Set R/W = 0
Set RS = 0
Set the 8 data lines to the desired command
Set enable high
Wait 1uS
Set enable low
Description
Return home
0 0
I/D S
Display on/off
0 0
Cursor/display shift
S/C R/L -
Function set
DL N
A A
A A A
The dash "-" means that it doesn't matter if the data bit is a 1 or 0. A is an address bit. The remaining bit
To initialise the display we need to send several configuration commands as shown in the pseudo code below.
Wait until the screen is not busy
Set data lines to outputs
Set R/W = 0
Set RS = 0
Set data lines to: 00111000 //Send "Function set" command. Sets display
to
8 wire mode, 2 lines and 5x8 dots.
Set enable high
Wait 1uS
Set enable low
When "H" is entered the cursor automatically moves one character to the right. This means that
when "I" is entered it appears to the right of "H".
If you were to keep entering more characters the cursor would eventually disappear off the edge
of the screen. Characters will still be written to the LCD, but they will not be visible. This is
because while the screen may only have space for 16 (or 8) characters on each line, the controller
actually has space to store 80 characters in its memory.
A map of the display's memory (DDRAM) is shown below for the 4 most common LCD sizes.
To set the position of the cursor use the "Set DDRAM address" command from the command
table further up the page. The pseudo code below shows how the cursor position can be set.
Wait until the screen is not busy
Set R/W = 0
Set RS = 0
Set data lines to: 10000000 //Set DDRAM address. Cursor to Row 1, column 1
Set enable high
Wait 1uS
Set enable low
Wait until the screen is not busy
Set R/W = 0
Set R/S = 1
Set data lines to 01001000 //ASCII code for "H"
Set enable high
Wait 1uS
Set enable low
Wait until the screen is not busy
Set data lines to outputs
Set R/W = 0
Set RS = 0
Set data lines to: 11000000 //Set DDRAM address. Cursor to Row 2, column 1
Set enable high
Wait 1uS
Set enable low
Wait until the screen is not busy
Set R/W = 0
Set R/S = 1Set data lines to 01001001 //ASCII code for "I"
Set enable high
Wait 1uS
Set enable low
This will print "H" on row 1 and a "I" underneath it.
Using the "Cursor/Display shift" command (see table further up the page) the cursor or screen can be moved left or
right by one position. If the display is shifted the DDRAM addresses that are visible will change. This is shown in
the image below.
The shift of the display can be reset by sending the "Return home" command (see command
table further up the page).
Symbols are sent to the screen in the same way as normal characters, as shown below.
Wait until the screen is not busy
Set data lines to outputs
Set R/W = 0
Set R/S = 1
Set data lines to 10011000 //Code for a bell symbol
Set enable high
Wait 1uS
Set enable low
If the symbols do not match either the European or Asian character sets then the display is using
a custom character set. In this case refer to the datasheet of the LCD display.
Generating custom LCD characters
Sometimes it is necessary to display characters that are not part of the default character set. The
HD44780 has space for 8 custom characters (5x8 dots) which can be displayed on the screen.
(For 5x10 dot displays please refer to page 19 of the Hitachi datasheet).
Each character requires 8 bytes of data, one for each of the 8 lines. The 3 MSBs of each byte are
ignored, with the remaining 5 bits setting whether the dots appears on or off in the symbol, this is
shown in the image below.
The CGRAM address of the first line of each of custom characters is shown in the table below.
The character code is also shown. This is the code used to display the symbol when it has already
been stored in the CGRAM.
Character
Custom 1
Custom 2
Custom 3
Custom 4
Custom 5
CGRAM Address
location
0100 0000 (ox40)
Character code
0000 0000
0000 0001
0000 0010
0000 0011
0000 0100
0000 0101
0000 0110
0000 0111
The pseudo code below shows how a custom symbol can be stored and then displayed on the
LCD screen.
Wait until the screen is not busy
//NB. this has been omitted from the rest
of this
code for clarity
Set data lines to outputs
Set R/W = 0
Set RS = 0
Set data lines to: 01000000 //Set the CGRAM address to line 1 of custom
character 1
Pulse enable
Set R/W = 0
Set RS = 1
Set data lines
Pulse enable
Set data lines
Pulse enable
Set data lines
Pulse enable
Set data lines
Pulse enable
Set data lines
Pulse enable
Set data lines
Pulse enable
Set data lines
Pulse enable
Set data lines
Pulse enable
Set R/W = 0
Set RS = 0
Set data lines to: 1000 0000
Pulse enable
Set R/W = 0
Set RS = 1
Set data lines to: 0000 0000
Pulse enable
An excellent web interface for designing custom characters can be found at quinapalus.com.
Interfacing an HD44780 LCD display with a PIC microcontroller
If you wish to use the HD44780 display with a PIC 16 microcontroller I have written a library that implements most
of the functions of the display. The code can be found here.
TODO
Add option to select between different screen sizes. I.e 16x4, 16x2, 16x1, 8x4, 8x2, 16x1. Currently only
16x2 is supported.
Add option to select between 8x5 dot and 10x5 dot displays.
Modify code so that it is easier to use the code with any PIC microcontroller.
Add option to select 4 wire mode.