本帖最后由 lanmanck 于 2019-11-18 18:59 编辑
代码:
void TIMER16_IRQHandler(void)
{
if(SET == timer_interrupt_flag_get(TIMER16, TIMER_INT_UP)){
/* clear channel 0 interrupt bit */
timer_interrupt_flag_clear(TIMER16, TIMER_INT_UP);
/* toggle selected led */
g_bsl.tick_1ms++;
}
}
uint32_t get_timer_tick(void)
{
return g_bsl.tick_1ms;
}
void delay_1ms(uint32_t xms)
{
volatile uint32_t tick,diff=xms;
SET_TICK(tick);
/*while(GET_DIFF_TICK(tick) < diff){}*/
while(xms){
diff = (0x100000+get_timer_tick()-tick)&0xFFFFF ;
while(diff < 1){
diff = (0x100000+get_timer_tick()-tick)&0xFFFFF ;
}
SET_TICK(tick);
xms--;
}
}
这个函数就是延时多少毫秒,这个毫秒计数器通过一个毫秒中断一直增加。
这个是5.0编译器的结果,杠杠的:
这个是6.0的结果,不加volatile直接给你优化了,等级为Oz/Os等都试过了,循环一直出不去,我没辙了,大家救救我吧:
|