【问题标题】:Timer1 on low priority doesn't work低优先级的 Timer1 不起作用
【发布时间】:2014-07-02 20:57:32
【问题描述】:

我正在使用带有PIC18F87J11 的 MPLAB XC8 编译器,我需要使用内部 time1 进行计数。我注意到如果将中断设置为高优先级,我的代码可以正常工作。然而,低优先级它不起作用,我就是想不通。

定时器 1 设置:

       // 1/1 prescalar
       T1CONbits.T1CKPS1 = 1;
       T1CONbits.T1CKPS0 = 1;

       // Use Internal Clock
       T1CONbits.TMR1CS = 0;

       // Timer1 overflow interrupt
       PIE1bits.TMR1IE = 1;

       // Enable Timer 1
       T1CONbits.TMR1ON = 1;

       INTCONbits.PEIE = 1; // Enable Perpherial Interrupt
       INTCONbits.GIE = 1; // Enable Global Interrupt

这很好用

void interrupt high_priority lowISR(void) {
    if (PIR1bits.TMR1IF == 1) {

         Printf("\r\n 1 second");

        PIR1bits.TMR1IF = 0;
    }
    }

但事实并非如此,我也不知道为什么。

void interrupt low_priority lowISR(void) {
    if (PIR1bits.TMR1IF == 1) {

         Printf("\r\n 1 second");

        PIR1bits.TMR1IF = 0;
    }


}

我错过了什么?

【问题讨论】:

    标签: embedded interrupt microcontroller pic microchip


    【解决方案1】:

    您是否真的将定时器 1 设置为使用低优先级中断,并且您是否启用了中断优先级控制(默认情况下,IIRC,所有中断都使用高优先级,而不管单个中断源优先级位如何)。

    【讨论】:

      【解决方案2】:

      我缺少以下内容,添加它们解决了我的问题。我找到了他们here

      IPR1bits.TMR1IP = 0;            // Timer 1 -> Low priority interrupt group
      PIE1bits.TMR1IE = 1;            // Enable Timer1 interrupt
      
      RCONbits.IPEN = 1;              // Enable interrupt system priority feature
      INTCONbits.GIEH = 1;            // Enable high priority interrupts
      INTCONbits.GIEL = 1;            // Enable low priority interrupts
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-09-24
        • 2014-10-27
        • 1970-01-01
        • 2020-03-22
        相关资源
        最近更新 更多