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);
}
2 个解决方案
#1
要配置中断啊
#2
不想用中断,直接一个延时函数,我这个还有哪里有问题?
#1
要配置中断啊
#2
不想用中断,直接一个延时函数,我这个还有哪里有问题?