Vous êtes sur la page 1sur 6

LCD interfacing with Microcontrollers tutorial


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.

For Specs and technical information HD44780 controller Click Here

►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 charachers, 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 VSS Power supply (GND)
Pin no. 2 VCC Power supply (+5V)
Pin no. 3 VEE Contrast adjust
0 = Instruction input
Pin no. 4 RS
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 1: Character LCD pins with 1 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)
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.

►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. we
will dicuss both ways of initialization one by one.

Initialization by internal Reset Circuit

An internal reset circuit automatically initializes the HD44780U when the power is
turned on. The following instructions are executed during the initialization. The busy flag
(BF) is kept in the busy state until the initialization ends (BF = 1). The busy state lasts for
10 ms after VCC rises to 4.5 V.
 Display clear
 Function set:
DL = 1; 8-bit interface data
N = 0; 1-line display
F = 0; 5 x 8 dot character font
 Display on/off control:
D = 0; Display off
C = 0; Cursor off
B = 0; Blinking off
 Entry mode set:
I/D = 1; Increment by 1
S = 0; No shift

Note: If the electrical characteristics conditions listed under the table Power Supply
Conditions Using Internal Reset Circuit are not met, the internal reset circuit will not
operate normally and will fail to initialize the HD44780U. For such a case, initial-ization
must be performed by the MCU as explained in the section, Initializing by Instruction.

As mentioned in the Note, there are certain condtions that has to be met, if user want to
use initialization by internal reset circuit. These conditions are shown in the Table 5

Table 5: Power Supply condition for Internal Reset circuit

Figure 7 shows the test condition which are to be met for internal reset circuit to be
Figure 7: Internal Power Supply reset

Now the problem with the internal reset circuit is, it is highly dependent on power supply,
to meet this critical power supply conditions is not hard but are difficult to achive when
you are making a simple application. So usually the second menthod i.e. Initialization by
instruction is used and is recommended most of the time.

Initialization by instructions

Initializing LCD with instructions is really simple. Given below is a flowchart that
describles the step to follow, to initialize the LCD.
Figure 8: Flow chart for LCD initialization

As you can see from the flow chart, the LCD is initialized in the following sequence...
1) Send command 0x30 - Using 8-bit interface
2) Delay 20ms
3) Send command 0x30 - 8-bit interface
4) Delay 20ms
5) Send command 0x30 - 8-bit interface
6) Delay 20ms
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 recomended 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).

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 incremement. I recommend you to try all the possible entry modes
and see the results, I am sure you will be surprised.