Most projects you create with the 8051 microcontroller require some form of display. The most common way to accomplish this is with the LCD (Liquid Crystal Display). LCDs have become a cheap and easy way to get text display for an embedded system Common displays are set up as 16 to 20 characters by 1 to 4 lines.
UNDERSTANDING LCD
Pinout
• 8 data pins D7:D0
Bi-directional data/command pins.
Alphanumeric characters are sent in ASCII format.
• RS: Register Select
RS = 0 -> Command Register is selected
RS = 1 -> Data Register is selected
• R/W: Read or Write
0 -> Write, 1 -> Read
• E: Enable (Latch data)
Used to latch the data present on the data pins.
A high-to-low edge is needed to latch the data.
• VEE : contrast control
NOTE: When writing to the display, data is transferred only on the high to low transition of this signal. However, when reading from the display, data will become available shortly after the low to high transition and remain available until the signal falls low again.
Registers
The HD44780 has two 8-bit registers, an instruction register (IR) and a data register (DR). The IR stores instruction codes. The DR temporarily stores data to be written into DDRAM or CGRAM and temporarily stores data to be read from DDRAM or CGRAM. Data written into the DR is automatically written into DDRAM or CGRAM by an internal operation. . These two registers can be selected by the register selector (RS) signal. See the table below:
Register Selection | ||
RS | R/W | Operation |
0 | 0 | IR write as an internal operation (display clear, etc.) |
0 | 1 | Read busy flag (DB7) and address counter (DB0 to DB6) |
1 | 0 | DR write as an internal operation (DR to DDRAM or CGRAM) |
1 | 1 | DR read as an internal operation (DDRAM or CGRAM to DR) |
Busy Flag (BF)
When the busy flag is 1, the LCD is in the internal operation mode, and the next instruction will not be accepted. When RS = 0 and R/W = 1 (see the table above), the busy flag is output to DB7 (MSB of LCD data bus). The next instruction must be written after ensuring that the busy flag is 0.
LCD Commands
The LCD’s internal controller accept several commands and modify the display accordingly. These commands would be things like:
– Clear screen
– Return home
– Shift display right/left
Instruction | Decimal | HEX |
Function set (8-bit interface, 2 lines, 5*7 Pixels) |
56
|
38
|
Function set (8-bit interface, 1 line, 5*7 Pixels) |
48
|
30
|
Function set (4-bit interface, 2 lines, 5*7 Pixels) |
40
|
28
|
Function set (4-bit interface, 1 line, 5*7 Pixels) |
32
|
20
|
Entry mode set |
See Below
|
See Below
|
Scroll display one character right (all lines) |
28
|
1E
|
Scroll display one character left (all lines) |
24
|
18
|
Home (move cursor to top/left character position) |
2
|
2
|
Move cursor one character left |
16
|
10
|
Move cursor one character right |
20
|
14
|
Turn on visible underline cursor |
14
|
0E
|
Turn on visible blinking-block cursor |
15
|
0F
|
Make cursor invisible |
12
|
0C
|
Blank the display (without clearing) |
8
|
08
|
Restore the display (with cursor hidden) |
12
|
0C
|
Clear Screen |
1
|
01
|
Set cursor position (DDRAM address) |
128 + addr
|
80+ addr
|
Set pointer in character-generator RAM (CG RAM address) |
64 + addr
|
40+ addr
|
INTERFACING LCD TO 8051
The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-bit data bus is used, the LCD will require a total of 7 data lines. If an 8-bit data bus is used, the LCD will require a total of 11 data lines. The three control lines are EN, RS, and RW. Note that the EN line must be raised/lowered before/after each instruction sent to the LCD regardless of whether that instruction is read or write, text or instruction. In short, you must always manipulate EN when communicating with the LCD. EN is the LCD’s way of knowing that you are talking to it. If you don’t raise/lower EN, the LCD doesn’t know you’re talking to it on the other lines.
Still more details needed? Click Here