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 CCS Technical Support

PIC16F914 EEPROM Usage

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



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PIC16F914 EEPROM Usage
PostPosted: Tue Feb 18, 2014 2:30 pm     Reply with quote

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: 19540

View user's profile Send private message

PostPosted: Tue Feb 18, 2014 3:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 18, 2014 4:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 18, 2014 4:15 pm     Reply with quote

Also it will only be written too a maximum of 10 times a day.
This should last well beyond my retirement Laughing
edbfmi1



Joined: 18 Jul 2006
Posts: 103

View user's profile Send private message

PostPosted: Tue Feb 18, 2014 4:17 pm     Reply with quote

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: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 18, 2014 6:53 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 18, 2014 10:06 pm     Reply with quote

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