|
利用計時器的原理設計的定時器,含有中斷程序
- #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
2022-7-12 20:49 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
44.15 KB, 下載次數: 7, 下載積分: 黑幣 -5
|