我做了个ms定时等待函数,做法是:首先初始化定时器4,用到的时候启动定时器4并开中断,赋值,中断中给此值减一 当此值为0时,关定时器和中断。问题是:TIM4ms_count在中断中减到0后,在while(TIM4ms_count);死循环了。自己都整糊涂了,哪位大侠指点一下! void Delayms(uint16_t count) { TIM_Cmd(TIM4, ENABLE); TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE); TIM4ms_count = count; while(TIM4ms_count); //死在这里了 printf("Delayms %d..........\r\n",TIM4ms_count); //等待中断次数到达 TIM_ITConfig(TIM4, TIM_IT_Update, DISABLE);//关中断 TIM_Cmd(TIM4, DISABLE); //关掉计数器 } uint16_t TIM4ms_count; void TIM4_IRQHandler(void) { if(TIM4ms_count>0) TIM4ms_count--; else { TIM_ITConfig(TIM4, TIM_IT_Update, DISABLE);//关中断 TIM_Cmd(TIM4, DISABLE); //关掉计数器 } } |