View previous topic :: View next topic |
Author |
Message |
dwburlington Guest
|
Preserving a variable during reset |
Posted: Fri Feb 08, 2008 10:27 am |
|
|
is there a way to tell the compiler not to initialize a variable to 0 during a reset.??
Thanks |
|
|
Ttelmah Guest
|
|
Posted: Fri Feb 08, 2008 10:38 am |
|
|
Anything that is not static/global, and is not assigned a value, is not by default initialised. So a simple variable declared inside the main as:
int8 fred;
Will retain the value it last had (but will also contain garbage on the first boot).
Remember though that variables in _subroutines_, can have the memory storage area re-used, so it has to be declared in main.
You can also use #locate, to put a variable into an area of memory, that _you_initialise on the first 'real' boot, but leave unchanged on resets.
Best Wishes |
|
|
dwburlington Guest
|
|
Posted: Fri Feb 08, 2008 10:45 am |
|
|
perfect that will work.
Thanks |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Feb 08, 2008 11:43 am |
|
|
Naturally the situation changes if you are using a bootloader as the bootloader has no visibility in the the memory space used by the application. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|