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

PIC 16F690 reading and writing to EEPROM

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



Joined: 23 Apr 2009
Posts: 4
Location: Montreal,QC,Canada

View user's profile Send private message MSN Messenger

PIC 16F690 reading and writing to EEPROM
PostPosted: Thu Apr 23, 2009 5:44 pm     Reply with quote

As a project I'm making a digital safe that prompts the user to enter a 6 digit password with the the use of an LCD, and numpad.

I added a feature that allows the user to create a new password, as long as he/she remembers the old one. The safe can now be only unlocked with the new password.

The only problem is that every time I power down and power back up, my PIC re-inializes my variables to the default password that I placed in the C+ code.

I would like to know if anyone knows how to write to the EEPROM of the PIC 16F690 so that after powering up again, it retains the new code.

Thanks. Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 23, 2009 5:51 pm     Reply with quote

See this thread about writing to eeprom in the 16F690:
http://www.ccsinfo.com/forum/viewtopic.php?t=32722

This post may also help:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17
cypherff



Joined: 23 Apr 2009
Posts: 4
Location: Montreal,QC,Canada

View user's profile Send private message MSN Messenger

EEPROM addresses for the 16F690
PostPosted: Sun Apr 26, 2009 2:45 pm     Reply with quote

Thanks for the example codes on how do read and wirte to the EEPROM.

I've read the datasheet of the 16f690 and if im not mistaken, each address can only hold a byte.

My "password" variable is an int32. I could use a function to break it down into 4 bytes then write to 4 different adresses.

In the example you sent me, the user was writing to address 10, I was wondering if you knew 3 more addresses I could write to.

I was also wondering what the line #rom 0x2100 = {0, 1, 2, 3, 4} meant

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 26, 2009 3:41 pm     Reply with quote

Use this FAQ article as a guide. To write to internal eeprom, just remove
the "ext" from all the function names in this example:
http://www.ccsinfo.com/faq.php?page=write_eeprom_not_byte

If you need detail instructions on how to convert that example to
work with 'int32' variables, read this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=38270&start=1


Quote:
I was also wondering what the line #rom 0x2100 = {0, 1, 2, 3, 4} meant

It inserts eeprom data into the HEX file at compile-time. The eeprom
will be programmed with those values when you program the PIC
(with your ICD-U40, or ICD2, or other programmer).

The address of 0x2100 is specific to the PIC 16-series devices.
cypherff



Joined: 23 Apr 2009
Posts: 4
Location: Montreal,QC,Canada

View user's profile Send private message MSN Messenger

Any address in mind?
PostPosted: Sun Apr 26, 2009 7:28 pm     Reply with quote

In the example you sent me it specified that "n is an offset into the eeprom" and that it was a long int. In guessing that it was some long address the user had given "n" at the start of the code that is missing from the example.

Your link also stated that if I wanted to add another in32, I would need to increment the chosen address by 4. I only have one int 32 to store in the eeprom, if you know of one such address it would be a great help.

You've already helped me a lot. I greatly appreciate it.

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 26, 2009 7:44 pm     Reply with quote

Quote:

I only have one int 32 to store in the eeprom, if you know of one such
address it would be a great help.

Then put it at eeprom address 0. It will use addresses 0 to 3.
cypherff



Joined: 23 Apr 2009
Posts: 4
Location: Montreal,QC,Canada

View user's profile Send private message MSN Messenger

Initialization problems
PostPosted: Sun Apr 26, 2009 11:47 pm     Reply with quote

I was able to Read and Write new values of the "password" variable although it did not store it once I powered down and back up. Is it even possible to retain it? Maybe the PIC automatically sets my in32 password to 0 at power up.

Here is my code that reads and writes to the EEPROM. Let me know if I made any mistakes.

Code:
void write_int32_EEPROM(int32 password)
{
   int i;
   long int y=0;
   
   for (i = 0; i < 4; i++)
      write_eeprom(i + y, *((int8*)&password + i) ) ;
}

int32 read_int32_EEPROM(void)
{
   int i;
   int32 password;
   long int y=0;
   
   for (i = 0; i < 4; i++)
      *((int8*)&password + i) = read_eeprom(i + y);

   return(password);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Apr 26, 2009 11:57 pm     Reply with quote

You have left out the address parameter in each routine. You have
taken away the general nature of the routines and hard-coded them
to use only address 0. Apparently that's what you want to do.

But if 'y' is always 0 there is no reason to have it in the routines.
i + 0 still = i. You might as well just use 'i' alone. You don't even
need to declare 'y' in each routine.

And then, because these are dedicated routines, the names of the
routines should be changed to something like 'write_password' and
'read_password'.
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