CLEARING THE DISPLAY
CLEAR_LCD:
CLR RS
MOV A,#01h
LCALL WRITE_2_NIBBLES ;Write A as two separate nibbles to LCD
LCALL WAIT_LCD
RET
|
WRITING TEXT TO THE LCD
WRITE_TEXT:
SETB RS
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
RET
|
THE "HELLO WORLD" PROGRAM
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT
|
The above "Hello World" program should, when executed, initialise the LCD, clear the LCD screen, and display
"Hello World" in the upper left-hand corner of the display. As you see, no difference in this routine with
the 8bit drive routines.
CURSOR POSITIONING
Let's again, write the word 'world' on the second line now, from the tenth position:
LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
CLR RS
MOV A,#0C9h
LCALL WRITE_2_NIBBLES
LCALL WAIT_LCD
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT
|
SUMMARY
This tutorial has presented the underlying concepts of programming an LCD display in 4bit modus. If things in
this document are not clear, please be sure to read again the first tutorial on using LCD modules.
MORE BACKGROUND INFORMATION ABOUT DIFFERENT SIZED LCD MODULES
The HD44780 or compatible controller is basically designed to build LCDisplays with one or two lines with a
maximum of 40 characterpositions each. A single HD44780 is able to display two lines of 8 characters each.
If we want more, the HD44780 has to be expanded with one or more expansion chips, like the HD 44100 (2 x 8
characters expansion) or the HD 66100 (2 x 16 characters expansion). Seen from the HD44780, the first line
starts with 00h; the second line with 40h.
LAYOUT OF DISPLAY MODULES WITHOUT EXPANSION CHIP(S):
- 8 characters x 1 line
| First Line: |
00 01 02 03 04 05 06 07 |
The module has to be initialised as a ONE line display.
- 8 characters x 2 lines
First Line: Second Line: |
00 01 02 03 04 05 06 07
40 41 42 43 44 45 46 47 |
To use the second line, don't forget to initialise the display as a TWO lines display.
- 16 characters x 1 line
| First Line: |
00 01 02 03 04 05 06 07 40 41 42 43 44 45 46 47 |
In fact, in this case the two lines are placed one after another. So when we want to use the display from
the ninth position, it has to be initialised as if it were a TWO lines display! Mind the ninth position is
addressed as 40h, not 08h.
LAYOUT OF DISPLAY MODULES WITH EXPANSION CHIP(S)
- 16 characters x 1 line
| First Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |
On the outside this module looks the same like #3 above, but all characterpositions are addressed continuously.
The module has to be initialised as a ONE-line display.
- 20 characters x 1 line
| First Line: |
00 01 02 03 04 05 06 07 08 09 40 41 42 43 44 45 46 47 48 49 |
In fact, from HD44780 point of view, in this case two lines are placed one after another. So when
we want to use the display from the eleventh position, it has to be initialised as if it were a TWO
lines display! Mind the eleventh position is addressed as 40h, not 0Ah.
- 40 characters x 1 line
| First Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11...27 |
The module has to be initialised as a TWO lines display, if we also want to use the second line.
- 24 characters x 2 lines
First Line: Second Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 |
The module has to be initialised as a TWO lines display, if we also want to use the second line.
- 40 characters x 2 lines
First Line: Second Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11... 27
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51... 67 |
The module has to be initialised as a TWO lines display, if we also want to use the second line. This is
also the maximum configuration which is possible with one HD44780 + extension chips (80 characters).
- 16 characters x 4 lines
First Line: Second Line: Third Line: Fourth Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F |
To use the second and the fourth line, the module has to be initialised as a TWO lines display (strange,
no?). In fact, the third line is continuous to the first line, and the fourth line is continuous two the
second line (from addressing point of view).
- 20 characters x 4 lines
First Line: Second Line: Third Line: Fourth Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53
14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27
54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 |
To use the second and the fourth line, the module has to be initialised as a TWO lines display. In fact,
the third line is continuous to the first line, and the fourth line is continuous two the second line
(from addressing point of view).
- 24 characters x 4 lines
First Line: Second Line: Third Line: Fourth Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57
60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 |
To use the THIRD and the FOURTH line, the module has to be initialised as a TWO lines display. Look out!
There is a small 'view'-gap between the address ing of the first and the second line (and the third and
fourth line respectively).
- 40 characters x 4 lines
First Line: Second Line: Third Line: Fourth Line: |
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12... 27
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52... 67
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12... 27
40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52... 67
|
These modules uses two HD44780's (each with expansion chips) and can be seen as two 40 x 2 modules in one.
All wiring is common, except for the EN (enable) lines, which are separate to drive each HD44780 apart.
Tip:If you are not sure what configuration your display has, you can do use the
following trick: Imagine you have a 16 characters x 1 line display. You want to know if it has configuration
#3 in the first section or #1 in this section. Just connect the contrast input of your module to GND
(= maximum contrast) and apply only power (+5V) to the module. The module will be initialised by an
internal routine, which puts it in single line modus. Only the positions that belong to the first line
will be black.
Conclusion: If all positions are black, we have a module as described under
#1 of this section. If only the first 8 characters are black, you have a module as described under
# of the previous section.
Not all possible module configurations are described here, but with the help of this information you must be able
to work with different modules. Some (functional, not necessary pin-) compatible chips; to help you to determine
your module:
Controller:
HD44780 (Hitachi)
KS0066 (Samsung)
SED1278 (Epson)
Expansion 8 x 2:
HD44100 (Hitachi)
KS0061 (Samsung)
M5259 (OKI)
Expansion 12 x 2:
SED1181 (Epson)
Expansion 16 x 2:
HD66100 (Hitachi)
Note: Some modules have black blobs which are chips direct mounted on the pc-board, covered with some resin
substantion, so the chips are not recognisable.
(C) Copyright 1997 - 2008 by Vault Information Services LLC. All Rights Reserved.
Information provided "as-is" without warranty. Please see details.
Contact us for usage and copy permission.