#include<reg51.h>
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit cs=P2^4;
sbit rd=P2^5;
sbit wr=P2^6;
sbit intr=P2^7;
void delay(unsigned int time)
{
unsigned int i,j;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
}
void lcddata(unsigned char val)
{
rs=1;
rw=0;
P0=val;
en=1;
delay(5);
en=0;
}
void lcdcmd(unsigned char val)
{
rs=0;
rw=0;
P0=val;
en=1;
delay(5);
en=0;
}
void lcd_init()
{
lcdcmd(0x38);
lcdcmd(0x0e);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x80);
}
unsigned char adc()
{
unsigned char adc;
cs=0;
//intr=1;
wr=0;
wr=1;
while(intr==1);
rd=0;
adc=P1;
rd=1;
return adc;
}
void main()
{
unsigned char a;
lcd_init();
P0=0x00;
P1=0xff;
cs=0;
rd=1;
wr=1;
intr=1;
while(1)
{
lcdcmd(0x83);
a=adc();
lcddata((a/100)+48);
lcddata(((a/10)%10)+48);
lcddata((a%10)+48);
delay(30);
}
}