Sample Program for LCD 16x2 Interfacing To AT89C51 Micro-controller
Now am moving ahead this time with 16X2 LCD. We will display simple "WELCOME" message.
1)Please do connection in Proteus as shown in fig.
2) To make connection without Wire as shown in fig right click on proteus screen then goto "PLACE>TERMINAL>DEFAULT".
3) Now connect your terminals as shown in fig for 89C51 and for 16X2 LCD. Please take care of terminal naming, as shown fig give same name to terminal on 89c51 and LCD where you want to make connection.
For Example terminal D0 on Controller must be virtually connected with D0 on LCD.
.
4) Here is C language Code for LCD.
#include<regx51.h>
#define msec 50
sbit rs=P3^5; //Register select (RS)
sbit rw=P3^6; //Read write (RW) pin
sbit en=P3^7; //Enable (EN) pin
void delay(unsigned int time) //Time delay function
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char value) //Function for sending values to the command register of LCD
{
P2=value;
rs=0;
rw=0;
en=0;
delay(15);
en=1;
return;
}
void lcddata(unsigned char value1) //Function for sending values to the data register of LCD
{
P2=value1;
rs=1;
rw=0;
en=0;
delay(15);
en=1;
return;
}
void main()
{
lcdcmd(0x38); //set LCD in 5x7 mode
delay(25);
lcdcmd(0x0E); //Cursor blinking
delay(25);
lcdcmd(0x01); // clear LCD
delay(25);
lcdcmd(0x80); //set cursor on first position of first line on LCD
delay(25);
lcddata('W');
lcddata('E');
lcddata('L');
lcddata(' ');
lcddata('C');
lcddata('O');
lcddata('M');
lcddata('E');
while(1);
}
#define msec 50
sbit rs=P3^5; //Register select (RS)
sbit rw=P3^6; //Read write (RW) pin
sbit en=P3^7; //Enable (EN) pin
void delay(unsigned int time) //Time delay function
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(unsigned char value) //Function for sending values to the command register of LCD
{
P2=value;
rs=0;
rw=0;
en=0;
delay(15);
en=1;
return;
}
void lcddata(unsigned char value1) //Function for sending values to the data register of LCD
{
P2=value1;
rs=1;
rw=0;
en=0;
delay(15);
en=1;
return;
}
void main()
{
lcdcmd(0x38); //set LCD in 5x7 mode
delay(25);
lcdcmd(0x0E); //Cursor blinking
delay(25);
lcdcmd(0x01); // clear LCD
delay(25);
lcdcmd(0x80); //set cursor on first position of first line on LCD
delay(25);
lcddata('W');
lcddata('E');
lcddata('L');
lcddata(' ');
lcddata('C');
lcddata('O');
lcddata('M');
lcddata('E');
while(1);
}
5) Use this code for creating .HEX file using Keil Software.
6) Load .HEX file in Proteus Controller and Run Project.
N'joy..
Comments
Post a Comment