📄 timer0.c
字号:
/**********************************************************************
* System Name DOOR
* Source Name timer0.c
* Function 定时器0
* Version Date Editor Modification
* 1.0 2007/05/09 周斌 做成
**********************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "global.h"
#include "timer0.h"
#include "uart0.h"
#include "uart2.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 timer0初始化函数
* 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;//启动定时器
}
/**********************************************************************
* Function Name SIGNAL(SIG_OVERFLOW0)
* Function Desc timer0溢出中断
* Return Value 无
* Parameter 无
* Version Date Editor Modification
* 1.0 2007/05/15 周斌 做成
**********************************************************************/
SIGNAL(SIG_OVERFLOW0)
{
static UCHAR timer0_task_action_counter = 0;
static UCHAR timer0_task_led1_counter = 0;
static UCHAR timer0_task_rfid_counter = 0;
static UCHAR timer0_task_uart0pack_counter = 0;
static UCHAR timer0_task_uart2pack_counter = 0;
//
TCNT0 = TCNT0_14M_1MS; //RELOAD TIMER0
//TIMER0 TASK ACTION - 10ms
timer0_task_action_counter++;
if(timer0_task_action_counter >= 10)
{
timer0_task_action_stat = TIMER0_TASK_ACTION_READY;
}
//TIMER0 TASK LED1 - 250ms
timer0_task_led1_counter++;
if(timer0_task_led1_counter >= 250)
{
timer0_task_led1_stat = TIMER0_TASK_LED1_READY;
timer0_task_led1_counter=0;
}
//TIMER0 TASK RFID - 50ms
timer0_task_rfid_counter++;
if(timer0_task_rfid_counter >= 50)
{
timer0_task_rfid_stat = TIMER0_TASK_RFID_READY;
timer0_task_rfid_counter=0;
}
//TIMER0 TASK UART0PACK - 2ms ,按照时间清除残缺的包
timer0_task_uart0pack_counter++;
if(timer0_task_uart0pack_counter >= 200)
{
if(timer0_task_uart0pack_stat == TIMER0_TASK_UART0PACK_NEW)
{
timer0_task_uart0pack_stat = TIMER0_TASK_UART0PACK_OLD;
}
else if(timer0_task_uart0pack_stat == TIMER0_TASK_UART0PACK_OLD)
{
timer0_task_uart0pack_stat = TIMER0_TASK_UART0PACK_BAD;
}
else if(timer0_task_uart0pack_stat == TIMER0_TASK_UART0PACK_BAD)
{
//uart0_clear_buffer();
}
timer0_task_uart0pack_counter = 0;
}
//TIMER0 TASK UART2PACK - 2ms ,按照时间清除残缺的包
timer0_task_uart2pack_counter++;
if(timer0_task_uart2pack_counter >= 200)
{
if(timer0_task_uart2pack_stat == TIMER0_TASK_UART2PACK_NEW)
{
timer0_task_uart2pack_stat = TIMER0_TASK_UART2PACK_OLD;
}
else if(timer0_task_uart2pack_stat == TIMER0_TASK_UART2PACK_OLD)
{
timer0_task_uart2pack_stat = TIMER0_TASK_UART2PACK_BAD;
}
else if(timer0_task_uart2pack_stat == TIMER0_TASK_UART2PACK_BAD)
{
//uart2_clear_buffer();
}
timer0_task_uart2pack_counter = 0;
}
//TIMER0 TASK UART1TIMEOUT - 2ms ,如果时间超时,重新发送数据包
timer0_task_uart1timeout_stat++;
if(timer0_task_uart1timeout_stat >= 100)
{
if(timer0_task_uart1timeout_stat == TIMER0_TASK_UART0TIMEOUT_WAIT)
{
timer0_task_uart1timeout_stat = TIMER0_TASK_UART0TIMEOUT_TIMEOUT;
}
else if(timer0_task_uart1timeout_stat == TIMER0_TASK_UART0TIMEOUT_TIMEOUT)
{
timer0_task_uart1timeout_stat = TIMER0_TASK_UART0TIMEOUT_READY;
}
timer0_task_uart1timeout_stat = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -