Professional Documents
Culture Documents
LCD Interfacing
LCD Interfacing
Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for
debugging purpose.
The most commonly used ALPHANUMERIC displays are 1x16 (Single Line & 16 characters), 2x16
(Double Line & 16 character per line) & 4x20 (four lines & Twenty characters per line). 8 lines X 80
Integrated controller
Fortunately, a very popular standard exists which allows us to communicate with the vast majority of
LCDs regardless of their manufacturer. The standard is referred to as HD44780U, which refers to
the controller chip which receives data from an external source (in this case, the 8051) and
communicates directly with the LCD.
These LCD's are very simple to interface with the controller as well as are cost effective.
Refreshing controller into the LCD will save time of cpu while led must be refreshd by cpu to keep
displaying the data
Ease of programming for characters and graphics
LM018L
HITACHI 44780
For Contrast setting a 10K pot should be used as shown in the figure.
Pin
1
2
3
4
5
6
7-14
15
16
Symbol
Vss
Vdd
Vo
RS
R/W
En
DB0-DB7
A/Vee
K Vcc
CGRAM 64 bytes
DDRAM 80 bytes
Function
Ground
Supply Voltage
Contrast Setting
Register Select
Read/Write Select
Chip Enable Signal
Data Lines
Gnd for the backlight
for backlight
Additionally, when you bring EN low and the LCD executes your instruction, it requires
a certain amount of time to execute the command.
After writing to the LCD, it takes some time for it to complete its internal operations.
During this time, it will not accept any new commands or data.
We need to insert time delay between any two commands or data sent to LCDThe
LCDs internal controller can accept several commands and modify the display
accordingly. These commands would be things like
Display clear, cursor home, display on/off, cursor on/off, display character blink,
cursor shift, display shift
The time it requires to execute an instruction depends on the command and the
speed of the crystal which is attached to the 44780's oscillator input.
Automatic reset circuit that initializes the controller/driver after power on
Internal oscillator with external resistors
Low power consumption
Data RAM
DDRAM - Display
Display data RAM (DDRAM) stores display data represented in 8-bit character codes.
Its extended capacity is 80 X 8 bits, or 80 characters.
The area in display data RAM (DDRAM) that is not used for display can be used as
general data RAM.
So whatever you send on the DDRAM is actually displayed on the LCD.
For LCDs like 1x16, only 16 characters are visible, so whatever you write after 16
chars is written in DDRAM but is not visible to the user.
Figures below will show you the DDRAM addresses of 1 Line, 2 Line and 4 Line
LCDs.
For first line addresses for first 15 characters is from 00h to 0Fh. But for second line
address of first character is 40h and so on up to 4Fh for the 16th character.
So if you want to display the text at specific positions of LCD , we require to
manipulate address and then to set cursor position accordingly
Registers
RS
R/W
Operation
IR write as an internal
operation (display clear,
etc.)
DR write as an internal
operation (DR to DDRAM
or CGRAM)
DR read as an internal
operation (DDRAM or
CGRAM to DR)
Time Delay
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.
Checking the Busy Flag
You can use subroutine for checking busy flag or just a big (and safe) delay.
Set R/W Pin of the LCD HIGH(read from the LCD)
Select the instruction register by setting RS pin LOW
Enable the LCD by Setting the enable pin HIGH
The most significant bit of the LCD data bus is the state of the busy flag(1=Busy,0=ready to
accept instructions/data).
The other bits hold the current value of the address counter.
If the LCD never come out from "busy" status because of some problems ,The program
will "hang," waiting for DB7 to go low.
So in a real applications it would be wise to put some kind of time limit on the delay--for
example, a maximum of 100 attempts to wait for the busy signal to go low.
This would guarantee that even if the LCD hardware fails, the program would not lock up.
Only the instruction register (IR) and the data register (DR) of the LCD can be controlled by
the MCU.
Before starting the internal operation of the LCD, control information is temporarily stored into
these registers to allow interfacing with various MCUs, which operate at different speeds, or
various peripheral control devices.
The internal operation of the LCD is determined by signals sent from the MCU.
These signals, which include register selection signal (RS), read/write signal (R/W), and the
data bus (DB0 to DB7), make up the LCD instructions
There are four categories of instructions that:
Designate LCD functions, such as display format, data length, etc.
Command Codes
LCD Addressing