#include<reg52.h>
#include<stdio.h>
sbit LCDrs=P0^0; //The Register select Pin
sbit LCDrw=P0^1; //The Read/Write Pin
sbit LCDen=P0^2; //The Enable Pin
char sbuf[16],c,store;
char buf[16];
void transmit(unsigned char );
void delay(unsigned int rtime)
{
unsigned int r,s;
for(r=0;r<rtime;r++)
for(s=0;s<1275;s++);
}
void lcdcmd (unsigned char DATA)
{
LCDrs=0;
LCDrw=0;
LCDen=1;
P1=DATA;
LCDrs=0;
LCDen=0;
}
void initialize (void)
{
lcdcmd (0x30); //1 line and 5x7 matrix
delay(1);
lcdcmd (0x38); //2 line and 5x7 matrix
delay(1);
lcdcmd (0x0C); //Display on, cursor off
delay(1);
lcdcmd (0x01); //Clear display Screen
delay(1);
lcdcmd (0x06); //shift cursor to right
delay(1);
}
void lcddat (unsigned int DATA)
{
LCDrs=1;
LCDrw=0;
LCDen=1;
P1=DATA;
LCDrs=1;
LCDen=0;
}
void display_lcd (unsigned char location, unsigned char *d)
{
lcdcmd(0x80 | location);
delay(1);
while(*d)
{
lcddat(*d++);
}
}
char mygetchar(void)
{
char c;
while(!RI);
RI =0;
c = SBUF;
return SBUF;
}
void init()
{
TMOD=0x20;
TH1=0xFD;
TL1=0xFD;
SCON=0x50;
TR1=1;
TI=1;
}
void main()
{
int i;
init();
ES=1;
EA=1;
P0=0xFF;
initialize();
display_lcd(0x80, " Serial Port ");
display_lcd(0xC0, " Reception ");
delay(300);
display_lcd(0x80, " Serial Port ");
display_lcd(0xC0, " Ready! ");
transmit('A');
transmit('T');
transmit('\r');
for(i=0;i<16;i++)
{
store=mygetchar();
sprintf(buf,"%c",store);
display_lcd(i,buf);
}
lcdcmd(0x01);
while(1)
{
}
}
void transmit(unsigned char c)
{
while(!TI);
TI=0;
SBUF=c;
}