You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.6 KiB

1 year ago
#include "ttss_time_stc.h"
#define D_TIMER_COUNT(t,clk,timeInUs) (U16)(65536 - (clk) / 1000 * timeInUs / 1000 / t)
/*************初始化定时器0由 stc-isp v6.86L定时器计算器生成******************/
#if(MainFre_5M == D_sys_MainFre)
#elif(MainFre_22M == D_sys_MainFre)
void L0_timer0_Init(void)//void Timer0Init(void) //12500微秒@22.1184MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初始值
TH0 = 0xA6; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
#elif(MainFre_27M == D_sys_MainFre)
#elif(MainFre_44M == D_sys_MainFre)
void L0_timer0_Init(void)/////void Timer0Init(void) //12.5m秒@44.0800MHz
{
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xA3; //设置定时初始值
TH0 = 0x4C; //设置定时初始值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void L0_timer4_Init(void)/////void Timer4_Init(void) //100微秒@44.2368MHz
{
T4T3M |= 0x20; //定时器时钟1T模式
T4L = 0xB8; //设置定时初始值
T4H = 0xEE; //设置定时初始值
T4T3M |= 0x80; //定时器4开始计时
}
#else ///MainFre_11M
////#warn
void L0_timer0_Init(void)
{
U16 val = D_TIMER_COUNT(12,D_sys_MainFre,D_sys_Jiffies * 1000);
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
//TL0 = 0x00; //设置定时初值
//TH0 = 0x4C; //设置定时初值
TL0 = val; //设置定时初值
TH0 = val >> 8; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
#endif//D_sys_MainFre)
#if 0
/// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms
///相当于1.39年后t_10ms 溢出,对于电池供电的系统而言 完全可以满足
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年
s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 验证
#endif
//10---87 10s
/********************** Timer0中断函数************************/
/// 和 L0_timer0_Init 关联,需要配置 bsp_config.h中的 D_sys_MainFre
/// 默认10ms 作为TTSS系统的定时引擎
void timer0_isrHandle (void) D_SERVE_TIMER0
{//
NOP(); NOP(); NOP();
TF0 = 0;
L1_task_tick_callback(); ///系统中的1sflag 和以10ms为颗粒的延时使用 为tdelay服务
/// BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0);
NOP(); NOP(); NOP();
}
void L1_timer0_Init(void)
{
///step1:时钟
///step2:模块使能
///step3:启动
///step4:模块中断使能
///step5:全局中断使能
L0_timer0_Init();
ET0 = 1;///经常因为替换L0_timer0_Init(由stcisp例程生成) 改指令漏掉
}