CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Preserving a variable during reset

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dwburlington
Guest







Preserving a variable during reset
PostPosted: Fri Feb 08, 2008 10:27 am     Reply with quote

is there a way to tell the compiler not to initialize a variable to 0 during a reset.??

Thanks
Ttelmah
Guest







PostPosted: Fri Feb 08, 2008 10:38 am     Reply with quote

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







PostPosted: Fri Feb 08, 2008 10:45 am     Reply with quote

perfect that will work.

Thanks
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 08, 2008 11:43 am     Reply with quote

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!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group