IŞIK UNIVERSITY
EE342-MICROPROCESSORS
EXPERIMENT #7
INTERRUPTS
Objective
The goal of this experiment is to learn writing interrupt service routines. Read Section 6.9, 6.10 and 6.11 of Miller.
Introduction
Interrupt is an event that requires the CPU to stop normal program execution and perform some service related to the unusual event. Examples of interrupts include I/O completion, timer time out, illegal opcodes, arithmetic overflow, dividing by 0, etc.
The CPU provides service to an interrupt by executing a program called the interrupt service routine.
A complete interrupt service cycle includes
1. Saving the program counter value in the stack
2. Saving the CPU status (including the CPU status register and some other registers) in the stack
3. Identifying the cause of interrupt
4. Resolving the starting address of the corresponding interrupt service routine
5. Executing the interrupt service routine
6. Restoring the CPU status and the program counter from the stack
7. Restarting the interrupted program
Steps of Interrupt Programming
Step 1. Initializing the interrupt vector table
Step 2. Writing the interrupt service routine
Step 3. Enabling the interrupt
Example 7.1 Interrupt Driven Parallel I/O
The push-button A on EVB is wired to STRA pin of 68HC11. Pushing this button sends a rising edge to STRA. This event can set STAF bit of PIOC register and can cause an interrupt if the PIOC is configured properly.
In this example, main program turns all leds off, configures the PIOC register, clears the interrupt mask and waits for an interrupt. If push-button A is pushed the 68HC11 receives an interrupt request via the STRA pin. This interrupt request is accepted, because the mask was cleared, and the interrupt service routine ISR is executed. In ISR the STAF flag is cleared and only the first led is turned on. At the end, the RTI instruction returns program control to the main program.
********************************************************
* Parallel I/O Read push-buttons, turn leds off or on
********************************************************
* Addresses of I/O Registers
BASE EQU $1000
PIOC EQU $02
PORTB EQU $04
PORTCL EQU $05
** Start address of ISR for interrupts from IRQ
ORG $00EE
JMP ISR
***** Program Section *******
* --- Main Program ---
ORG $C000 Start of program
LDS #$CFFFIntialize the SP
LDX #BASE
BCLR PORTB,X %01110000
* Initialize for simple strobe mode and
* rising edge on EGA, enable STRA interrupt
BSET PIOC,X %01000010
CLIEnable interrupts
WAIwait for interrupt
SWI
* --- Interrupt Service Routine ---
ISR LDAAPIOC,XRead PIOC and
LDAAPORTCL,XPORTCL to clear STAF
ONE BCLR PORTB,X %01110000 turn all leds off
BSET PORTB,X %00010000turn only first led on
RTIreturn from isr
Exercise 7.1: Running the Program in Example 7.1
Assemble the program given in Example 7.1, load the executable file into EVB, and run it.