#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uchar num,disnum;
uchar code table_du[]={
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90};
void display(uint);
void delay(uchar);
void main()
{
EA=1;
ET0=1;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
while(1)
{
if(num==20)
{
num=0;
if(disnum==1000)
disnum=0;
disnum++;
}
display(disnum);
}
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
void display(uint disnum)
{
P0=table_du[disnum/1000];
dula=1;
dula=0;
P2=0xfe;
wela=1;
wela=0;
delay(10);
P0=table_du[disnum/100];
dula=1;
dula=0;
P2=0xfd;
wela=1;
wela=0;
delay(10);
P0=table_du[disnum%100/10];
dula=1;
dula=0;
P2=0xfb;
wela=1;
wela=0;
delay(10);
P0=table_du[disnum%100%10];
dula=1;
dula=0;
P2=0xf7;
wela=1;
wela=0;
delay(10);
}
void delay(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=200;b>0;b--);
}
|