Question: A clever student hatched a plan to debounce a switch connected to INT2 (assume PPS was done correctly and the INT2 interrupt was left at

A clever student hatched a plan to debounce a switch connected to INT2 (assume PPS was done correctly and the INT2 interrupt was left at the default priority, 4). There was available a delay function, which would delay by its parameter in microseconds (here's its declaration): void delay( unsigned int musecs); Assume it works properly. So the student wrote this ISR: volatile unsigned short int buttonPresses = 0; void __attribute__((__interrupt__,__auto_psv__)) _INT2Interrupt(void) { IFS1bits.INT2IF = 0; SRbits.IPL = 1; // re-enable interrupts delay(40000); buttonPresses++; } (a) What could possibly go wrong? For some reason, that didn't quite work right, so the student scratched his (or her) head for a while, then made a little change: volatile unsigned short int buttonPresses = 0; void __attribute__((__interrupt__,__auto_psv__)) _INT2Interrupt(void) { SRbits.IPL = 1; // re-enable interrupts delay(40000); IFS1bits.INT2IF = 0; buttonPresses++; } (b) What could possibly go wrong? (c) How would you solve this problem using INT2 to detect switch closures? (Hint: you might want to use another device to help.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!