Rb4: rb7 on change interrupt

pic

I am using a pic 6f628a and I want to use "on change" interrupt on pins RB4:RB7
I also want to use two different interrupts on pins RB4 & RB5 so when either of the pins have a valid change the flag will be set >>> my problem is how to differentiate between the two interrupts coming from RB4 and RB5. I Want to check the flag of RB4 or RB5 but i don't know how to write this line of the code.

Best Answer

You would check the state of the PORTB pins you are interested. You can also store their status on a global variable for comparison on the next time around, this would allow you to determine which pins have changed. Here is a sample of what your CN ISR might look like:

void __attribute__((interrupt,auto_psv)) _CNInterrupt(void)
{
    unsigned char ChangeVector;

    IFS1bits.CNIF = 0;  //clear interrupt flag

    ChangeVector = (PORTB&0xf0)^LastPortB;  //bit vector of changed pins of interest
    LastPortB = PORTB&0xf0; //store value of PORTB pins of interest for the next ISR

    if (ChangeVector&0x10)  // routine for RB4
    {<do stuff here>}
    if (ChangeVector&0x20)  // routine for RB5
    {<do stuff here>}
    <...repeat for other pins>
}