Q12. An essential part of a microcontroller system is the interrupt mechanism.
a) Draw the diagrams of the instruction execution cycle of a PIC microcontroller both with and without interrupt mechanisms to compare and explain why the interrupt procedure can be run immediately.
b) List at least 4 interrupt resources available for PIC16F877A microcontroller. How can recursive multiple interrupts be avoided?
c) What is context saving that allows an interrupt procedure to return to the right place?
d) In a PIC16F877A-based embedded system using interrupts, the main function is the following C code:
int count; // global variable
void main (void) {
set.bit(intcon, GIE); // line 1
set.bit(intcon, TMROIE); // line 2
count = 1000;
while(count != 0) { // do until delay = 0
do_something_else(); // other functions
}
}
Give comments on line 1 and line 2 in the code and write the interrupt subroutine in C to decrease the value of count by one every time the interrupt happens.
void interrupt(void) {
count--;
}
Assume the interrupt happens every 256 us, how long will the "do_something_else" subroutine be run in the main code?