📄 timer.c
字号:
#pragma REGISTERBANK(0)
#include <reg52.h>
#include <intrins.h>
#include <stdlib.h>
#include "def.h"
#include "timer.h"
#include "at24c02.h"
#include "mtv130.h"
extern bit PIN_SIGIND;
extern void check_key(void);
volatile unsigned char jiffies = 0;
bit timerbh_pending = 0;
#if 1
static volatile unsigned char xjiffies = 0;
struct time_val xtime = { 0, 0, 0 };
#endif
#define INIT_T0 (65536L - (F_OSC/12)/HZ)
#define MAX_T0 10
static unsigned char t0_count = MAX_T0;
void timer_bh(void)
{
#if 1
while (xjiffies != jiffies) {
xjiffies++;
xtime.msec10 += 100/HZ;
t0_count--;
}
while (xtime.msec10 >= 100) {
xtime.sec++;
xtime.msec10 -= 100;
}
while (xtime.sec >= 60) {
xtime.min++;
xtime.sec -= 60;
}
#endif
check_key();
#if 0
if (t0_count == 0) {
TR1 = 0;
if (TL1 < MAX_T0*2/4)
PIN_SIGIND = 1;
else {
PIN_SIGIND = 0;
if (TL1 > MAX_T0*11/4)//55/HZ)
HZ_IND = 1;
else
HZ_IND = 0;
}
TMOD = 0x51;
TH1 = TL1 = TF1 = 0;
TR1 = 1;
t0_count = MAX_T0;
}
#endif
}
void timer_init(void)
{
TH0 = (unsigned char)(INIT_T0>>8);
TL0 = (unsigned char)INIT_T0;
TR0 = 1;
ET0 = 1;
HZ_IND = 1;
TH1 = TL1 = TF1 = 0;
TR1 = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -