Interfacing of Alphanumeric LCD (2x16 Line) Atmega16: Pin Description
Interfacing of Alphanumeric LCD (2x16 Line) Atmega16: Pin Description
Explanation
LCD 16 characters ×2 line module
Character construction 5 × 7 dots
Character Pitch 3.65 mm
Dot size 0.55W × 0.5H mm
In the LCD there are either 16-pins or 14-pins and last two pins are for back light and for
initializing LCD , enable pin is stored.
Introduction
The most commonly used Character based LCDs are based on Hitachi's HD44780
controller or other which are compatible with HD44580.
Pin Description
The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line
LCDs which have only 1 controller and support at most of 80 characters. Most LCDs
with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two pins are extra
in both for back-light LED connections). Pin description is shown in the table below.
0 = Instruction input
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.
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 codes
(see Figure a and Figure b for more details). 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 mask-programmed ROM.
As you can see in both the code maps, the character code from 0x00 to 0x07 is
occupied by the CGRAM characters or the user defined characters. If user wants to
display the fourth custom character then the code to display it is 0x03 i.e. when user
sends 0x03 code to the LCD DDRAM then the fourth user created character or pattern
will be displayed on the LCD.
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
x 8 dots, eight character patterns can be written, and for 5 x 10 dots, four character
patterns can be written.
BF - Busy Flag
Busy Flag is a status indicator flag for LCD. When we send a command or data to the
LCD for processing, this flag is set (i.e BF =1) and as soon as the instruction is
executed successfully this flag is cleared (BF = 0). This is helpful in producing and exact
amount of delay for the LCD processing.
To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of the
LCD data bus (D7) act as busy flag. When BF = 1 means LCD is busy and will not
accept next command or data and BF = 0 means LCD is ready for the next command or
data to process.
Instruction register
Data register
Instruction register corresponds to the register where you send commands to LCD
e.g. LCD shift command, LCD clear, LCD address etc. and Data register is used for
storing data which is to be displayed on LCD. When send the enable signal of the LCD
is asserted, the data on the pins is latched in to the data register and data is then
moved automatically to the DDRAM and hence is displayed on the LCD. Data Register
is not only used for sending data to DDRAM but also for CGRAM, the address where
you want to send the data, is decided by the instruction you send to LCD.
Although looking at the table you can make your own commands and test them. Below
is a brief list of useful commands which are used frequently while working on the LCD.
Table 4: Frequently used commands and instructions for LCD
No
Instruction Hex Decimal
.
Function Set: 8-bit, 1
1 0x30 48
Line, 5x7 Dots
Function Set: 8-bit, 2
2 0x38 56
Line, 5x7 Dots
Function Set: 4-bit, 1
3 0x20 32
Line, 5x7 Dots
Function Set: 4-bit, 2
4 0x28 40
Line, 5x7 Dots
5 Entry Mode 0x06 6
Display off Cursor off
(clearing display
6 0x08 8
without clearing
DDRAM content)
7 Display on Cursor on 0x0E 14
8 Display on Cursor off 0x0C 12
Display on Cursor
9 0x0F 15
blinking
10 Shift entire display left 0x18 24
12 Shift entire display right 0x1C 30
Move cursor left by one
13 0x10 16
character
Move cursor right by
14 0x14 20
one character
Clear Display (also
15 0x01 1
clear DDRAM content)
Set DDRAM address or
16 cursor position on 0x80+add* 128+add*
display
17 Set CGRAM address or 0x40+add** 64+add**
set pointer to CGRAM
location
The table above will help you while writing programs for LCD.
LCD Initialization
Before using the LCD for display purpose, LCD has to be initialized either by the internal
reset circuit or sending set of commands to initialize the LCD. It is the user who has to
decide whether an LCD has to be initialized by instructions or by internal reset circuit.
Initialization by instructions
Initializing LCD with instructions is really simple. Given below is a flowchart that
describes the step to follow, to initialize the LCD.
You can see in the flow chart given below, the LCD is initialized in the following
sequence:
The first 3 commands are usually not required but are recommended when you are
using 4-bit interface. So you can program the LCD starting from step 7 when working
with 8-bit interface. Function set command depends on what kind of LCD you are using
and what kind of interface you are using (see Table 4 in LCD Command section).
Fig. Flow chart for LCD initialization
From Table 3 in command section, you can see that the two bits decide the entry mode
for LCD, these bits are:
With these two bits we get four combinations of entry mode which are 0x04, 0x05, 0x06,
0x07 (see table 3 in LCD Command section). So we get different results with these
different entry modes. Normally entry mode 0x06 is used which is No shift and auto
increment.