Download CodeVisionAVR User Manual

Transcript
CodeVisionAVR
The automatic saving and restoring of registers R0, R1, R22, R23, R24, R25, R26, R27, R28, R29,
R30, R31 and SREG, during interrupts can be turned on or off using the #pragma savereg directive.
Example:
/* Turn registers saving off */
#pragma savereg/* interrupt handler */
interrupt [1] void my_irq(void) {
/* now save only the registers that are
affected by the routines in the handler,
for example R30, R31 and SREG */
#asm
push r30
push r31
in
r30,SREG
push r30
#endasm
/* place the C code here */
/* .... */
/* now restore SREG, R31 and R30 */
#asm
pop r30
out SREG,r30
pop r31
pop r30
#endasm
}
/* re-enable register saving for the other interrupts */
#pragma savereg+
The default state is automatic saving of registers during interrupts.
The automatic allocation of global variables to registers can be turned on or off using the #pragma
regalloc directive.
The default state is determined by the Project|Configure|C Compiler|Compilation|Automatic
Register Allocation check box.
Example:
/* the following global variable will be automatically
allocated to a register */
#pragma regalloc+
unsigned char alfa;
/* the following global variable will not be automatically
allocated to a register and will be placed in normal SRAM */
#pragma regallocunsigned char beta;
© 1998-2001 HP InfoTech S.R.L.
Page 56