Introduction to Interrupts

Can implement a delay by waiting for the TOF flag to become set:

void delay(void)
    while ((TFLG2 & 0x80) == 0) ;
    TFLG2 = 0x80;

Can't do anything else while waiting. Wastes resources of HC12.

Use an interrupt to tell you when the timer overflow has occurred.

Allow the HC12 to do other things while waiting for an event to happen. When the event happens, tell HC12 to take care of event, then go back to what it was doing.

What happens when HC12 gets an interrupt:
HC12 automatically jumps to part of the program which tells it what to do when it receives the interrupt (Interrupt Service Routine).

How does HC12 know where the ISR is located:
A set of memory locations called Interrupt Vectors tell the HC12 the address of the ISR for each type of interrupt.

How does HC12 know where to return to:
Return address pushed onto stack before HC12 jumps to ISR.

What happens if ISR changes registers:
All registers are pushed onto stack before jumping to ISR, and pulled off the stack before returning to program.

Bill Rison