27,382
社区成员
发帖
与我相关
我的任务
分享
#include<reg51.h>
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x18};
unsigned time=0;//为一秒的计数周期
unsigned char count=0;为59秒的计数周期
unsigned char a,b;//a为十位上的数,b为个位上的数
delay(unsigned int s )//延时函数几MS
{
unsigned char i;
while(s--)
for(i=0;i<240;i++);
}
display(unsigned char shiwei,unsigned char gewei)//显视函数
{
P2=0XFE;
P0=tab[gewei];
delay(10);
P0=0XFF;
P2=0XFD;
P0=tab[shiwei];
delay(500);
P0=0XFF;
}
void timer0() ;//定时器0的中断函数声明
main()
{
TMOD=0x01;//定时器0工作方式1
TH0=0x3c;
TL0=0xb0;//设置初值为50MS
EA=1;
ET0=1;
TR0=1;
while(1)
{
a=count/10;
b=count%10;
display(a,b);
}
void timer0() interrupt 1//定时器0的中断函数入口程序
{
TH0=0x3c;
TL0=0xb0;
time++;
if(time==20)
{
time=0;
count++;
if(count==59)
count=0;
}
}