What did I do wrong? - Interrupt on change bit

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Jan 18, 2010.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    I have a momentary contact switch tied to +5V and connected to RB6 of a 18F14K22.

    I can see the input changing state via the debugger but the interrupt does not seem to be working when the button is pressed. I know it is probably something simple but I am just not seeing it.


    Code ( (Unknown Language)):
    1.  
    2.  
    3. void InterruptServiceHigh(void);
    4.  
    5.  
    6. //----------------------------------------------------------------------------
    7. // High priority interrupt vector
    8.  
    9. #pragma code InterruptVectorHigh = 0x08
    10. void InterruptVectorHigh (void)
    11. {
    12.   _asm
    13.     goto InterruptServiceHigh //jump to interrupt routine
    14.   _endasm
    15. }
    16. #pragma code    // declare executable instructions
    17.  
    18.  
    19.  
    20.  
    21. void VoltSel_Init()
    22. {
    23.  
    24.     ANSELH=0;
    25.     TRISBbits.TRISB4 = 0;        //Setup for output
    26.     TRISBbits.TRISB5 = 0;        //Setup for output
    27.     TRISBbits.TRISB6 = 1;        //Setup for input (button)
    28.  
    29.     INTCON2bits.RABPU = 0;        // enable PORTB internal pullups
    30.     WPUBbits.WPUB6 = 1;            // enable pull up on RB6
    31.     IOCBbits.IOCB6 = 1;
    32.  
    33.      // Set up switch interrupt on INT0
    34.     INTCON2bits.INTEDG0 = 0;    // interrupt on falling edge of INT0 (switch pressed)
    35.     INTCONbits.INT0IF = 0;      // ensure flag is cleared
    36.     INTCONbits.INT0IE = 1;      // enable INT0 interrupt
    37.       INTCONbits.GIEL = 1;        // Low priority interrupts allowed
    38.     INTCONbits.GIEH = 1;        // Interrupting enabled.
    39.  
    40.     // NOTE: INT0 is ALWAYS a high priority interrupt
    41.  
    42.     // Set up global interrupts
    43.     RCONbits.IPEN = 1;          // Enable priority levels on interrupts
    44.  
    }
     
Loading...