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

📄 timer0.c

📁 基于芯片DS1302的湍流实时时钟的实现
💻 C
字号:
/**********************************************************************
* System Name		DOOR
* Source Name		timer0.c
* Function			定时器
* Version	Date		Editor		Modification
* 1.0		2007/05/09	周斌		做成
**********************************************************************/

#include <avr/io.h>
#include <avr/interrupt.h>
#include "global.h"
#include "timer0.h"


//定时器初始值列表
#define TCNT0_14M_1MS 0xC6
#define TCNT0_14M_2MS 0x8D
#define TCNT0_14M_3MS 0x53
#define TCNT0_14M_4MS 0x1A




/**********************************************************************
* Function Name		led_init
* Function Desc		LED初始化函数
* Return Value		无
* Parameter         无
* Version	Date		Editor		Modification
* 1.0		2007/05/09	周斌		做成
**********************************************************************/
void timer0_init(UCHAR t_time)
{
	TCCR0  = 0x00;//停止定时器
	switch(t_time)
	{
		case TIMER0_1MS:
			TCNT0  = TCNT0_14M_1MS;//初始值
			break;
		case TIMER0_2MS:
			TCNT0  = TCNT0_14M_2MS;//初始值
			break;
		case TIMER0_3MS:
			TCNT0  = TCNT0_14M_3MS;//初始值
			break;
		case TIMER0_4MS:
			TCNT0  = TCNT0_14M_4MS;//初始值
			break;
		default:
			TCNT0  = TCNT0_14M_1MS;//初始值
			break;
	}			
	OCR0   = 0x19;//匹配值
	TIMSK |= 0x01;//中断允许
	TCCR0  = 0x03;//启动定时器
}

SIGNAL(SIG_OVERFLOW0)
{
	static UCHAR timer0_task_led1_counter=0;
	//
	TCNT0 = TCNT0_14M_1MS;	//RELOAD TIMER0
	//TIMER0 TASK ACTION
	timer0_task_action_stat = TIMER0_TASK_ACTION_READY;
	//TIMER0 TASK LED1
	timer0_task_led1_counter++;
	if(timer0_task_led1_counter>=250)
	{
		timer0_task_led1_stat = TIMER0_TASK_LED1_READY;
		timer0_task_led1_counter=0;
	}
}

⌨️ 快捷键说明

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