关于定时器延时(和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);
}
我的思路是想做一个延时函数,比如在配置时序时,某个引脚配置完高或者低电平之后,需要有几毫秒的延时,用这个定时器去实现。进中断实现不方便。请问大神,我这个配置哪里有问题?
一周热门 更多>