Microcontroller › 8051 › programming 8×2 LCD (pc0802A) › Try out this
March 14, 2012 at 10:12 am
#7301
Shailesh Tambe
Participant
Try out this code……………… it should work
#include<reg51.h>
#include<string.h>
sbit rs = P2^0;
sbit rw = P2^1;
sbit en = P2^2;
sbit b = P1^7;
void writecmd(unsigned char a);
void writedat(unsigned char b);
void busy();
void writestr(unsigned char *s);
void delay(unsigned int msec);
void writecmd(unsigned char a)
{
busy();
rs=0;
rw=0;
P1=a;
en=1;
en=0;
}
void writedat(unsigned char b)
{
busy();
rs=1;
rw=0;
P1=b;
en=1;
en=0;
}
void busy()
{
en=0;
P1=0xFF;
rs=0;
rw=1;
while(b==1)
{
en=0;
en=1;
}
en=0;
}
void writestr(unsigned char *s)
{
unsigned char i,len;
len=strlen(s);
for(i=0;i<len;i++)
{
writedat(*s);
s++;
}
}
void delay(unsigned int msec)
{
int count1,count2;
for(count1=0;count1<msec;count1++)
for(count2=0;count2<1275;count2++);
}
void main()
{
P1=0x00;
P2=0x00;
writecmd(0x3C); // Initialize the LCD
delay(50);
writecmd(0x0E); // turn display ON for cursor blinking
delay(50);
writecmd(0x01); //Clear the LCD Screen
delay(50);
writecmd(0x06);
delay(50);
writestr(“HAPPY”);
delay(50);
writecmd(0xC0);
delay(50);
writestr(“BIRTHDAY”);
delay(50);
while(1);
}