timer.c

来自「通用OSD控制(51单片机控制的TFTLCD源码,MTV018)」· C语言 代码 · 共 48 行

C
48
字号
#pragma REGISTERBANK(0)

#include "Header.H"

//extern bit PIN_SIGIND;

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)
{
	extern void check_key(void);

	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;
	}
	check_key();
}

void timer_init(void)
{
	TH0 = (unsigned char)(INIT_T0>>8);
	TL0 = (unsigned char)INIT_T0;
	TR0 = 1;
	ET0 = 1;
	HZ_IND = 1;// Default PAL System
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?