View previous topic :: View next topic |
Author |
Message |
Rez
Joined: 10 Feb 2019 Posts: 26
|
12f683 write to eeprom help |
Posted: Thu Feb 28, 2019 10:37 am |
|
|
I would like to be able to store in memory if an output is high or low. When I push a button I want it to store in memory if pin A5 output was high or low and when I shut off the device and turn it back on again it will output pin A5 either high or low depending on how it was set before turning the device off etc. |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
Posted: Thu Feb 28, 2019 12:29 pm |
|
|
Very easy. write_eeprom() when you detect the button and read_eeprom() when your device wakes up.
Of course you might very quickly kill internal eeprom with constant writing. Maybe you could attach a 50c DS1307 module that has a battery backed RAM and store the state of your pin there.
Regards |
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Fri Mar 01, 2019 5:48 pm |
|
|
I have tried a few examples from other posts but I can't figure it out. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Mar 01, 2019 7:04 pm |
|
|
Before you cut/compile/try code that writes/reads to the EEPROM use the logic to control an LED first ! You could actually 'use up' the life of the EEPROM if your code isn't 100% correct. LEDs live forever and are a GREAT visual indicator that 'yes it works' or 'no - try again'. You could actually have 2 LEDs. One, the 'control' LED indicates what status the 'EEPROM' LED should be... a visual truth table...
Also be sure to account for the programming delays when writing to EEPROM. They typically can be 10s of ms, depending on PIC and EEPROM. That information is in the 300-400 page datasheet (which we all read cover to cover... )
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 01, 2019 8:22 pm |
|
|
This program shows you how to save the status in eeprom and read it
when the PIC is powered-up:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17
One thing I would change in that program is this line:
Quote: | #ROM 0x2100 = {0x00} |
The more modern way to do it in CCS is:
Code: |
#rom int8 getenv("EEPROM_ADDRESS") = {0x00}
|
|
|
|
Rez
Joined: 10 Feb 2019 Posts: 26
|
|
Posted: Fri Mar 01, 2019 8:47 pm |
|
|
PCM programmer wrote: | This program shows you how to save the status in eeprom and read it
when the PIC is powered-up:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17
One thing I would change in that program is this line:
Quote: | #ROM 0x2100 = {0x00} |
The more modern way to do it in CCS is:
Code: |
#rom int8 getenv("EEPROM_ADDRESS") = {0x00}
|
|
Can you send that data to window of the ide instead of an led display? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 01, 2019 9:27 pm |
|
|
Yes.
1. Add this line after the #use delay() line:
Code: | #use rs232(debugger) |
2. Comment out the following lines:
Quote: | #include <lcd.c>
lcd_init();
lcd_gotoxy(1,1); // 2 places
printf(lcd_putc, "%u ", count); // 2 places
|
3. Substitute the following line (in 2 places) for the two printf statements:
Code: | printf("%u ", count); |
|
|
|
|