2013-11-03 106 views
0

我試圖用MPLAB Simulator調試定時器1中斷,但似乎調試器永遠不會進入中斷服務程序。如何在PIC​​18調試模式下模擬中斷?

定時器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; 
    } 


} 

回答

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


} 
相關問題