I'am trying to work with the external interrupt source and I wrote a small program to test the interrupt. When I start the program RB0 is set low, and RB1 is set high. If I set RB7 high, it must be generated an interrupt that reverses the logic state of RB0 and RB1. I don't know why the interrupt doesn't work. I have configured all registers, is something missing yet? The compiler is xc16.
Thanks.
Here is the code:
#include <xc.h>
#include "setup.h"
void main(void) {
AD1PCFG = 0xFFFF;
TRISBbits.TRISB7=1;
TRISBbits.TRISB0=0;
TRISBbits.TRISB1=0;
PORTBbits.RB0=0;
PORTBbits.RB1=0;
_INT0IE= 1; //enable interrupt on RB7
_INT0IF = 0; //clear status flag interrupt on RB7
_INT0IP = 0b010; /priority level 2 for INT0
while(1) {
_RB0=0;
_RB1=1;
}
}
void _ISR _INT0Interrupt(void) {
if(_INT0IF) {
_INT0IF = 0;
_RB0=1;
_RB1=0;
}
}