📄 timer.c
字号:
/*------------------------------------------------------------------------------
timer.c:
------------------------------------------------------------------------------*/
#include <reg52.h> /* special function register 8052 */
#include "timer.h" /* timer definition file */
#include "measure.h"
static uchar intcycle = 0;
/******************************************************************************/
/* Timer 0 interrupt service function */
/* executes each 50ms @ 12 MHz Crystal Clock */
/******************************************************************************/
void timer0(void) interrupt 1 using 1
{ /* Int Vector at 000BH, Reg Bank 1 */
TH0 = PRELOAD_HIGH;
TL0 = PRELOAD_LOW;
/* update current time */
++ intcycle;
}
void init_timer0(void) {
/* setup the timer 0 interrupt */
TH0 = PRELOAD_HIGH; /* set timer period */
TL0 = PRELOAD_LOW;
TMOD = (0xF0 & TMOD) | 0x01; /* select mode 1 */
TR0 = 1; /* start timer 0 */
ET0 = 1; /* enable timer 0 interrupt */
}
void do_timer0(void) {
current.time.sec += intcycle / SEC_COUNT;
DISABLE();
intcycle %= SEC_COUNT;
ENABLE();
if (current.time.sec >= 60) { /* update second counter */
current.time.sec -= 60;
if (++current.time.min == 60) { /* update minute counter */
current.time.min = 0;
if (++current.time.hour == 24) { /* update hour counter */
current.time.hour = 0;
}
}
}
/* end of if( ++current.time.msec... */
}
bool check_timer0(void) {
return (intcycle >= SEC_COUNT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -