0

我尝试使用 MPLAB 模拟器调试定时器 1 中断,但调试器似乎从未进入中断服务程序。

计时器 1 的设置对我来说似乎是正确的,不确定我是否错过了其他东西。这是数据表

/*  
     File: main.c
     Date: 2011-SEP-4
     Target: PIC18F87J11
     IDE: MPLAB 8.76
     Compiler: C18 3.40

 */
#include <p18cxxx.h>

#pragma config FOSC = INTOSC, WDTEN = OFF, XINST = OFF

#pragma code HighISR = 0x08 // high priority 0x18
#pragma interrupt HighISR



int time = 0;

void main(void) {
    /* set FOSC clock to 8MHZ */
    OSCCON = 0b01110000;

    /* turn off 4x PLL */
    OSCTUNE = 0x00;

    /* make all ADC inputs digital I/O */
    ANCON0 = 0xFF;
    ANCON1 = 0xFF;

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

    // 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



    while (1);

}


// Timer Interrupt

void HighISR(void) {
    if (PIR1bits.TMR1IF == 1) {
        time++;
        PIR1bits.TMR1IF = 0;
    }


}
4

1 回答 1

0

刚刚发现我错过了什么......

 #pragma code highVector=0x08
        void HighVector (void)
        {
            _asm goto HighISR _endasm
        }
        #pragma code /* return to default code section */

现在整个程序看起来像这样

/*  
     File: main.c
     Date: 2011-SEP-4
     Target: PIC18F87J11
     IDE: MPLAB 8.76
     Compiler: C18 3.40

 */
#include <p18cxxx.h>

#pragma config FOSC = INTOSC, WDTEN = OFF, XINST = OFF
#pragma interrupt HighISR



int time = 0;

void main(void) {
    /* set FOSC clock to 8MHZ */
    OSCCON = 0b01110000;

    /* turn off 4x PLL */
    OSCTUNE = 0x00;

    /* make all ADC inputs digital I/O */
    ANCON0 = 0xFF;
    ANCON1 = 0xFF;

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

    // 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



    while (1);

}


 #pragma code highVector=0x08
        void HighVector (void)
        {
            _asm goto HighISR _endasm
        }
        #pragma code /* return to default code section */


// Timer Interrupt
void HighISR(void) {
    if (PIR1bits.TMR1IF == 1) {
        time++;
        PIR1bits.TMR1IF = 0;
    }


}
于 2013-11-03T20:11:07.057 回答