源代码如下
#include <reg51.h>
#define uchar unsigned char
#define Fosc 12000000
#define t50ms (65536-Fosc*50/12000)
uchar date a=20;
uchar date chuzhi=0;
uchar code tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,
0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
void dis(uchar cct)
{ P1=tab[cct/10];
P2=tab[cct%10];
}
void int0f(void) interrupt 0using1
{ F0=!F0;
if(F0==0)
TR1=1;
else
TR1=0;
}
void t1f(void) interrupt 3using 0
{ TH1=t50ms/256;
TL1=t50ms%256;
a=a-1;
if(a==0)
{ a=20;
chuzhi=chuzhi+1;
if(chuzhi==100)
EA=0;
else
dis(chuzhi);
}
}
void main()
{ TMOD=0x10;
EA=1;
ET1=1;EX0=1;
TR1=1;IT0=1;
TH1=t50ms/256;
TL1=t50ms%256;
dis(chuzhi);
for(;;);
}
|