#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code num[]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f};
uint t=0,x,x1,x2,x3,y;
void delay(uint a)
{
uchar j;
while(--a)
{
for(j=0;j<120;j++)
;
}
}
void inint_0()
{
TMOD=0x51;
TH0=0x3c;
TL0=0xb0;
TH1=0x00;
TL1=0x00;
IE=0x82;
}
void display(uint c)
{
P2=0xfe;
P1=num[c/1000];
delay(5);
P2=0xfd;
P1=num[(c/100)%10];
delay(5);
P2=0xfb;
P1=num[(c/10)%10];
delay(5);
P2=0xf7;
P1=num[c%10];
delay(5);
}
yunsuan()
{
x3=x2*256;
x=x1+x3;
return x;
}
void main()
{
inint_0();
TR0=1;
TR1=1;
while(1)
{
y=yunsuan();
display(y);
}
}
void timer0_server() interrupt 1
{
TR0=0;
TR1=0;
TH0=0x3c;
TL0=0xb0;
t++;
if(t==20)
{
t=0;
x2=TH1;
x1=TL1;
TH1=0x00;
TL1=0x00;
}
TR0=1;
TR1=1;
}
|