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

12f683 write to eeprom help

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



Joined: 10 Feb 2019
Posts: 26

View user's profile Send private message

12f683 write to eeprom help
PostPosted: Thu Feb 28, 2019 10:37 am     Reply with quote

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: 478
Location: Montenegro

View user's profile Send private message

PostPosted: Thu Feb 28, 2019 12:29 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 5:48 pm     Reply with quote

I have tried a few examples from other posts but I can't figure it out.
temtronic



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

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 7:04 pm     Reply with quote

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... Laughing )

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 8:22 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 8:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 01, 2019 9:27 pm     Reply with quote

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