如何使用PIC18在调试模式下模拟中断?

时间:2013-11-03 19:56:09

标签: c timer embedded interrupt microcontroller

我尝试使用MPLAB Simulator调试定时器1中断,但似乎调试器永远不会进入中断服务程序。

计时器1的设置对我来说似乎是对的,不确定我是否错过了其他内容。这是datasheet

/*  
     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;
    }


}

1 个答案:

答案 0 :(得分: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;
    }


}