中断触发定时器:99秒计时+99秒倒计时.doc

上传人:白大夫 文档编号:3368118 上传时间:2019-08-18 格式:DOC 页数:4 大小:22.50KB
返回 下载 相关 举报
中断触发定时器:99秒计时+99秒倒计时.doc_第1页
第1页 / 共4页
亲,该文档总共4页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《中断触发定时器:99秒计时+99秒倒计时.doc》由会员分享,可在线阅读,更多相关《中断触发定时器:99秒计时+99秒倒计时.doc(4页珍藏版)》请在三一文库上搜索。

1、中断触发定时器:99秒计时+99秒倒计时#includecode unsigned char tab=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;unsigned char Dis_Shiwei;unsigned char Dis_Gewei;void delay(unsigned int cnt)while(-cnt);main()TMOD |=0x01; /10ms in 12M crystal,工作在模式一,16位定时器TH0=0xd8;TL0=0xf0;IE= 0x82; /打开中断TR0=1; /打开定时开关while(1)P0

2、=Dis_Shiwei;P2=0;delay(300);P0=Dis_Gewei;P2=1;delay(300);void TIm(void) interrupt 1 using 1staTIC unsigned char second,count;TH0=0xd8;TL0=0xf0;count+;if (count=100) /100x10mscount=0;second+;if(second=100)second=0;Dis_Shiwei=tabsecond/10;Dis_Gewei=tabsecond%10;/*定时器设定为:TH0=0xd8;TL0=0xf0;经确定时10ms。从程序开

3、始执行,每当主程序中的16位数发生溢出则触发中断,主程序保护现场并调用中断子程序,也可以写为:TH0=(65536-10000)/256;TL0=(65536-10000)%256。秒脉冲的产生要求精确定时1s,实际情况可能有延误。1 0000 0000 0000 00001101 1000 1111 00000010 0111 0001 0000TIme=16(1+16+32+64+512)=16*625=10000us=10ms主函数中的关于定时器和中断的控制位:TMOD |=0x01; /模式选择TH0=0xd8; /高8位TL0=0xf0; /低8位IE= 0x82; /打开中断TR0

4、=1; /打开定时开关(定时器运行控制位,置1启动定时器0)TMOD |= 0x01; /使用模式1,16位定时器TH0=0x00;TL0=0x00;EA=1; /总中断打开ET0=1; /定时器中断打开TR0=1; /定时器开关打开*/_功能:99秒倒计时时间:2010718_#includecode unsigned char tab=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;unsigned char Dis_Shiwei;unsigned char Dis_Gewei;void delay(unsigned int cnt)wh

5、ile(-cnt);main()TMOD |=0x01; /10ms in 12M crystalTH0=0xd8;TL0=0xf0;IE= 0x82;TR0=1;while(1)P0=Dis_Shiwei;P2=0;delay(300);P0=Dis_Gewei;P2=1;delay(300);void TIm(void) interrupt 1 using 1statIC unsigned char second=99,count;TH0=0xd8;TL0=0xf0;count+;if (count=100)count=0;second-;if(second=0)second=99;Dis_Shiwei=tabsecond/10;Dis_Gewei=tabsecond%10;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1