SW006010 Microchip Technology, SW006010 Datasheet - Page 62

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
apRNOVM^-page 56
C17 C Compiler User’s Guide
In this simple program the PICmicro MCU wasn't doing much at the time the interrupt
occurred. Therefore do not save any more registers in addition to what the compiler
interrupt code saved. However, in a more complex application, the interrupt may occur
at any point in the program. Therefore other registers may need to be saved. The best
way to find out is to look at the generated code for the interrupt handling function. Find
out which registers are used by the compiler inside the function and make sure to
save them at the beginning and restore them at the end of the function. Looking at the
following example's generated code, determine that registers PRODL and PRODH
are used both inside and outside the interrupt function.
#include <p17c44.h>
#pragma udata intSave = 0xFa
#pragma udata anywhere
void _ _TMR0()
{
_asm
_endasm
_asm
_endasm
}
void main()
{
// Set prescale value for TMR0
// Unmask TMR0 overflow interrupt
// Enable all unmasked interrupts
// Set Port B in o/p mode
}
The registers PRODH and PRODL are saved in
respectively. These variables are declared globally and allocated at locations 0xFa to
0xFB in bank 0 using the
bank just before
the interrupt support code, don't do any bank switching to save those three registers.
However, clear the BSR (using
function code could have switched banks.
unsigned char save_PRODL;
unsigned char save_1F;
unsigned char save_1E;
unsigned char x, y;
movpf PRODL, save_PRODL
movpf PRODH, save_1E
movpf PRODL, save_1F
x++;
PORTB = x;
y = y * x;
movlr 0
movfp save_PRODL, PRODL
movfp save_1E, PRODH
movfp save_1F, PRODL
x = y = 1;
Install_TMR0(_ _TMR0);
T0STA = 0b11100110;
INTSTA = 0b00000010;
CPUSTA = 0;
TRISB = 0;
while(1)
{
}
x = x * 5;
save_B
and guarantees they are in bank 0. Since BSR is cleared in
#pragma udata
MOVLR 00
// Switch to bank 0
// 0xF9
// 0xFA
// 0xFB
) before restoring them as the interrupt
directive. This places them at the end of the
save_1F
,
save_1E
 2002 Microchip Technology Inc.
and
save_PRODL
,

Related parts for SW006010