Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Interfacing of alphanumeric LCD (2x16 line) Atmega16

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.

Fig. Character LCD type HD44780 Pin diagram

Table 1: Character LCD pins

Pin No. Name Description

Pin no. 1 VSS Power supply (GND)

Pin no. 2 VCC Power supply (+5V)

Pin no. 3 VEE Contrast adjust

Pin no. 4 RS 0 = Instruction input


1 = Data input

0 = Write to LCD module


Pin no. 5 R/W
1 = Read from LCD module

Pin no. 6 EN Enable signal

Pin no. 7 D0 Data bus line 0 (LSB)

Pin no. 8 D1 Data bus line 1

Pin no. 9 D2 Data bus line 2

Pin no. 10 D3 Data bus line 3

Pin no. 11 D4 Data bus line 4

Pin no. 12 D5 Data bus line 5

Pin no. 13 D6 Data bus line 6

Pin no. 14 D7 Data bus line 7 (MSB)

Table 2: Character LCD pins with 2 Controller

Pin No. Name Description

Pin no. 1 D7 Data bus line 7 (MSB)

Pin no. 2 D6 Data bus line 6

Pin no. 3 D5 Data bus line 5

Pin no. 4 D4 Data bus line 4

Pin no. 5 D3 Data bus line 3

Pin no. 6 D2 Data bus line 2

Pin no. 7 D1 Data bus line 1

Pin no. 8 D0 Data bus line 0 (LSB)

Enable signal for row 0 and 1

Pin no. 9 EN1 (1stcontroller)


0 = Write to LCD module

Pin no. 10 R/W 1 = Read from LCD module

0 = Instruction input

Pin no. 11 RS 1 = Data input

Pin no. 12 VEE Contrast adjust

Pin no. 13 VSS Power supply (GND)

Pin no. 14 VCC Power supply (+5V)

Enable signal for row 2 and 3

Pin no. 15 EN2 (2ndcontroller)

Pin no. 16 NC Not Connected

DDRAM - Display Data RAM

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.

Fig. DDRAM Address for 1 Line LCD

Fig. DDRAM Address for 2 Line LCD


Fig. DDRAM Address for 4 Line LCD

CGROM - Character Generator ROM

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.

Figure a: LCD characters code map for 5x8 dots


Figure b: LCD characters code map for 5x10 dots

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.

CGRAM - Character Generator RAM

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 (IR) and Data Register (DR)

There are two 8-bit registers in HD44780 controller

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

Commands and Instruction Set


Only the instruction register (IR) and the data register (DR) of the LCD can be controlled
by the MCU/up. 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
Table 3: Command and Instruction set for LCD type HD44780

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

* DDRAM address given in LCD basics section


** CGRAM address from 0x00 to 0x3F, 0x00 to 0x07 for char1 and so on..

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:

1) Send command 0x30 - Using 8-bit interface


2) Delay 15ms
3) Send command 0x30 - 8-bit interface
4) Delay 4.1ms
5) Send command 0x30 - 8-bit interface
6) Delay 100us
7) Send Function set - see Table 4 for more information
8) Display Clear command
9) Set entry mode command - explained below

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

LCD Entry mode

From Table 3 in command section, you can see that the two bits decide the entry mode
for LCD, these bits are:

a) I/D - Increment/Decrement bit


b) S - Display shift

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.

You might also like