SW006010 Microchip Technology, SW006010 Datasheet - Page 76

no-image

SW006010

Manufacturer Part Number
SW006010
Description
MPLAB 17C SOFTWARE
Manufacturer
Microchip Technology
Datasheets

Specifications of SW006010

Tool Function
Compiler
Tool Type
Compiler
Processor Series
PIC17C
Lead Free Status / RoHS Status
Not applicable / Not applicable
For Use With/related Products
MPLAB®
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
MPLAB
9.3
apRNOVM^-page 70
WRITING AN INTERRUPT SERVICE ROUTINE
C17 C Compiler User’s Guide
Following the guidelines in this section, you can write all of your application code,
including your interrupt service routines (ISR’s), using only C language constructs.
9.3.1
The guidelines for writing ISR’s are:
• Declare ISR’s with no parameters and a void return type
• Do not let ISR’s call other functions
• Do not let ISR’s be called by main line code
An MPLAB C17 ISR is like any other C function in that it can have local variables and
access global variables. However, an ISR needs to be declared with no parameters
and no return value. This is necessary because the ISR, in response to a hardware
interrupt, is invoked asynchronously to the mainline C program. (i.e., it is not called in
the normal way, so parameters and return values don’t apply).
ISR’s should only be invoked through a hardware interrupt and not from other C
functions. There are two reasons for this. First, an interrupt service routine uses the
return from interrupt (RETFIE) instruction to exit from the function rather than the
normal RETURN instruction. Using a RETFIE instruction out of context can corrupt
processor resources, such as WREG. Second, ISR’s use a temporary data area that is
distinct from that used by normal C functions. If an ISR were called by an ordinary
function during the occurrence of an interrupt, then the temporary data area may
become corrupted. For a similar reason, a MPLAB C17 ISR should not call any other
functions; otherwise the temporary data area used by ordinary functions may become
corrupted.
9.3.2
Use the
MPLAB C17
#pragma interrupt
The function-name parameter of the pragma names the C function serving as an ISR.
The optional section-name parameter names the section which allocates the
temporary data of the ISR. Any temporary data required during the evaluation of
expressions in the function is allocated in a private memory section and is not overlaid
with the temporary locations of any other functions, including other interrupt functions.
The default temporary data settings for section-name is as follows:
9.3.3
Place the
code the function prototype immediately after the pragma.
isr_tmp
interrupt
interrupt
Guidelines for Writing ISR’s
Syntax for Writing ISR’s
Coding ISR’s
(single interrupt priority level)
interrupt
pragma to declare C functions as ISR’s. The syntax for the
function-name [section-name]
pragma before the C function that is serving as the ISR. Then,
pragma is as follows.
 2002 Microchip Technology Inc.

Related parts for SW006010