Introduction to Microcontrollers Lab Manual - Microchip
Introduction to Microcontrollers Lab Manual - Microchip
Introduction to Microcontrollers Lab Manual - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
2.1 INTERRUPTS<br />
2.2 PRE-LAB<br />
2.1.1 Objective<br />
<strong>Lab</strong> 2. Interrupts<br />
LABS<br />
This lab covers the following concepts:<br />
• Using interrupts on the PIC24F<br />
• Using the MPLAB IDE Watch window <strong>to</strong> inspect real-time register values during<br />
programming debugging<br />
2.2.1 Reference Material<br />
• PIC24FJ256GB110 Family Data Sheet (DS39897)<br />
• 16-Bit MCU and DSC Programmer’s Reference <strong>Manual</strong> (DS70157)<br />
• MPLAB IDE User’s Guide (DS51519)<br />
• PIC24F Family Reference <strong>Manual</strong> – Section 8. Interrupts (DS39707)<br />
• PIC24F Family Reference <strong>Manual</strong> – Section 14. Timers (DS39704)<br />
2.2.2 Interrupts<br />
An interrupt (also called an exception) is an asynchronous signal or a synchronous<br />
software event intended <strong>to</strong> inform the processor that there is a need for a change in<br />
execution.<br />
Interrupts were introduced <strong>to</strong> avoid wasting the processor’s time in a polling loop. This<br />
method means the processor is fully executing while waiting for an external event, often<br />
without the ability <strong>to</strong> handle other system events.<br />
When an interrupt occurs, it causes the processor <strong>to</strong> save its current state on the software<br />
stack and then execute a special subroutine. The Interrupt Vec<strong>to</strong>r Table is a list<br />
of the addresses <strong>to</strong> these special routines. The PIC24F allows for the possibility of a<br />
unique subroutine for each interrupt source.<br />
The special subroutines are known as Interrupt Service Routines (ISRs). It is good<br />
design practice for an ISR <strong>to</strong> execute as quickly as possible, so the processor should<br />
spend as little time in the ISR as possible. This becomes an issue when you have multiple,<br />
real-time, nested interrupts. In all cases, loops and polling should be avoided in<br />
any ISR.<br />
The main difference between an ISR and a normal subroutine is that before executing<br />
an ISR, the processor saves its current state so that when the ISR is complete, the processor<br />
state can be exactly reproduced and program flow will continue as if the interrupt<br />
did not occur (with the exception of any changes caused by the ISR itself). As a<br />
result, the last instruction of an ISR must be a RETFIE instruction. This res<strong>to</strong>res the<br />
processor state.<br />
2011 <strong>Microchip</strong> Technology Inc. DS51963A-page 19