The program achieves nothing inparticular. Pressing the RB0 button should simply clear the PORTA leds. There is also a routine flashing bit7 of PORTB - the aim of the excercise - identifying which interrupt was tripped.
#include<io16f84.h>
//#include <htc.h>
#pragma vector=0x04 //sets interrupt vector
__interrupt void my_ISR(void);
void main(void)
{
unsigned int i;
RP0=1;
TRISB=0x01; //portB output/input
TRISA=0x00; //porta output
OPTION=0x07;
RP0=0;
TMR0=0x00; //clear timer
PORTA=0x00;
PORTB=0x00;
INTCON=0xB0; //sets up interrupt options
while (1)
{
for (i=0;i<32000;i++);
PORTA=PORTA+1; //arbitrarily count up on PORTA
} //end of while(1)
} //end of void(main)void
//Interrupt service routine
//only runs when timer overflows/RB0 is pressed
__interrupt void my_ISR(void)
{
GIE=0; //disables interrupts for a bit
if(T0IE==1) //if timer causes interrupt
{
T0IF=0; //clear flag
PORTB=PORTB^0x80; //toggle bit7
TMR0=0x00; //ensure timer is cleared
}
if(INTF==1) //if RB0 caused interrupt
{
INTF=0; //clear flag
PORTA=0x00; //set PORTA at zero
}
else;
GIE=1; //re enables interrupts
} //end of void main(void)

