How to interface 16*2 LCD with 8051 microcontroller

· 8051 MICROCONTROLLER

DESCRIPTION
This post is about to interface 16*2 LCD with 8051 microcontroller.The data pins of LCD is connected to P1 port of controller and the pins RS, R/W, E is connected to P3.2, P3.3, P3.4 respectively

Let’s start with connecting the LCD hardware with microcontroller (P89v51). The following table lists all pins of LCD module (JHD162A) along with their description.

Pin 1 — Vss — Ground
Pin 2 — Vdd — +5v
Pin 3 — Vee — Contrast Adjustment -2V to -5V
Pin 4 — RS — Register Select
Pin 5 — R/W — 1-Read, 0-Write
Pin 6 — E — Enable
Pin 7 — D0 — Data Line
Pin 8 — D1 — Data Line
Pin 9 — D2 — Data Line
Pin 10 — D3 — Data Line
Pin 11 — D4 — Data Line
Pin 12 — D5 — Data Line
Pin 13 — D6 — Data Line
Pin 14 — D7 — Data Line
Pin 15 — LED+ — BackLight LED +V
Pin 16 — LED- — BackLight LED -V

CODE
# include < reg51.h >
unsigned char a;
sfr lcddata=0x90; //p1 port
sbit rs=P3^2;
sbit rw=P3^3;
sbit en=P3^4;

/**********************start of program functions************************************************/
//________________________________Delay subroutine________________________________________________________________

void delay(unsigned int b)
{
unsigned int a;
for(b;b>0;b–)
for (a=75;a>0;a–);
}

/*************************LCD Routine**************************************/

void command(unsigned char dost)
{
lcddata=dost;
en=1;
rs=0; //initialise of the LCD
rw=0;
delay(5);
en=0;
}

void lcddisplaydata(unsigned char word)
{
lcddata=word;
en=1; //Data writing of the Lcd
rs=1;
rw=0;
delay(5);
en=0;
}

void displaydata(unsigned char *word)
{
int x;
for(x=0;word[x]!=0;x++) //Data writing of the LCD
{
lcddisplaydata(word[x]);
}
}
/********************************************************/

void main()
{
command(0x38);
command(0x0C);
command(0x80);
displaydata(“ELECTRONICS WORK”);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 347 other followers

%d bloggers like this: