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 CCS Technical Support

Reading and writing data structures to flash

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







Reading and writing data structures to flash
PostPosted: Fri Jul 06, 2007 9:52 am     Reply with quote

I neet to be able to store some large data structures in Flash on a PIC 18F4680 so they are preserved when the power is off.

There are a few things I don't understand about this - I assume I use the write_program_memory() function - but how do I know where my code ends and where the empty memory begins.

The structs contain several arrays of SInt16's plus int8's and pointers of both types. Ideally I want an easy way to copy an entire structure to flash, and to read and write individual variables within the structure.

I'm assuming that working directly with the structures in flash will be slow so my code will start by copying all the flash data into RAM.

I'm also unsure of the best (i.e most efficient) way to convert the SInt16's to and from the int8 values that will be stored in flash - can I just use the make8() and make16() functions even though the documentation only refers to their use with unsigned values?

Although I'm reasonably profecient at C I'm not the best programmer so some simple and clear advice would be greatly appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 06, 2007 12:37 pm     Reply with quote

Quote:

There are a few things I don't understand about this - I assume I use the
write_program_memory() function - but how do I know where my code
ends and where the empty memory begins.

You need to tell the compiler to reserve a range of Flash memory
addresses for your use. Then the compiler won't use them for code.
You can do this by using the #org statement. See the Ex_logger.c file
for an example:
Quote:
c:\program files\picc\examples\Ex_Logger.c


Near the start of that file, there's a large number of #org statements
buried within #if and #elif statements. You don't have to worry about
that. That's only for the 16F-series PICs, which have ROM pages.
You're using an 18F, so this code is all you need to define the buffer:
Code:

#define BUFFER_SIZE   4096  // in bytes

#define PROGRAM_MEMORY_SIZE   getenv("PROGRAM_MEMORY")
#define BUFFER_END      PROGRAM_MEMORY_SIZE-1
#define BUFFER_START   (PROGRAM_MEMORY_SIZE-BUFFER_SIZE)

#org BUFFER_START, BUFFER_END {}
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