|
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit ST=P1^0;
sbit EOC=P1^1;
sbit OE=P1^5;
sbit da=P1^2;
sbit db=P1^3;
sbit dc=P1^4;
uchar code dispcode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳数码管段码
void delay()
{
unsigned char a,b;
for(b=1;b>0;b--)
for(a=47;a>0;a--);
}
void start()
{
uchar t=0;
da=t&0x01;
db=t&0x02;
dc=t&0x04;
ST=0;
ST=1;
ST=0;
}
uint read()
{
uint date=0;
float date1=0;
while(EOC==0);
OE=1;
date1=P2;
OE=0;
date=date1*500/255;
return date;
}
void display(uint a)
{
uchar a1=0,a2=0,a3=0,a4=0;
a1=a/100;
a2=(a%100)/10;
a3=a%10;
P3=0x10;
P0= dispcode[a1];
delay();
P3=0x20 ;
P0= dispcode[a2];
delay();
P3=0x40 ;
P0= dispcode[a3];
delay();
}
void main()
{ uint a;
while(1)
{
start();
a= read();
display(a);
}
}