
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);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2020-01-15 广告
单片机(Microcontrollers)是一种集成电路芯片,是采用超大规模集成电路技术把具有数据处理能力的中央处理器CPU、随机存储器RAM、只读存储器ROM、多种I/O口和中断系统、定时器/计数器等功能(可能还包括显示驱动电路、脉宽调制...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
不用谢哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询