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

Write to / read from PIC16LF877A internal eeprom

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



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

Write to / read from PIC16LF877A internal eeprom
PostPosted: Mon Jul 10, 2006 3:09 am     Reply with quote

Hi,

I need to save a float to the eeprom at certain time. After a device reset I should be able to read the same float from EEPROM and use it.
I manage to save it and read it but when I reprogram my PIC (=flash) and I want to read the EEPROM it reads FF FF FF FF.
Could you help me figure out what's the problem?
Or why does the EEPROM get erased on programming? When I want to update my PIC software, my EEPROM values are being deleted!? That is not wanted. If this is, how can I solve this problem?

header file fuses:
Code:
//NEXTSCOPE DEV
#include <16F877A>
#device adc=10 *=16 // meer geheugen
#fuses XT, PUT, NOWDT, NOPROTECT, NOLVP, NOCPD, NOWRT, NOBROWNOUT, NODEBUG
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS)


function declarations
Code:
void WRITE_FLOAT_EEPROM (int8 n, float data);
float READ_FLOAT_EEPROM (int8 n);


write to EEPROM (don't mind the buzzers)
Code:
//****************** V_07_TIMER afgelopen vlag afhandelen ******************//
// Na 7 minuten in calibratiemode V07 meten en opslaan nr EEPROM
   If ( V_07_TIMER_AFGELOPEN )
   {
      V_07_TIMER_AFGELOPEN = FALSE;
      Meet_Vbat ();
      V07 = Vbat;
      WRITE_FLOAT_EEPROM (0, V07);
      Buzzer ();
      delay_ms (150);
      Buzzer ();
      delay_ms (150);
      Buzzer ();
      delay_ms (150);
   }

read from EEPROM
Code:
         case TESTEN:
                  V07 = READ_FLOAT_EEPROM (0);
                  Send_Float_RS232 (V07 , 0);
                  break;


Reading and writing functions: (got them from CCS faq page, slightly adapted)
Code:
//************************** Schrijf naar EEPROM *****************************//
void WRITE_FLOAT_EEPROM (int8 n, float data)
{
   int8 i;

   for (i = 0; i < 4; i++)
      write_eeprom (i + n, *(&data + i) ) ;
}

//**************************** Lees van EEPROM *******************************//
float READ_FLOAT_EEPROM (int8 n)
{
   int8 i;
   float data;

   for (i = 0; i < 4; i++)
      *(&data + i) = read_eeprom (i + n);

   return(data);
}
Ttelmah
Guest







PostPosted: Mon Jul 10, 2006 3:59 am     Reply with quote

This is really a 'programmer' question, not a CCS question. The answer will depend on what programmer you are using. If the programmer is performing a bulk erase before programming (normal), then the EEPROM will be erased as well. Most programmers will do a bulk erase, and then use just program cycles to write the code to the chip. However some units will have option settings to allow seperate program/erase cycles for each block. Oherwise, you are going to have to read the EEPROM contents, and save these, then reload them after programming the chip (again some programmers have an option to do this).

Best Wishes
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Mon Jul 10, 2006 4:03 am     Reply with quote

I am using the CCS-ICDU40 programmer.
Does anybody know how I can prevent a bulk erase using the ICDU40?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Jul 10, 2006 9:40 am     Reply with quote

In the ICD.exe program in the lower right corner is an ADVANCED tab
under that is the bulk erase mode enable/disable.
rglapion



Joined: 06 Jul 2006
Posts: 1
Location: Huntsville, AL

View user's profile Send private message

PostPosted: Mon Jul 10, 2006 2:49 pm     Reply with quote

Instead of trying to disable the bulk erase of the programmer, I tried the brute force approach. Once the Target board has the data that you want in the EEPROM use the programming software to read the EEPROM data. Then I use MPLAB to save the EEPROM data along with the compiled C code. When I want to program another device I use the FILE - IMPORT command to import the saved file that contains the EEPROM data along with my compiled code. You just have to remember to repeat the steps every time you compile.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 10, 2006 2:57 pm     Reply with quote

Yes, but as Treitmey says, CCS has got the feature in it, as explained
in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=21777
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Tue Jul 11, 2006 12:58 am     Reply with quote

Thanks for the input, but I cannot find that option? I'm using PCW windows ide. I do not see the hammer + wrench icon?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jul 11, 2006 8:02 am     Reply with quote

Go into debug mode.
Then in the debug window, is a debug configure tab.
That is where the hammer/wrench is found.
Clicking on it just brings up the ICD.exe program.
Then in the lower right is the advanced button...(same as above)

Is it that the two programs share these configurations???
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Tue Jul 11, 2006 9:31 am     Reply with quote

I guess the pcw.exe uses the icd.exe and so uses the settings of icd.exe. Thnks for input, eeprom data is guarded now.
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