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 support@ccsinfo.com

How to save variable value permanently in PIC16f877a?

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



Joined: 19 Jul 2019
Posts: 1
Location: Pakistan

View user's profile Send private message

How to save variable value permanently in PIC16f877a?
PostPosted: Fri Jul 19, 2019 6:03 am     Reply with quote

How to save a variable value permanently in PIC16f877a ? If I restart the controller, the value should remain intact, which i have entered first time. I am using CCS.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 19, 2019 7:47 am     Reply with quote

Consult the CCS compiler manual, locate 'eeprom' functions.
You use them to write and read data stored in EEPROM.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Jul 19, 2019 8:09 am     Reply with quote

But, also remember that you must only write this infrequently.
So you don't want (for example) to be using this for something you change
repeatedly. Once an hour, OK. Once a day, OK. But change the value
once a second. No.
Every time you update a value in EEPROM it uses a 'life' for this.
The EEPROM has a limited life. In your case warranted 100K cycles.
So change it once per second, and the life can be used in just 1.15 days...
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Jul 19, 2019 12:59 pm     Reply with quote

As a further comment (Don't know why this was moved to the code library?).

Look at the include file <internal_eeprom.c>

This contains routines to save and load different types of variable to
the internal EEPROM.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jul 19, 2019 1:47 pm     Reply with quote

Also, forgot to add... read the DATASHEET !! As 'T' points out, EEPROM has limited lifespan. There are of course several 'tricks' to extend data life when using EEPROM.
Usually you don't just have the micro, so IF you have an RTC, use the battery backed RTC RAM to store data. It's 'free' with much longer lifespan than EEPROM.
Jay
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