uchar disbuf[]={'0','0','0',0x00};
sbit rs=P2^0;
sbit en=P2^1;
sbit rw=P2^2;
sbit OE=P2^3;
sbit EOC=P2^4;
sbit ST=P2^5;
sbit CLK=P2^6;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void command(uchar com)
{
rs=0;
delay(5);
P1=com;
en=1;
delay(5);
en=0;
}
void figure(uchar figure)
{
rs=1;
delay(5);
P1=figure;
en=1;
delay(5);
en=0;
}
void write_first(uchar *s)
{
command(0x80);
while(*s)
{
figure(*s);
s++;
delay(20);
}
}
void write_second(uchar x)
{
command(0xc0);
disbuf[0]=x/100+0x30;
disbuf[1]=x%100/10+0x30;
disbuf[2]=x%10+0x30;
for(i=0;i<3;i++)
{
figure(disbuf);
delay(5);
}
}
void init()
{
rw=0;
TMOD=0x22;
SCON=0X50;
PCON=0;
TH1=TL1=0XFD;
TH0=(256-4)/256;
TL0=(256-4)%256;
command(0x38);
command(0x0c);
command(0x06);
command(0x80);
}
void main()
{
uchar temp,i;
uchar *p;
init();
p="ADconvert result";;
write_first(p);
EA=1;
ET0=1;
TR0=1;
TR1=1;
while(1)
{
ST=0;ST=1;ST=0;
delay(5);
while(EOC==0);
OE=1;
temp=P0;
write_second(temp);
OE=0;
i=0;
while(disbuf!=0x00)
{
SBUF=disbuf;
while(TI==0);
TI=0;
i++;
delay(5);
}
while(RI==0);
RI=0;
while(TI==0);
TI=0;
}
}
void timer0() interrupt 1
{
CLK=~CLK;
} |