2013-11-03 78 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; 
    } 


} 
相关问题