第1个回答 2009-04-22
#include <reg51.h>
unsigned char time_1m=120;
unsigned char time_1h=60;
//timer init
void initTimer(void) //1Mhz晶振
{
TMOD=0x1;
TH0=0x5d;
TL0=0x3e;
}
//timer0/counter0 interrupt
void timer0(void) interrupt 1 // 500MS 中断一次
{
TH0=0x5d;
TL0=0x3e;
time_1m--;
if(time_1m==0)
{
time_1m=120;
//add your code here.
time_1h--;
if(time_1h==0)
{
time_1h=60;
//add your code here.
}
}
}
//the main fun
void main(void)
{
initTimer(); //int0定时器
TR0=1;
ET0=1;
EA=1;
while(1);
}本回答被提问者和网友采纳