Provide code that implements an interrupt service routine every 20 milliseconds
ID: 3661397 • Letter: P
Question
Provide code that implements an interrupt service routine every 20 milliseconds using timer 1. You may assume that the microcontroller is using a 40MHz SYS_FREQ and that PB_DIV=2. Provide comments to explain what each line does. Your ISR need only clear the interrupt flag and set a variable called tick_flag that has already been declared and initialised to zero. Provide code that initialises the timer and interrupt systems. The ISR has a function prototype of type:
void __ISR(_TIMER_1_VECTOR, ipl2) yourhandler(void);
should be used to contain the code for your interrupt service routine.
Provide code for an interrupt service routine and an initialisation routine that allows use of timer2 and timer 3 to provide a 5 second interrupt.
Explanation / Answer
void __ISR(_TIMER_1_VECTOR, ipl2) _Timer1Handler(void)
{
LATDINV = 0x0001;
mT1ClearIntFlag(); // clear the interrupt flag
}
void __ISR(_TIMER_2_IRQ, IPL3) Timer2Handler(void) // Function d'interruption Timer 2
{
LATD= 0x0002;
IFS0CLR = 0x00000100; // Clear timer interrupt status flag
T3CONSET = 0x8000;
}
void __ISR(_TIMER_3_VECTOR, IPL3) Timer3Handler(void) // Function interrupt Timer 3
{
LATD= 0x0001;
IFS0CLR = 0x00001000; // Be sure to clear the Timer 2 interrupt status
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.