|
|
View previous topic :: View next topic |
Author |
Message |
hello188
Joined: 02 Jun 2010 Posts: 74
|
saving variables to program memory? |
Posted: Sat Dec 01, 2012 10:49 am |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Sat Dec 01, 2012 1:48 pm |
|
|
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 |
|
|
|
|
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
|