View previous topic :: View next topic |
Author |
Message |
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
PIC16F914 EEPROM Usage |
Posted: Tue Feb 18, 2014 2:30 pm |
|
|
I need a little help figuring out what command to use to store a variable in the EEPROM on the PIC16F914.
I have a machine that can be running in one of 4 various modes. I need to store either a "0" , "1" , "2" or "3" in memory so that if power is interrupted I can read the memory location on power up to startup in the mode it was in when power was lost.
Would I simply do something like this to store mode "2" for instance.
Code: | write_eeprom(STORED_MODE,2); |
and then something like this when the program restarts to read the mode?
Code: | mode = read_eeprom(STORED_MODE); |
I tried this but it didn't seem to work right.
Thanks for the help! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19541
|
|
Posted: Tue Feb 18, 2014 3:11 pm |
|
|
So, start, what is 'STORED_MODE'?. Normally capitals are reserved for 'defines'. So, if a define, what is it defined as?. If it's a variable, what type is it (int etc.), and what does it contain?.
Then you refer to what you want to store in inverted commas. A string?.
Then remember that write_eeprom takes a long time (typically 5mSec), and can only be done a limited number of times (100K). If (for instance) this was done in a loop, you could kill the EEPROM in 500seconds.
Then what compiler version?. Some have faults. |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Tue Feb 18, 2014 4:10 pm |
|
|
Hi Ttelmah,
Thanks for the quick reply.
STORED_MODE is the location in the EEPROM I am using to store the variable.
In my case I used the following define:
Code: | #define STORED_MODE 10 |
I am using PCM Compiler V4.140
Thanks, |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Tue Feb 18, 2014 4:15 pm |
|
|
Also it will only be written too a maximum of 10 times a day.
This should last well beyond my retirement |
|
|
edbfmi1
Joined: 18 Jul 2006 Posts: 103
|
|
Posted: Tue Feb 18, 2014 4:17 pm |
|
|
One last thing.
I am simply storing a number. Either a 0 or a 1 or a 2 or a 3. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Tue Feb 18, 2014 6:53 pm |
|
|
hmm...it should have worked, but show us your code.Maybe between writing and reading something's gone 'funny'.
A printout of what should be stored and what is really there is necessary.
You can even just look at the eeprom from MPLAB.
hth
jay |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Feb 18, 2014 10:06 pm |
|
|
Unless you have power failure detection you would save the "mode" only on startup or runtime mode change...
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|