1.Timer配置
timer0,timer1是32位计数器,而其他计数器只有16位,则timerConfig0.loadValue的值应合理设置,不应溢出
#define CLK (48000000)
#define Delay1s (CLK-1)
void Timer_Init(void)
{
TIMER_ConfigType timerConfig0 = {0};
/* configure TIMER channel 0, only enable timer */
timerConfig0.loadValue = Delay1s; ///1s timeout
timerConfig0.interruptEn = 1; //中断使能
timerConfig0.linkMode = 0; //禁能链接
timerConfig0.timerEn = 1; //使能TIMER0
TIMER_SetCallback(TIMER0, TIM0_Task);
TIMER_Init(TIMER0, &timerConfig0); //TIMER配置初始化
}
void TIM0_Task(uint8_t timerIndex)
{
if (TIMER_GetIntFlag(TIMER0))
{
LED_TOGGLE;
TIMER_ClrIntFlag(TIMER0); //清中断标志
TIMER_Disable(TIMER0);
}
}