Experiment
Experiment
LCD DISPLAY
16×2 LCD Pin Diagram
Pin Description
LCD COMMANDS
CIRCUIT DIAGRAM
LCD DISPLAY
D
LCD
e always use devices made up of Liquid
W
Crystal Displays (LCDs) like computers,
Microcontroller one knows the exact working of it. Let us
take a look at the working of an LCD.
Pin Description
Microcontroller – Programming
Send Data 16×2 LCD means it can display 16
A
characters per line and there are 2 such
Send String
lines. In this LCD each character is
Send Command
displayedina5×7pixelmatrix.ThisLCDhas
LCD Initializing tworegisters,namely,CommandandData.
LCD Interfacing with 8051 – FULL Thecommandregisterstoresthecommand
CODE instructions given to the LCD. A command
is an instruction given to LCD to do a
redefined task like initializing it, clearing
p
its screen, setting the cursor position,
controlling the display, etc. The data ontrast adjustment;
C
3 VE E
register stores the datatobedisplayedon through a variable resistor
theLCD.ThedataistheASCIIvalueofthe
character to be displayed on the LCD.
Pin Description
7 DB0
Groun
1 Ground (0V)
d
8 DB1
8-bit data pins
hethreecontrollinesarereferredtoasEN,
T
RS, and RW.
1
DB5
2 he EN line is called “Enable.” This control
T
line is used to tell the LCD that you are
sending it data. To send data to the LCD,
your program should make sure thislineis
low (0) and then set the other two control
lines and/or put data on the data bus.
1
DB6 When the other linesarecompletelyready,
3
bringENhigh(1)andwaitfortheminimum
amount of time required by the LCD
datasheet (this varies from LCD to LCD),
and end by bringing it low (0) again.
1
DB7 he RS line is the “Register Select” line.
T
4
WhenRSislow(0),thedataistobetreated
as a command or special instruction(such
as a clear screen, position cursor, etc.).
When RS is high (1),thedatabeingsentis
textdatawhichshouldbedisplayedonthe
1 screen.Forexample,todisplaytheletter“T”
Backlight VCC (5V) Led+
5 on the screen you would set RS high.
heRWlineisthe“Read/Write”controlline.
T
WhenRWislow(0),theinformationonthe
databusiswrittentotheLCD.WhenRWis
1 high(1),theprogramiseffectivelyquerying
Backlight Ground (0V) Led-
6 (or reading) the LCD. Only one instruction
(“Get LCD status”) is a read command. All
others are write commands–so RW will
almost always be LOW.
inally,thedatabusconsistsof4or8lines
F
(depending on the mode of operation
selectedbytheuser).Inthecaseofan8-bit
data bus, the lines are referred to asDB0,
DB1, DB2, DB3, DB4, DB5, DB6, and DB7.
LCD COMMANDS
voiddat(unsignedcharb)
{
Send Command
lcd_data=b;
o send a command on the LCD, a
T
particularcommandisfirstspecifiedtothe
rs=1; datapinswithR/W=0(tospecifythewrite
operation) and RS = 0 (to select the
command register). A high to low pulse is
r w=0; given at the EN pin when data is sent.
en=1; voidcmd(u
nsignedchara)
lcd_delay(); {
en=0; lcd_data=a;
} rs=0;
r w=0;
Send String
en=1;
e cannot send more than 8 bits at the
W
same time. Because data lines are only
having 8 bits. So how we can sendstring? lcd_delay();
Any guess?Yeah,youarecorrect.Wehave
to send the string by character. See this
code. en=0;
voidshow(u
nsignedchar*s) }
{
LCD Initializing
while(*s) {
o initializetheLCDwehavetousecertain
T
commands.
dat(*s++);
voidlcd_init()
}
{
}
cmd(0x38);
cmd(0
x0e); voidlcd_delay();
cmd(0
x01); voidlcd_init()
cmd(0
x06); {
cmd(0
x0c); cmd(0x38);
cmd(0
x80); cmd(0x0e);
} cmd(0x01);
}
#include <reg51.h>
voidcmd(u
nsignedchara)
{
sbit rs=P0^0;
lcd_data=a;
sbit rw=P0^1;
rs=0;
sbit en=P0^2;
r w=0;
voidlcd_init();
en=1;
voidcmd(u
nsignedchara);
lcd_delay();
voiddat(u
nsignedcharb);
en=0;
voidshow(u
nsignedchar*s);
} unsignedintlcd_delay;
voiddat(u
nsignedcharb) for(lcd_delay=0;lcd_delay<=6000;lcd_delay++);
{ }
lcd_data=b; intmain()
rs=1; {
r w=0; unsignedintj;
en=1; lcd_init();
lcd_delay(); while(1) {
en=0; cmd(0x80);
voidshow(u
nsignedchar*s) cmd(0xc0);
dat(*s++); cmd(0x01);
} }
voidlcd_delay() }
{
LCD Interfacing with
8051 – Working