#include "tim4.h"
#include "stm8s_tim4.h"
#define TIM4_PERIOD 124
void Dely1ms(void)
{
TIM4_DeInit();
/* Time base configuration */
// 8M/64=125000HZ
// (x + 1)/125000=0.001s = 1ms
// x = 124
TIM4_TimeBaseInit(TIM4_PRESCALER_64, TIM4_PERIOD);
/* Clear TIM4 update flag */
TIM4_ClearFlag(TIM4_FLAG_UPDATE);
/* Enable update interrupt */
TIM4_ITConfig(TIM4_IT_UPDATE, DISABLE);
/* Enable TIM4 */
TIM4_Cmd(ENABLE);
while( SET != TIM4_GetFlagStatus(TIM4_FLAG_UPDATE));
}
void DelyMs(uint32_t ms)
{
while(ms--) Dely1ms();
}
时间: 2024-10-24 23:29:41