void interrupt( void ) {
static short new_value;
static short old_value;
/* Timer 1 will overflow at 65535 and if it does we have to take this into account in our math
freq is a global which can hold a long value so lets put the result there
*//
if (test_bit(pir1,CCP1IF)) { // 4. When a CCP interrupt occurs:
// test = 0x01;
// a) Subtract saved captured time (old_value) from captured time (new_value)
// if no rollover of timer 1 has occurred, then the difference is our time
MAKESHORT(new_value, ccpr1l, ccpr1h); // or ccpr1l and ccpr1h
// now record timer1 value
if (test_bit(pir1,TMR1IF)) {
// timer 1 had overflowed so we need to add 65535 to the old_value before we subtract
// the value of
freq = = old_value - new_value + 0xFF;
clear_bit(pir1, TMR1IF);
} // end if
// and store (use Timer1 interrupt flag as overflow indicator.)
else {
freq = old_value - new_value;
} // end else
// if (pir1.CCP1IF) { // must be cleared in software
clear_bit(pir1, CCP1IF); // clear capture flag
old_value = new_value;
} // end if
first_time = FALSE;
} // end interrupt