We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I am using P89v51rd2.
I want to store only one variable in the code memory, so that it is stored permanently. (say a=9999; max)
I want to update this frequently in the program, and read when required.
can anyone provide me the code for the same ?
thank you...
because my 'frequently'= about 2000 per day.
and the data is 2 byte which is going to be updated.
how much flash do you have left? how many years must your device function
with a 'walking write', you can get about a million writes (500 days) per 256 bytes of flash.
does your device give a 'power down interrupt?
Note that if counting every item to flash, then it isn't needed to store two bytes, i.e. 1878, 1879, 1880, 1881, ...
Each save would basically just be a +1, +1, +1, +1 in relation to a base counter value.
So a flash sector could contain: 1878, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4... and unused bytes remains at 0xff. This means a 128 byte sector can spend maybe 4 bytes for initial value and inverse of initial value and then have room for 128-4 counts.
If the flash supports multiple writes of the single byte, then a 128-byte sector could fit 1000+ counts for a single erase cycle.
Then there exists processors that computes a CRC with every sector, setting the limit at one single write to a sector before it needs to be erased.
But if the hardware can't handle a dropping supply voltage correctly, then the firmware needs to be able to detect scrambled data and be able to figure out with a reasonably high safety margin how far it had made it before a flash write goofed and scrambled data. And that requires that there are some form of redundancy in the storage in the form of check bits or similar.
Checkpointed write transactions to non-volatile memory are used on some systems that lack adequate power-fail notification. A "record" is either written in its entirety before power fails or a partial write is "rolled back" during power-up recovery.
Some keywords to Google.