static void interrupt isr(void)
{
if (TMR0IF) // TMR0 is overflow
{
TMR0IF = 0; // clear flag bit
To +=0x100; // count number of
TMR0 overflow ( make it to 16bit TMR)
}
if(RBIF) // there is change bit
on RB4-RB7
{
RBIF = 0; //
____
if (RB4) // Rb4 is 1 mean is
rising form 0 __|
{
TMR0 = 0; // clear all counter
involved, start new count for period of RB4 high
To = 0;
}
//
___
else TH = TMR0 + To; // RB4 is 0 mean is falling form 1
|_____ // save TH, RB4 high period
}
if(RCIF)
{
RCIF = 0; // clear flag bit
if (RCREG == 'R') data[i=0]= RCREG; // check if start byte
'R' is met
else if (RCREG == 100) data[i=0]= RCREG; // check if start byte
'd'(decimal 100) is met
if ((data[0] == 'R'))data [i++] = RCREG; // save the data in data
array
if (i>4) i = 4;
// if the data array reached max, set the index to 4
}
}