Page 299 - Programming Microcontrollers in C
P. 299
284 Chapter 5 Programming Large 8-Bit Systems
measured_period=0;
for(j=0;j<COUNT_8;j++)
measured_period += mparray[j];
measured_period >>= DIVIDE_8_SHIFT;
}
time1=time2;
TOC2=time2+5*measured_period/8; /*debounce time
Is 5/8 revolution */
TMSK1.IC1I=OFF; /* disable IC1 interrupt */
TMSK1.OC2I=ON; /* enable OC2 interrupt */
}
@port void OC2_Isr(void) /* the debounce isr */
{
TFLG1=IC1F|OC2F; /* reset interrupt flags */
TMSK1.OC2I=OFF; /* disable OC2 interrupt */
TMSK1.IC1I=ON; /* enable IC1 interrupt */
}
@port void OC3_Isr( void) /* the PWM isr */
{
TFLG1=OC1F; /* reset OC1 interrupt flag */
TOC1+=PWM_period;
OC1D.OC1D7 ^=ON;
TFLG1=OC3F; /* reset OC3 interrupt flag */
TOC3=TOC1+PWM_count;
if(++count>=COUNT_ONE_QUARTER)
{
count=0; /*enter speed control about */
tick=TRUE; /*each quarter of a second */
}
if(++count1==COUNT_ONE_SECOND)
{
count1=0;
tick1=TRUE;
}
}
Listing 5-8: The Completed Application