51单片机编写延时1分钟、1小时的子程序

如上,多谢
linimbus 你好,你用的是C语言吧,呵呵,还是谢了
期待好心人解答,谢谢!

第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);

}本回答被提问者和网友采纳
第2个回答  2009-04-22
不用谢哈