View previous topic :: View next topic |
Author |
Message |
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
Write to / read from PIC16LF877A internal eeprom |
Posted: Mon Jul 10, 2006 3:09 am |
|
|
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
|
|
Posted: Mon Jul 10, 2006 3:59 am |
|
|
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
|
|
Posted: Mon Jul 10, 2006 4:03 am |
|
|
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
|
|
Posted: Mon Jul 10, 2006 9:40 am |
|
|
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
|
|
Posted: Mon Jul 10, 2006 2:49 pm |
|
|
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
|
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Tue Jul 11, 2006 12:58 am |
|
|
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
|
|
Posted: Tue Jul 11, 2006 8:02 am |
|
|
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
|
|
Posted: Tue Jul 11, 2006 9:31 am |
|
|
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. |
|
|
|