关于定时器延时(和sys
tick一样延时毫秒和微秒),为什么我写的不行呢?求大神帮忙看看,哪里的问题?
void timdelay_init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM7,ENABLE);
TIM_TimeBaseInitStruct.TIM_Prescaler=72-1;
TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit (TIM7,&TIM_TimeBaseInitStruct);
}
void timdelay_us(int nus)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_TimeBaseInitStruct.TIM_Period=nus;
TIM_TimeBaseInitStruct.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit (TIM7,&TIM_TimeBaseInitStruct);
TIM_SelectOnePulseMode(TIM7,TIM_OPMode_Single);
TIM_Cmd (TIM7,ENABLE);
while(TIM_GetFlagStatus(TIM7,TIM_IT_Update)==RESET);
TIM_ClearFlag(TIM7,TIM_IT_Update);
}
一周热门 更多>