基于Proteus的51系列单片机设计与仿真
源代码在线查看: 59秒计时器的设计.c
/****************************************************************************
59秒计时器的设计
******************************************************************************/
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit p21=P2^1;
sbit p20=P2^0;
uint t=0;
uchar count;
uchar counth,countl;
const uchar tab[]={ 0XC0,0XF9,0XA4,0XB0,0X99,/*0~9*/
0X92,0X82,0XF8,0X80,0X90};
void delay(void) //延时
{ uint i;
for(i=0;i }
void time0_server_(void) interrupt 1
{
TH0=0x3C; //定时时间为 50ms 12MHZ的晶振
TL0=0xB0;
t++;
}
void Init_t0(void) //定时器初始化
{
TMOD=0X01; //选择方式1
TH0=0x3C;
TL0=0xB0;
EA=1;
ET0=1;
TR0=1;
}
void display(void)
{counth=count/10;
countl=count%10;
P1=tab[counth]; //十位显示
p21=1;
delay();
p21=0;
P1=tab[countl]; //十位显示
p20=1;
delay();
p20=0;
}
void main(void)
{ count=0;
while(1) //0到99的显示
{if(t==20)
{if(count==59)
count=0;}
t=0;
count++;
display();
}
}