Sonsivri

Electronics => Pic C Languages => Topic started by: modafox on September 19, 2008, 07:45:32 07:45



Title: How can I save some variable to Program Memory?
Post by: modafox on September 19, 2008, 07:45:32 07:45
I'm using PIC24FJ48 with MPLAB C30.
I want to save the data to flash (Program Memory section) and read it back when new power up.

Does anyone know how to do this?

Thanks.


Title: Re: How can I save some variable to Program Memory?
Post by: maddoc on September 19, 2008, 08:26:51 08:26
It is not advisable to do that, if you expect frequent power cycling then it is better to add an eeprom to the design.
The flash wears out quick and those variables won't get stored anymore.


Title: Re: How can I save some variable to Program Memory?
Post by: BharatSujanani on June 27, 2009, 12:39:19 12:39
I have done this thing in 18f452.
You can save data to flash by declaring variables as a const rom variables.
As a ex.
const rom unsigned char temp=25;
And you can read it by function
void *memcpypgm2ram (auto void *s1, auto const MEM_MODEL rom void *s2, auto sizeram_t n);
Information about this function is available in string.h file of your compiler.


Title: Re: How can I save some variable to Program Memory?
Post by: TomJackson69 on June 28, 2009, 12:05:00 00:05
modafox ,

If you only read the data then storing in the program memory is ok, but to write and rewrite for later use is not a good pratice because, the flash memory is only cappable for write so many cycles. Use EEPROM is better but still depends on how often you write to the EEprom.

Tom


Title: Re: How can I save some variable to Program Memory?
Post by: ALLPIC on June 28, 2009, 11:40:48 11:40
I used such think previously and working no problem, as every one telling you flash write is not good but if you keep track on 1000 write cycle then that work properly

please find attachment this code I found from Microchip web site and seams working good from last 1 year  ;)

i think this will help you  :)

regards