LIQUID CRYSTAL DISPLAY:
►Introduction
The most commonly used Character based LCDs are based on Hitachi's HD44780
controller or other which are compatible with HD44580. In this tutorial, we will discuss about
character based LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-
bit), programming, special stuff and tricks you can do with these simple looking LCDs which
can give a new look to your application.
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines.
In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers,
namely, Command and Data.
FIG 4.6 LCD PIN DIAGRAM
The command register stores the command instructions given to the LCD. A
command is an instruction given to LCD to do a predefined task like initializing it,
clearing its screen, setting the cursor position, controlling display etc. The data register
stores the data to be displayed on the LCD. The data is the ASCII value of the character
to be displayed on the LCD. Click to learn more about internal structure of a LCD.
Features of LCD
16 characters wide, 2 rows
White text on blue background
Connection port is 0.1" pitch, single row for easy bread boarding and wiring
Pins are documented on the back of the LCD to assist in wiring it up
Single LED backlight included can be dimmed easily with a resistor or PWM and
uses much less power than LCD with EL (electroluminescent) backlights
Can be fully controlled with only 6 digital lines!
Built in character set supports most English/European/Japanese text, see the
HD44780 datasheet for the full character set
Up to 8 extra characters can be created for custom glyphs or 'foreign' language
support
Comes with strip of header pins
►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, whereas LCDs
supporting more than 80 characters make use of 2 HD44780 controllers.
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.
Figure 1: Character LCD type HD44780 Pin diagram
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)
Pin no. 9 EN1 Enable signal for row 0 and 1 (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)
Pin no. 15 EN2 Enable signal for row 2 and 3 (2ndcontroller)
Pin no. 16 NC Not Connected
Table 2: Character LCD pins with 2 Controller
Usually these days you will find single controller LCD modules are used more in the market. So
in the tutorial we will discuss more about the single controller LCD, the operation and everything
else is same for the double controller too. Lets take a look at the basic information which is there
in every LCD.
►BF - Busy Flag:
Busy Flag is an 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 and 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. We will discuss more on LCD instruction set further in this tutorial.
►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
(Table 3). 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
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.
No. Instruction Hex Decimal
1 Function Set: 8-bit, 1 Line, 5x7 Dots 0x30 48
2 Function Set: 8-bit, 2 Line, 5x7 Dots 0x38 56
3 Function Set: 4-bit, 1 Line, 5x7 Dots 0x20 32
4 Function Set: 4-bit, 2 Line, 5x7 Dots 0x28 40
5 Entry Mode 0x06 6
Display off Cursor off
6 (clearing display without clearing DDRAM 0x08 8
content)
7 Display on Cursor on 0x0E 14
8 Display on Cursor off 0x0C 12
9 Display on Cursor blinking 0x0F 15
10 Shift entire display left 0x18 24
12 Shift entire display right 0x1C 30
13 Move cursor left by one character 0x10 16
14 Move cursor right by one character 0x14 20
15 Clear Display (also clear DDRAM content) 0x01 1
Set DDRAM address or coursor position on
16 0x80+add* 128+add*
display
Set CGRAM address or set pointer to
17 0x40+add** 64+add**
CGRAM location
Table 4: Frequently used commands and instructions for LCD