static unsigned char n = 0;
static unsigned int Qarray [] = { 1500, 1500, 1500, 1500,
1500, 1500, 1500, 1500, 20000 };
static unsigned char Servo = 1; // Port B shadow register
/*****************************************************************
* K8LH Crazy-8 'Soft' 8-channel (Port B) Servo Algorithm *
* */
void isr_hi ()
{ if (PIR1bits.CCP1IF == 1) // if CCP "compare" interrupt
{
LATB = Servo; // output new Servo pulse
CCPR1H += (Qarray[n]/256); // update "match" period value
CCPR1L += (Qarray[n]%256); // for this Servo pulse
PIR1bits.CCP1IF = 0; // clear CCP1 interrupt flag
Qarray[8] -= Qarray[n]; // adjust end-of-period time
Servo <<= 1; // prep for next channel
n++; // increment array index
if (n = 9) // if end-of-cycle
{ n = 0; // reset array index
Qarray[8] = 20000; // reset the 20.0-msec period
Servo = 1; // reset the Servo to Servo 1
}
}
}