定时中断里面加延迟,为什么程序就挂掉了

2019-03-25 20:05发布

        extern void delayMs(unsigned int delayInMs);
      void delayMs(unsigned int delayInMs)
        {
                T2TCR = 0x02;                /* reset timer 计数器复位*/
                T2PR  = 0x00;                /* set prescaler to zero 设置预分频的值为0 */
                T2MR0 = delayInMs * (FPCLK-1);//匹配寄存器0   FPCLK等于24000000
                T2IR  = 1;                /* reset all interrrupts 设置全部中断寄存器*/
                T2MCR = 0x03;                /* stop timer on match */
                T2TCR = 0x01;                /* start timer 开启定时/计数器 */
          
                /* wait until delay time has elapsed */
                while (T2TCR & 0x01);
        }   
void TIMER1_IRQHandler (void)里面加了一个延迟
{
    delayMs(10); //定时时间10秒钟

}
程序只是示意表达我的意思,就是在定时器1中断的情况下,做个延迟

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
13条回答
dontium
2019-03-26 13:23
中断里面加延时??

延时函数,因为执行的时间长,在必要的时候才使用它。中断,本来是为了节约资源的,还要加上延时做什么呢?

如果,这个延时函数要主程序中执行,进入中断后也要执行,这不是引起冲突了吗?

要解决这个问题,  --------- 定义“再入函数”

一周热门 更多>