Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 24

LCD Interfacing

Liquid Crystal Displays (LCDs)

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

cheap and easy way to display text

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

The display has two register


command register
data register
By RS you can select register
Data lines (DB7-DB0) used to transfer data and commands

The LCD requires 3 control lines (RS, R/W & EN)


8 (or 4) data lines.
The number on data lines depends on the mode of operation.
If operated in 8-bit mode then 8 data lines + 3 control lines i.e. total 11 lines are
required.
And if operated in 4-bit mode then 4 data lines + 3 control lines i.e. 7 lines are
required.
How do we decide which mode to use?
Its simple if you have sufficient data lines you can go for 8 bit mode & if there is a
time constrain i.e. display should be faster then we have to use 8-bit mode because
basically 4-bit mode takes twice as more time as compared to 8-bit mode.

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

When RS is low (0), the data is to be treated as a command.


When RS is high (1), the data being sent is considered as text data
which should be displayed on the screen.
When R/W is low (0), the information on the data bus is being
written to the LCD.
When RW is high (1), the program is effectively reading from the
LCD.
Most of the times there is no need to read from the LCD so this line
can directly be connected to Gnd thus saving one controller line.
The ENABLE pin is used to latch the data present on the data pins.
A HIGH - LOW signal is required to latch the data.
The LCD interprets and executes our command at the instant the
EN line is brought low.
If you never bring EN low, your instruction will never be executed.

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

HD44780U Block Diagram

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

Character Generator ROM (CGROM

Character Generator ROM (CGROM)


Now you might be thinking that when you send an ascii value to
DDRAM, how the character is displayed on LCD? so the answer is
CGROM.
The character generator ROM generates 5 x 8 dot or 5 x 10 dot
character patterns from 8-bit character code. It can generate 208
5 x 8 dot character patterns and 32 5 x 10 dot character patterns.
User defined character patterns are also available by maskprogrammed ROM.

Character Generator RAM (CGRAM)


As clear from the name, CGRAM area is used to
create custom characters in LCD.
In the character generator RAM, the user can
rewrite character patterns by program.
For 5 * 8 dots, eight character patterns can be
written, and for 5 *10 dots, four character patterns
can be written.
Areas that are not used for display can be used as
general data RAM.

LCD characters code map for 5x8 dots

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 :

RS

R/W

Operation

IR write as an internal
operation (display clear,
etc.)

Read busy flag (DB7) and


address counter (DB0 to
DB6)

DR write as an internal
operation (DR to DDRAM
or CGRAM)

DR read as an internal
operation (DDRAM or
CGRAM to DR)

Time Delay

As previously mentioned, it takes a certain amount of time for each instruction to be


executed by the LCD.
The delay varies depending on the frequency of the crystal attached to the oscillator
input of the 44780 as well as the instruction which is being executed.
While it is possible to write code that waits for a specific amount of time to allow the
LCD to execute instructions, this method of "waiting" is not very flexible.
If the crystal frequency is changed, the software will need to be modified.
Additionally, if the LCD itself is changed for another LCD which, although 44780
compatible, requires more time to perform its operations, the program will not work
until it is properly modified.
A more robust method of programming is to use the "Get LCD Status" command to
determine whether the LCD is still busy executing the last instruction received

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.
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.

Address Counter (AC)


The address counter (AC) assigns addresses to both
DDRAM and CGRAM.
When an address of an instruction is written into the IR,
the address information is sent from the IR to the AC.
Selection of either DDRAM or CGRAM is also
determined concurrently by the instruction.
After writing into (reading from) DDRAM or CGRAM, the
AC is automatically incremented by 1 (decremented by
1).
The AC contents are then output to DB0 to DB6 when
RS = 0 and R/W= 1

Commands and Instruction set

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.

Set internal RAM addresses

Perform data transfer with internal RAM

Perform miscellaneous functions

Command Codes

LCD Addressing

LCD TIMING FOR WRITE OPERATION


tD= data output delay time

You might also like