秒表 StopWatch演示
#include <REGX52.H>
#include "LCD1602.h"
void Timer0Init();
unsigned char Ms=0,Sec=40,Min=59,Hour=23;
main(){
LCD_Init();
Timer0Init();
LCD_ShowString(1,1,"StopWatch:");
LCD_ShowString(2,3,": : .");
while(1){
LCD_ShowNum(2,1,Hour,2);
LCD_ShowNum(2,4,Min,2);
LCD_ShowNum(2,7,Sec,2);
LCD_ShowNum(2,10,Ms,2);
}
}
/**
* @brief 定时器0中断程序;
* @param
* @retval
*/
void Timer0_Routine() interrupt 1{
static unsigned int T0Count;
TL0=0x18;
TH0=0xFC;//设置定时初始值
T0Count++;
if(T0Count>=10){
T0Count=0;
Ms++;
if(Ms>=100){
Ms=0;
Sec++;
if(Sec>=60){
Sec=0;
Min++;
if(Min>=60){
Min=0;
Hour++;
if(Hour>=24){
Hour=0;
}
}
}
}
}
}