inline void vMBPortTimersEnable( ) { /* Enable the timer with the timeout passed to xMBPortTimersInit( ) */ TIM2_ClearFlag(TIM2_FLAG_UPDATE); TIM2_SetCounter(0x00); TIM2_ITConfig(TIM2_IT_UPDATE, ENABLE); TIM2_Cmd(ENABLE); }
void timerInit(void) { /* TIM2 initial */ TIM2_TimeBaseInit(TIM2_PRESCALER_16,7812); TIM2_ITConfig( TIM2_IT_UPDATE , ENABLE); TIM2_SetCounter(0x0000); /*计时器打开*/ TIM2_Cmd(ENABLE); TIM2_ClearFlag(TIM2_FLAG_UPDATE); }
void __delay_us(uint16_t delay) { delay = delay * 16; uint16_t count = 0; TIM2_ARRPreloadConfig(DISABLE); TIM2_SetAutoreload(delay); TIM2_SetCounter(0); TIM2_Cmd(ENABLE); while(TIM2_GetFlagStatus(TIM2_FLAG_Update) == RESET); TIM2_ClearFlag(TIM2_FLAG_Update); TIM2_Cmd(DISABLE); }
void setTimeoutCheck(Mod_Timer_Check_TypeDef act) { if (act == MOD_TIMER_START) { TIM2_Cmd(DISABLE); TIM2_SetCounter(0); TIM2_Cmd(ENABLE); modInts.timeout_int_en = TRUE; } else if (act == MOD_TIMER_PAUSE) { TIM2_Cmd(DISABLE); modInts.timeout_int_en = FALSE; } else if (act == MOD_TIMER_RESUM) { TIM2_Cmd(ENABLE); modInts.timeout_int_en = TRUE; } else if (act == MOD_TIMER_STOP) { TIM2_Cmd(DISABLE); modInts.timeout_int_en = FALSE; } }