Tuesday, 3 November 2015

AT89C51 LCD(4BIT) INTERFACE





#include<reg51.h>
void cmd(unsigned char c);
void dat(unsigned char c);
void init();

void delay(unsigned int i)
{
while(i--);
}
void string(unsigned char *);
void main()
{
init();
cmd (0x80);
string("EMBEDDED LAB");
cmd (0xc0);
string("WWW.SUMMITBHARDWAJ.BLOGSPOT.IN");
while(1)
{
}
}
void init()
{
cmd(0x02);
delay(1000);
cmd(0x28);
delay(1000);
cmd(0x01);
delay(1000);
cmd(0x0e);
delay(1000);

}
void cmd(unsigned char c)
{
unsigned char l,h;
l=(c&0x0f);
h=(c>>4);
P3=h;
P2=0x04;
delay(1000);
P2=0x00;
P3=l;
P2=0x04;
delay(1000);
P2=0x00;
}
void dat(unsigned char c)
{
unsigned char l,h;
l=c&0x0f;
h=c>>4;
P3=h;
P2=0x05;
delay(1000);
P2=0x01;
P3=l;
P2=0x05;
delay(1000);
P2=0x01;
}
void string(unsigned char *p)
{
while(*p!='\0')
{
delay(100);
 dat(*p);
 p++;
 }

 }

No comments:

Post a Comment