源代码~~~~如下所示
/*******************
2016Äê5ÔÂ17èÕ
19:48
£á£Ä£ÃμçÑ1±í
£Ã£ìÎaÖD¶ÏêμÏÖ
í¨μࣰ
*//////////////////
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit Q1=P2^0;
sbit Q2=P2^1;
sbit Q3=P2^2;
sbit Q4=P2^3;
sbit aa=P2^4;
sbit bb=P2^5;
sbit cc=P2^6;
sbit cl=P3^3;
sbit st=P3^0;
sbit eoc=P3^1;
sbit oe=P3^2;
sbit LED=P3^4;
uchar code table []={ //0-9
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,};
uint dat,y;
void delay(uint a)
{
uint b,c;
for(b=a;b>0;b--)
for(c=120;c>0;c--);
}
void display(uint x)
{ Q1=Q2=Q3=Q4=0;
y=x*19.609;
if(y>=2000)
LED=0;
else
LED=1;
Q1=1;
P1=~(~(table[y/1000])|0x80);
delay(1);
Q1=0;
P1=0xff;
Q2=1;
P1=table[y%1000/100];
delay(1);
Q2=0;
P1=0xff;
Q3=1;
P1=table[y%100/10];
delay(1);
Q3=0;
P1=0xff;
Q4=1;
P1=table[y%10];
delay(1);
Q4=0;
P1=0xff ;
}
void ADC_read()
{
aa=0;
bb=0;
cc=0; //Ñ¡í¨μúò»í¨μà
st=0;
st=1;
st=0; //Æeê¼
while(eoc==0); //μè′y×a»»½áêø
oe=1; //ÔêDí¶áè¡
dat=P0; //¸3Öμ
oe=0; //½áêø¶áè¡
}
void time_0()
{
TMOD=0x02;
TH0=0x14;
TL0=0x00;
TR0=1; //Æô¶ˉ¶¨ê±Æ÷
ET0=1; //ÔêDí¶¨ê±Æ÷ÖD¶Ï
EA=1;
}
void ti_0() interrupt 1
{
cl=~cl;
}
void main()
{
time_0();
while(1)
{
ADC_read();
display(dat);
}
}
|