|
利用计时器的原理设计的定时器,含有中断程序
- #include <REGX52.H>
- #include "Delay.h"
- #include "LCD1602.h"
- #include "Timer.h"
- #include "key.h"
- unsigned int sec=0,min=0,hour=0;
- unsigned char key1=0;
- void main()
- {
- LCD_Init();
- Timer0_Init();
-
- while(1)
- {
- LCD_ShowString(1,1,"Clock:");
- LCD_ShowString(2,1," : :");
- LCD_ShowNum(2,1,hour,2);
- LCD_ShowNum(2,4,min,2);
- LCD_ShowNum(2,7,sec,2);
- key1=key();
- if(key1)
- {
- if(key1==1){sec=0;min=0;hour=0;}
- if(key1==2) sec++;
- if(key1==3) min++;
- if(key1==4) hour++;
- }
- }
- }
- void Timer0_Rountine() interrupt 1
- {
- static unsigned int T0count;
- TL0 = 0x18;
- TH0 = 0xFC;
- T0count++;
- if(T0count>=1000)
- {
- T0count=0;
- sec++;
- if(sec>=60)
- {sec=0;min++;}
- if(min>=60)
- {min=0;hour++;}
- if(hour>=24)
- {hour=0;}
-
- }
- }
复制代码
|
-
-
定时器.zip
44.15 KB, 下载次数: 7, 下载积分: 黑币 -5
|