You are on page 1of 8

SUBJECT:

Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DATE :

DOC. CODE: DIET/EC/SEM5


REV. NO.: 1.00/JUNE-2015

THEORY:
LCD is finding widespread use replacing LEDs, because of
The declining prices of LCD
The ability to display numbers, characters, and graphics
Incorporation of a refreshing controller into the LCD, thereby relieving the
CPU of the task of refreshing the LCD
Ease of programming for characters and graphics
The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines.
The number on data lines depends on the mode of operation. If operated in 8-bit
mode, there are 8 data lines + 3 control lines i.e. total 11 lines are required. And if
operated in 4-bit mode, there are 4 data lines + 3 control lines i.e. 7 lines are required.
How do we decide which mode to use? Its simple if you have sufficient data lines
you can go for 8 bit mode & if there is a time constrain i.e. display should be faster
then we have to use 8-bit mode because basically 4-bit mode takes twice as more time
as compared to 8-bit mode.
PIN DESCRIPTION:
Pin
1.
2.
3.
4.

Symbol
VSS
VCC
VEE
RS

I/O
---I

5.

R/W

6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

E
DB0
DB0
DB0
DB0
DB0
DB0
DB0
DB0
A
K

I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
---

Descriptions
Ground
+5V power supply
Power supply to control contrast
RS=0 to select command register,
RS=1 to select data register
R/W=0 for write,
R/W=1 for read
Enable
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
The 8-bit data bus
GND for the backlight
Vcc for backlight

Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DATE :

DOC. CODE: DIET/EC/SEM5


REV. NO.: 1.00/JUNE-2015

When RS is low (0), the data is to be treated as a command. When RS is high (1), the
data being sent is considered as text data which should be displayed on the screen.
When R/W is low (0), the information on the data bus is being written to the LCD.
When RW is high (1), the program is effectively reading from the LCD. Most of the
times there is no need to read from the LCD so this line can directly be connected to
GND thus saving one controller line.
The ENABLE pin is used to latch the data present on the data pins. A HIGH - LOW
signal is required to latch the data. The LCD interprets and executes our command at
the instant the EN line is brought low. If you never bring EN low, your instruction
will never be executed.
COMMAND LIST:
Code (Hex)
1
2
4
6
5
7
8
A
C
E
F
10
14
18
1C
80

Command to LCD Instruction Register


Clear display screen
Return home
Decrement cursor (shift cursor to left)
Increment cursor (shift cursor to right)
Shift display right
Shift display left
Display off, cursor off
Display off, cursor on
Display on, cursor off
Display on, cursor blinking OFF
Display on, cursor blinking ON
Shift cursor position to left
Shift cursor position to right
Shift the entire display to the left
Shift the entire display to the right
Force cursor to beginning to 1st line

Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DATE :

C0
38

DOC. CODE: DIET/EC/SEM5


REV. NO.: 1.00/JUNE-2015

Force cursor to beginning to 2nd line


2 lines and 5x7 matrix

EXERCISE:
1. Write a Program to send string GTU IS BEST to LCD in C Language. Use LCD
in 8-bit mode.
INTERFACE DIAGRAM:
As in figure following are connections of LCD with 8051
DB0 to DB7 is connected with port P0
RS is connected with P2.0
RW is connected with P2.1
EN is connected with P2.2

#include <reg52.h>
sbit rs= P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void lcdcmd(unsigned char);
void lcddata(unsigned char);
void msdelay(unsigned char);
Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DOC. CODE: DIET/EC/SEM5

DATE :

REV. NO.: 1.00/JUNE-2015

void main()
{
unsigned char data[]=GTU IS BEST;
unsigned char k;
lcdcmd(0x38);
msdelay(250);
lcdcmd(0x0E);
msdelay(250);
lcdcmd(0x01);
msdelay(250);
lcdcmd(0x06);
msdelay(250);
lcdcmd(0x86);
msdelay(250);
for(k=0;k<11;k++)
{
lcddata(data[k]);
msdelay(250);
}
while(1);

// 2 line 5x7 display


// LCD ON, Cursor not Blinking
// Clear LCD
// Shift cursor Right
// Starting address

}
void lcdcmd(unsigned char value)
{
P0=value;
rs=0;
// Command register
rw=0;
en=1;
msdelay(1)
en=0;
// EN is H to L pulse
return;
}
void lcddata(unsigned char value)
{
P0=value;
rs=1;
// Data Register
rw=0;
en=1;
msdelay(1)
en=0;
// EN is H to L pulse
return;
}

Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DATE :

DOC. CODE: DIET/EC/SEM5


REV. NO.: 1.00/JUNE-2015

void msdelay(unsigned char itime)


{
unsigned char i;
unsigned int j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
Output on Simulator:

2. Write a Program to send string GTU IS BEST to LCD in C Language. Use LCD
in 4-bit mode.
INTERFACE DIAGRAM:
As in figure following are connections of LCD with 8051
DB4 to DB7 is connected with port P0.4 to P0.7
RS is connected with P0.0
RW is connected with P0.1
EN is connected with P0.2

Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

DOC. CODE: DIET/EC/SEM5

DATE :

REV. NO.: 1.00/JUNE-2015

#include <reg52.h>
sbit rs= P0^0;
sbit rw=P0^1;
sbit en=P0^2;
void lcd_cmd_8bit(unsigned char);
void lcd_cmd_4bit(unsigned char);
void lcd_data_4bit(unsigned char);
void msdelay(unsigned char);
void main()
{
unsigned char str[]="GTU IS BEST";
unsigned char k;
msdelay(550);
lcd_cmd_8bit(0x20); //default on reset is 8bit, so first write in 8 bit then repeat in 4bit
msdelay(250);
lcd_cmd_4bit(0x20);
// 0x20 for 4-bit
msdelay(250);
lcd_cmd_4bit(0x28);
// 2 line 5x7 display
msdelay(250);
lcd_cmd_4bit(0x0E);
// LCD ON, Cursor not Blinking
msdelay(250);
lcd_cmd_4bit(0x01);
// Clear LCD
msdelay(250);
lcd_cmd_4bit(0x06);
// Shift cursor Right
msdelay(250);
lcd_cmd_4bit(0x83);
// Starting address
msdelay(250);
for(k=0;k<11;k++)
{
lcd_data_4bit(str[k]);
msdelay(250);
}
while(1);

//wait for infinite time

}
void lcd_cmd_8bit(unsigned char value)
{
unsigned char temp;
rs=0;
// Command register
rw=0;
temp = value & 0xf0;//data bit are only higer and rs,rw and en are on lower bits
P0 = P0 & 0x0f; //make higher bits of P0 zero maintain lower bits
Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

P0 = P0 | temp;
en=1;
msdelay(1);
en=0;
return;

DATE :

DOC. CODE: DIET/EC/SEM5


REV. NO.: 1.00/JUNE-2015

//change only higer bits maintian lower bits

// EN is H to L pulse

}
void lcd_cmd_4bit(unsigned char value)
{
unsigned char temp;
rs=0;
rw=0;
temp=value;
temp=temp & 0xf0; // Mask Lower 4 Bits
P0 = P0 & 0x0f; //make higher bits of P0 zero maintain lower bits
P0 = P0 | temp;
//change only higer bits maintian lower bits
en=1;
msdelay(1);
en=0;
temp=value<<4;
//Left Shift Byte Four Times
temp=temp & 0xf0;
// Mask Higher 4 Bits
P0 = P0 & 0x0f; //make higher bits of P0 zero maintain lower bits
P0 = P0 | temp;
//change only higer bits maintian lower bits
en=1;
msdelay(1);
en=0;
}
void lcd_data_4bit(unsigned char value)
{
unsigned char temp;
rs=1;
rw=0;
temp=value;
temp=temp & 0xf0; // Mask Lower 4 Bits
P0 = P0 & 0x0f; //make higher bits of P0 zero maintain lower bits
P0 = P0 | temp;
//change only higer bits maintian lower bits
en=1;
msdelay(1);
en=0;
temp=value<<4;
//Left Shift Byte Four Times
temp=temp & 0xf0;
// Mask Higher 4 Bits
P0 = P0 & 0x0f; //make higher bits of P0 zero maintain lower bits
P0 = P0 | temp;
//change only higer bits maintian lower bits
en=1;
msdelay(1);
en=0;
}
Darshan Institute of Engineering And Technology, Rajkot

SUBJECT:
Microprocessor & Microcontroller

TITLE:

Architecture & Interfacing (2150907)

Interfacing of LCD with 8051

EXPERIMENT NO.

void msdelay(unsigned char itime)


{unsigned char i;
unsigned int j;
for(i=0;i<itime;i++)
for(j=0;j<125;j++);
}

DOC. CODE: DIET/EC/SEM5

DATE :

REV. NO.: 1.00/JUNE-2015

//gives approx. delay of 1 msec

GRADE
Darshan Institute of Engineering And Technology, Rajkot

SIGNATURE

You might also like