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

saving variables to program memory?

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



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

saving variables to program memory?
PostPosted: Sat Dec 01, 2012 10:49 am     Reply with quote

Hi, I designed an USB target board using PIC18F47J53.

I just realized that this device doesn't have internal eeprom.

But it does allow program memories to be written.

Is there ways I can save my 32 byte array into program memory? and take

it back when the device powers on after powering off?

I think there has to be ways to reserve some program memory so that the compiler does not write program to those address, otherwise, the program will be corrupt every time I use it as data storage.

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 01, 2012 11:52 am     Reply with quote

Quote:
I just realized that this device doesn't have internal eeprom.
Is there ways I can save my 32 byte array into program memory?

There are several threads on this:

How to use program memory as data memory in pic16f877a
http://www.ccsinfo.com/forum/viewtopic.php?t=48981
In the thread above, read Ttelmah's comments on problems with using
Flash as a substitute for data eeprom.

18F87J11 Family Flash Read/Write/Erase
http://www.ccsinfo.com/forum/viewtopic.php?t=38279

Confuse with program memory and eeprom
http://www.ccsinfo.com/forum/viewtopic.php?t=38459
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Sat Dec 01, 2012 1:48 pm     Reply with quote

The really big problem with your chip, is that the erase page is 1024bytes.
So, you'd need to reserve a block this large - I'd suggest at 0x1F800 to 1FBFF. The reason for this is that you don't want to erase the config fuses at the top of memory, and this is then the highest 'page' below this.
#ROM automatically reserves the memory.
Then you'll just need to read_program_memory, using this address and your RAM structure, and do a write_program_memory to put it back. However you really want to avoid writing more than you have to (life), and the erase takes 33mSec, with the processor _stopped_ during this time.
Writes can be done a word at a time using write_program_eeprom. This won't erase memory though. write_program_memory, will automatically erase the page if it writes to the bottom address of the page. A write can only change bits from 1 to 0. To change a bit from 0 to 1, requires an erase.
If you can make the changes really infrequent, then the simplest coding, is to just write the block at the start of the page. with an automatic erase. If not, Microchip has a large application note about how to simulate the EEPROM, using a word for each byte, with multiple blocks used, which uses the second byte in each word as an address marker, and erases as infrequently as possible to reduce the life problem.

Best Wishes
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