⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 这是一个远程温度计 MCU: AT89S52 温度传感器: DS18B20 晶振: 12MHz 使用串口连接,在PC端使用"超级终端"打开 设置如下: 波特率: 4800 数据
💻 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 + -