#include<regx52.h>
#include<intrins.h>
unsigned char code table[16]=" THE RESULT: ";
unsigned char table1[]="0123456789";
unsigned char tab[]="0.00V";
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
void delay(unsigned int x)
{
unsigned int k;
for(k=0;k<x;k++);
}
unsigned int ad()
{
unsigned int result = 0;
unsigned char i;
P1_7=0;
P1_6=0;
while(P1_5==0);
for(i=0;i<12;i++)
{
P1_7=1;
result<<=1;
result|=P1_5;
delay(200);
P1_7=0;
delay(200);
}
P1_7=0;
P1_6=1;
return result;
}
void write_com(unsigned char com)
{
P0=com;
RS=0;
RW=0;
EN=1;
delay(200);
EN=0;
}
void write_dat(unsigned char dat)
{
P0=dat;
RS=1;
RW=0;
EN=1;
delay(200);
EN=0;
}
void init()
{
write_com(0x01);
write_com(0x38);
write_com(0x0f);
write_com(0x06);
}
void main()
{
unsigned char j;
unsigned int t;
t=ad()*5000.0/4096;
tab[0]=t/1000+'0';
tab[2]=(t/100)%10+'0';
tab[3]=(t/10)%10+'0';
init();
write_com(0x80);
for(j=0;j<16;j++)
{
write_dat(table[j]);
delay(3000);
}
write_com(0xc0);
for(j=0;j<5;j++)
{
write_dat(tab[j]);
delay(3000);
}
write_com(0x02);
while(1);
}
把功能放在while1里面,才能动态显示
void main()
{
unsigned char j;
unsigned int t;
write_com(0x02);
while(1)
{
t=ad()*5000.0/4096;
tab[0]=t/1000+'0';
tab[2]=(t/100)%10+'0';
tab[3]=(t/10)%10+'0';
init();
write_com(0x80);
for(j=0;j<16;j++)
{
write_dat(table[j]);
delay(3000);
}
write_com(0xc0);
for(j=0;j<5;j++)
{
write_dat(tab[j]);
delay(3000);
}
}
}