You are on page 1of 5

Experiment No:- 3

Aim:- Write a program for interfacing LCD to Microcontroller

Apparatus:- keiluvision5 software

Theory :-

LCD display is an inevitable part in almost all embedded projects and this article is about
interfacing a 16×2 LCD with 8051 microcontroller. Many guys find it hard to interface LCD
module with the 8051 but the fact is that if you learn it properly, it is a very easy job and by
knowing it you can easily design embedded projects like digital voltmeter / ammeter, digital clock,
home automation displays, status indicator display, digital code locks, digital speedometer/
odometer, display for music players etc. Thoroughly going through this article will make you able
to display any text (including the extended characters) on any part of the 16×2 display screen. In
order to understand the interfacing first you have to know about the 16×2 LCD module.
LCD initialization.

The steps that has to be done for initializing the LCD display is given below and these steps are
common for almost all applications.

 Send 38H to the 8 bit data line for initialization


 Send 0FH for making LCD ON, cursor ON and cursor blinking ON.
 Send 06H for incrementing cursor position.
 Send 01H for clearing the display and return the cursor.

Hex Code Command to LCD Instruction Register


0F LCD ON, cursor ON
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to left)
06 Increment cursor (shift cursor to right)
05 Shift display right
07 Shift display left
0E Display ON, cursor blinking
80 Force cursor to beginning of first line
C0 Force cursor to beginning of second line
38 2 lines and 5×7 matrix
83 Cursor line 1 position 3
3C Activate second line
08 Display OFF, cursor OFF
C1 Jump to second line, position 1
OC Display ON, cursor OFF
C1 Jump to second line, position 1
C2 Jump to second line, position 2

Sending data to the LCD.

The steps for sending data to the LCD module is given below. I have already said that the LCD
module has pins namely RS, R/W and E. It is the logic state of these pins that make the module to
determine whether a given data input is a command or data to be displayed.

 Make R/W low.


 Make RS=0 if data byte is a command and make RS=1 if the data byte is a data to be displayed.
 Place data byte on the data register.
 Pulse E from high to low.
 Repeat above steps for sending another data.

Circuit Diagram:-

Circuit diagram for LCD interfacing with 8051 microcontroller is shown in the above figure. If
you have basic understanding of 8051 then you must know about EA(PIN 31), XTAL1 &
XTAL2, RST pin(PIN 9), Vcc and Ground Pin of 8051 microcontroller. I have used these Pins in
above circuit. If you don’t have any idea about that then I recommend you to read this Article
LED Interfacing with 8051 Microcontroller before going through LCD interfacing.
So besides these above pins we have connected the data pins (D0-D7) of LCD to the Port 2
(P2_0 – P2_7) microcontroller. And control pins RS, RW and E to the pin 12,13,14 (pin 2,3,4 of
port 3) of microcontroller respectively.
PIN 2(VDD) and PIN 15(Backlight supply) of LCD are connected to voltage (5v), and PIN 1
(VSS) and PIN 16(Backlight ground) are connected to ground.
Pin 3(V0) is connected to voltage (Vcc) through a variable resistor of 10k to adjust the contrast
of LCD. Middle leg of the variable resistor is connected to PIN 3 and other two legs are
connected to voltage supply and Ground.

Code:-
org 00h
temp equ 30h
mov a,#28h
acall cmnd
mov a,#0fh
acall cmnd
mov a,#01h
acall cmnd
mov a,#06h
acall cmnd
mov a,#82h
acall cmnd
mov a,#45h
acall disp
mov a,#54H
acall disp
mov a,#52h
acall disp
mov a,#58h
acall disp
here:sjmp here
cmnd:mov temp,a
swap a
anl a,#0fh
rl a
rl a
add a,#02h
mov p2,a
clr p2.1
mov a,temp
anl a,#0fh
rl a
rl a
add a,#02h
mov p2,a
clr p2.1
acall delay
ret
disp:mov temp,a
swap a
anl a,#0fh
rl a
rl a
add a,#03h
mov p2,a
clr p2.1
mov a,temp
anl a,#0fh
rl a
rl a
add a,#03h
mov p2,a
clr p2.1
acall delay
ret
delay:mov 03,#0f0h
loop2:mov r4,#0f0h
loop1:djnz r4,loop1
djnz r3,loop2
ret
end

Expected Output:-

You might also like