Datasheet

124
$ML1 BIT.B #01h,P0IN ; Test P0.0
JNZ $ML1 ; Do nothing if P0.0 low
1.2.13 How to Use an Interrupt Routine
Assemble and download the file gs_stk4.asm in the examples directory, as described previously.
1. When an interrupt occurs, the program sends the contents of the program counter and status
register to the stack.
2. Next, the program branches to the starting address of the interrupt routine.
3. The interrupt routine normally ends with the RETI instruction.
4. The RETI instruction loads the data, which was saved to the stack at the beginning of the interrupt
routine, to the status register and program counter.
5. The program continues from the point of interruption.
Using interrupt routines allows the MSP430 to use low power modes. Selecting a low power mode causes
the program to stop at the current position, and an activity that causes an interrupt automatically clears the
low power mode. The interrupt continues program execution at the starting address of the corresponding
interrupt routine. The RETI loads the saved program data to the status register and program counter.
Loading the status register and program counter clears out the low power mode bits, and the program
continues with the next instruction. Figure 120 is the Basic Timer Interrupt routine.
BIS #CPUOFF,SR ; set CPUoff Bit
;****************************************************************************
; Basic Timer Interrupt routine
;****************************************************************************
Int_BT ; Basic Timer 128 Hz (7.8 ms)
DEC.B lcd_timer ; decrement SW lcd-timer
JNZ Int_BT_end ; !0 : no action
BIC #CPUOFF,0(SP) ; Clear CPUoff Bit
MOV.B #lcd+ival,lcd_timer ; = 0 : load again
Int_BT_end
RETI
To use the interrupts, the interrupt vector table must be set up as follows:
;****************************************************************************
; Interrupt vectors
;****************************************************************************
.sect int_Vect, USER_END-31
.word RESET ; no source
.word Int_BT ; Basic Timer
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; no source
.word RESET ; NMI, Osc. fault
.word RESET ; POR, ext. Reset, Watchdog
.end
Figure 120. Basic Timer Interrupt Routine