#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
sbit ADC_RD = P3^3;
sbit ADC_WR = P3^4;
sbit ADC_INT = P3^5;
uchar ledcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0Xbf};
uchar str[]={0,0,0,0};
uchar cnt;
void TIME_Init()
{
TMOD=0X21;
TH0=0X3c;
TL0=0Xb0;
ET0=1;
EA=1;
TR0=1;
}
void display(void)
{
uchar t;
P2=0x01;
P0=ledcode[str[0]]&0x7f;
for(t=0;t<150;t++);
P2=0x02;
P0=ledcode[str[1]];
for(t=0;t<150;t++);
P2=0x04;
P0=ledcode[str[2]];
for(t=0;t<150;t++);
P2=0x08;
P0=ledcode[str[3]];
for(t=0;t<150;t++);
}
uchar ADCStart()
{
uchar a;
ADC_WR=0;
ADC_WR=1;
while(ADC_INT);
ADC_RD=0;
a=P1;
ADC_RD=1;
return a;
}
void main()
{
uint Data;
TIME_Init();
while(1)
{
display();
if(cnt==20)
{
Data=ADCStart()*100.0*5/255;
str[0]=Data/100%10;
str[1]=Data/10%10;
str[2]=Data%10;
}
}
}
void t0ser() interrupt 1 using 1
{
TH0=0X3c;
TL0=0Xb0;
cnt++;
}