定时器配置:
static void App_Timer0Cfg(void)
{
uint16_t u16ArrValue = 0x10000 - 6000; // 1ms中断一次(24MHz系统时钟)
uint16_t u16CntValue = 0x10000 - 6000;
stc_bt_mode0_cfg_t stcBtBaseCfg;
DDL_ZERO_STRUCT(stcBtBaseCfg);
Sysctrl_SetPeripheralGate(SysctrlPeripheralBaseTim, TRUE); // Base Timer外设时钟使能
stcBtBaseCfg.enWorkMode = BtWorkMode0; // 定时器模式
stcBtBaseCfg.enCT = BtTimer; // 定时器功能,计数时钟为内部PCLK
stcBtBaseCfg.enPRS = BtPCLKDiv4; // PCLK/4
stcBtBaseCfg.enCntMode = Bt16bitArrMode; // 自动重载16位计数器/定时器
stcBtBaseCfg.enGateP = BtGatePositive;
stcBtBaseCfg.bEnTog = FALSE;
stcBtBaseCfg.bEnGate = FALSE;
Bt_Mode0_Init(TIM0, &stcBtBaseCfg);
Bt_M0_ARRSet(TIM0, u16ArrValue); // 设置重载值
Bt_M0_Cnt16Set(TIM0, 0); // 设置计数初值
Bt_ClearAllIntFlag(TIM0); // 清中断标志
Bt_Mode0_EnableIrq(TIM0); // 使能TIM0中断
EnableNvic(TIM0_IRQn, IrqLevel0, TRUE); // TIM0中断使能
Bt_M0_Run(TIM0); // 启动定时器
}
volatile uint32_t delaytick = 0;
void Tim0_IRQHandler(void)
{
if (TRUE == Bt_GetIntFlag(TIM0, BtUevIrq))
{
Bt_ClearIntFlag(TIM0, BtUevIrq); // 中断标志清零
delaytick++;
}
}
|