CS 273: IRQ Interrupts

The simplest interrupt-driven device on the miniboard is the button labelled IRQ: when the button is pressed, it requests an IRQ interrupt.

Enabling IRQ Interrupts

The IRQ interrupt has no local enable bit. Consequently, all you have to do to enable IRQ interrupts is to use a CLI instruction to enable interrups for the processor.

However, there is one bit (literally) of initialization that's a good idea: IRQ can be either an "edge-triggered" or a "level-triggered" interrupt. The difference here is whether it will request a single interrupt when you first press the button, or if it will keep requesting them for as long as you hold the button down. Since the HC11 is so much faster than we are, if we were to use level-triggered interrupts, we'd get a flurry of interrupts whenever we pressed the button — there's no way we could push the button and release before the interrupt service routine was done. So we'll want to set it to "edge-triggered" using a bit in the OPTION register:

ADPU CSEL IRQE DLY CME   CR1 CR0

Yes, this is the same OPTION register we use to turn on the A/D subsystem; we'll want to set both the ADPU (if needed) and the IRQE bits in the same instruction.

IRQ Interrupt Handler

There are two things you need to do in any interrupt service routine: you need to set up the interrupt vector, and you need to return from the interrupt.

Interrupt Vector

The IRQ interrupt vector is located at $fff2. This means that you need to put the address of your interrupt service routine in this address. Here's an example: suppose your interrupt service routine starts at a label irqint, like this:

*irq interrupt service routine
irqint

Then, after your program code and before your end statement, you need to put

        org $fff2
        fdb irqint

IRQ interrupt service routine requirements

The only absolute requirement is that you need to end the interrupt service routine with an RTI instruction.

Example

Here's an example, that uses the IRQ interrupt. All it does is complement the state of the motor outputs on every IRQ; so it turns them from all off to all red, then back to all off, and so forth. One thing to notice when you try this is that every so often the IRQ button will "bounce" and you'll get two IRQ interrupts. The symptom of this is that you may or may not notice the LEDs flash, but they won't change state. This is something I'll bet you've seen many times in commercial products; in my experience timers and clocks on coffee pots seem to be the worst about having un-debounced inputs that end up skipping when you press the "set" buttons.

irq.asm


Last modified: Wed Nov 11 09:45:53 MST 2009

Valid HTML 4.01 Transitional