Lab 5 – Interrupts
Upgrade Your Interrupt Service Routine (ISR)
If you hadn’t already guess what the problem was, since the IFG bit never got cleared, the CPU
never realized that new interrupts were being applied.
For grouped interrupts, if we use the appropriate Interrupt Vector (IV) register, we can easily
decipher the highest priority interrupt of the group, as well as getting the CPU to clear the IFG bit.
30. Replace the code inside your ISR with the code that uses the P1IV register.
Once again, we have already created the code as part of the worksheet; refer to the
Worksheet, Step 14 (page 5-41).
To make life easier, here’s a copy of the original template from the worksheet. You may want
to cut/paste this code, then tweak it with answers from your worksheet.
//*********************************************************************
// Interrupt Service Routines
//*********************************************************************
#pragma vector=PORT1_VECTOR
__interrupt void pushbutton_ISR (void) {
switch(__even_in_range(
, 10 )) {
case 0x00: break; // None
case 0x02: break; // Pin 0
case 0x04: // Pin 1
??????????????????????;
break;
case 0x06: break; // Pin 2
case 0x08: break; // Pin 3
case 0x0A: break; // Pin 4
case 0x0C: break; // Pin 5
case 0x0E: break; // Pin 6
case 0x10: break; // Pin 7
default: _never_executed();
}
Hint: The syntax indentation often gets messed up when pasting code. If/when this occurs, the
CCS editor provides a prettying feature (<ctrl>-I).
Select the ‘ugly’ code and press c-I
31. Build the code.
If you correctly inserted the code and replaced all the questions marks, hopefully it built
correctly the first time.
32. Launch the debugger. Run. Push the button. Verify the light toggles.
Run the program. Push the button and verify that the interrupt is taken every time you push
the button. If the breakpoint in the ISR is still set, you should see the processor stop for each
button press (and you’ll need to click Resume).
You’re welcome to explore the code further by single-stepping thru code, using breakpoints,
syspending (halting) the processor and exploring the various registers.
5 - 50 MSP430 Workshop - Interrupts