
51单片机编写延时1分钟、1小时的子程序
展开全部
#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);
}
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);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2025-08-04 广告
联系方式:13671592388上海实邦电子科技有限公司是一家专业电子产品开发与ODM/OEM/电子制造服务(EMS)企业,具有多年基于消费电子产品、工业自动化产品、机电控制产品的PCBA开发与生产经验,更有多年的单片机开发及工业控制电路设...
点击进入详情页
本回答由上海实邦电子科技提供
展开全部
不用谢哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询