void interrupt(void) {
if(INTCON.INTF == 1)
{
PORTD = 0x01; //To see if interrupt is triggered
Delay_ms(2000);
INTCON.INTF = 0; //You HAVE to clear interrupt flag
}
}
void main()
{
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
OPTION_REG.INTEDG = 1; //Interrupt on rising edge
PORTA = 0x00; /*set RA0-RA5 low */
TRISA = 0x00; /*set PORTA to output*/
PORTA = 0; //Clear initial PORTA state
ADCON1 = 7; //Disable ADC so that PORTA can be used for digital purpose
//CMCON = 7; //Disable comparator --------> Only for 16F877A not 877
TRISD = 0x00; /*set PORTD to output*/
PORTD = 0; //Clear initial PORTD state
TRISB0_bit = 1; // set RB0 to input
do{ //Flash all LED's
PORTA = ~PORTA;
Delay_ms(100);
}while(1);
}