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

Why Is EEPROM Data Erased?

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



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

Why Is EEPROM Data Erased?
PostPosted: Tue Mar 24, 2009 5:13 pm     Reply with quote

Hi,
I wrote a very simple code to write 22 byte to EEPROM from address 0 to 21 and read data back successfully.
Code:

#include <16F689.h>
#include <stdio.h>
#include <stdlib.h>

#use delay(clock=3686400, crystal)
#use rs232(baud=115200, xmit=PIN_B7, rcv=PIN_B5)
#fuses XT, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN

unsigned int8 i;

void main()
{
  for(i=1; i<=22; i++)
    write_eeprom(i-1, i);
  for(i=0; i<=21; i++)
    putc(read_eeprom(i));
  while(1);
}

However, if I recompile the code without write_eeprom() and power reset, I read back 0xFF from the same eeprom chip.
Code:

#include <16F689.h>
#include <stdio.h>
#include <stdlib.h>

#use delay(clock=3686400, crystal)
#use rs232(baud=115200, xmit=PIN_B7, rcv=PIN_B5)
#fuses XT, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN

unsigned int8 i;

void main()
{
  for(i=0; i<=21; i++)
    putc(read_eeprom(i));
  while(1);
}

Could anybody tell me what I am missing in my code? My compiler is 4.085 and MPLAB IDE is 8.15a.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 5:47 pm     Reply with quote

It's a setting in the programmer's options. See this link for ICD2:
http://www.ccsinfo.com/forum/viewtopic.php?t=33108
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 6:07 pm     Reply with quote

But I am using PICKit2 instead of ICD2. I do not see the option of preserve EEPROM data.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 6:48 pm     Reply with quote

In MPLAB 8.20a, if you select PicKit2 as the programmer and then go to
the Programmer menu and click on Settings, a dialog box will appear.
In the Settings tab, it has a tickbox for "Preserve Device EEPROM".
If you don't have that option, then I suggest you upgrade MPLAB.
boulder



Joined: 15 Mar 2008
Posts: 53

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 8:59 pm     Reply with quote

PCM,
Thanks. You are right, the latest version of MPLAB, 8.20a has this option for PicKit2.
I have one more question about read data eeprom. Does it need to add delay between reading each byte data from eeprom? If the answer is yes, what's the minimum delay?

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 24, 2009 9:33 pm     Reply with quote

There is no delay for reading. For writing, the delay is handled by the
CCS compiler in the write_eeprom() function. You don't have to do anything.
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