C51: INTERRUPTS AND LOCAL VARIABLES
Information in this article applies to:
I don't want an ISR to destroy the contents of variables in the main program that it is interrupting. Can I declare variables inside an interrupt routine or do all the variables that the ISR uses have to be global variables (declared outside the routine)?
Also, what about subroutines that the ISR calls? Can they have their own local variables? (assuming the subroutines use the same register bank, of course).
Interrupts may have local variables just like normal functions. Higher levels of optimization in the compiler will move variables automatically into the registers, thus saving them when an interrupt triggers.
Use the following techniques to prevent "corruption" of your DATA space by interrupts.
The following Discussion Forum threads may provide information related to this topic.
Last Reviewed: Tuesday, October 24, 2006
of your data.