Interrupts
All the input we've done so far has been based on polling. We
continually check the status of the input device, and respond to it.
The next basic form of input handling is called interrupts.
Think about what happens when you press the reset button: the
processor stops whatever it was doing, picks up a new PC from a known
address, and continues. This is the basic idea of interrupt handling:
the processor is ``interrupted'' by the input.
The reset button is a special case, of course, in that when you press
reset, you aren't interested in whatever was happening beforehand.
Most of the time, an interrupt tells us that something has happened
that we are interested in, so we have to go process it and then return
to work. One of the best examples of this is the IRQ input.
- All of the registers get pushed, including the PC and CC registers.
- A new PC is loaded from
fff2
-fff3
.
- This sends the machine to go off and execute whatever software
we've written to deal with the situation. This code is called an
interrupt handler.
- At the end of the interrupt handler, we return with an RTI
instruction. This restores all of the processor registers.
You can think of an interrupt as being a lot like a procedure, but
requested by the outside world instead of by your program. The
critical differences are (1) there are no parameters and (2) when it
happens is not synchronized with your program. It can happen any
time.
We have a number of ways to control interrupts. First, we have the
capability of enabling or disabling them globally with the I and X
bits in the CCR, and by local interrupt disable bits in the on-chip
devices themselves.
Available Interrupts
See manuals, like page 3 of the HC11 Programming Reference Guide (our
HC11 bible).
Enable Interrupts
cli
enables interrupts.
Example
Here's an example, that uses the IRQ interrupt:
irq.asm