Academic Program

Servicing an Interrupt

Servicing an Interrupt

Interrupt Service Routine (ISR)

The ISR is a user-written program which performs the necessary tasks when an interrupt occurs. The user is responsible for writing the ISR and locating it at address 04h. The last instruction executed by the ISR must be the RETFIE instruction. ISRs can be written in either C or assembly language.

ISR in Assembly (left) and ISR in C (right)

isr-location.png

 

Context Saving

The MCU's hardware will invoke the context saving mechanism when an interrupt occurs.

context-saving.png

 

Verify Source of the Interrupt

There is one ISR which services all the interrupts for the application. The ISR needs to sequentially check the individual interrupt request flags to determine the source of the interrupt.

Clearing the Interrupt Request Flag

The Interrupt Request flags are latched when set by the peripheral. They must be cleared by ISR. Failure of the ISR to reset a request flag will cause another interrupt to occur immediately after the ISR returns control to the main program.

sample-isr.png