View previous topic :: View next topic |
Author |
Message |
Zia ur Rehman
Joined: 19 Jul 2019 Posts: 1 Location: Pakistan
|
How to save variable value permanently in PIC16f877a? |
Posted: Fri Jul 19, 2019 6:03 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Fri Jul 19, 2019 7:47 am |
|
|
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: 19518
|
|
Posted: Fri Jul 19, 2019 8:09 am |
|
|
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: 19518
|
|
Posted: Fri Jul 19, 2019 12:59 pm |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Fri Jul 19, 2019 1:47 pm |
|
|
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 |
|
|
|