vedavis
Joined: 16 Mar 2005 Posts: 1
|
Internal EEPROM 16F877 - No Retention (PCW 3.222) |
Posted: Wed Apr 06, 2005 7:29 am |
|
|
I cannot seem to keep values in the PIC16F877 Internal EEPROM when I shut down the PCS Debugger or power-cycle. If I run within the PCW debugger, my code set the values (using write_EEPROM(), see below) and when I refresh the Data EE the values are there. If I reset the MPU, the values are still there. If I close the PCW Debugger and then re-open it, the EEPROM values are gone, replaced with 0xFF (except for location 0x02, which is correct). #fuse NOPROTECT is being used. Now when the code runs, it's as though no values were set. Am I seeing a side-effect of the PCW Debugger or am I missing something?
Thanks, Vernon Davis
#FUSES:
NOWDT, HS, NOPUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, DEBUG
CODE:
//==========================================================================
void init_EEPROM(void) {
BYTE rev, inv_rev, tst_rev;
WORD i;
// Location 0 is the revision
// - The high nibble is the major revision
// - The low nibble is the minor revision
// Location 1 is the the inverse of the revision
rev = read_EEPROM(EEP_REVISION);
inv_rev = read_EEPROM(EEP_INV_REVISION);
// If Location 0 is not equal to the inverse of Location 1,
// then the EEPROM has not been initialized.
if (rev != ~inv_rev) {
set_Default_Label_Number(2);
set_Handshake_Protocol(AUTO_PROTOCOL);
for (i=1; i<16; i++) {
set_Motor_Speed(i, DEFAULT_MOTOR_SPEED);
set_Pick_Delay(i, DEFAULT_PICK_DELAY);
set_Label_Timeout(i, DEFAULT_LABEL_TIMEOUT);
}
// Write zeroes to designated EEPROM locations
for (i=128; i<256; i++) write_EEPROM(i, 0);
}
// If revision has changed, re-write it and the inverse
tst_rev = ((BYTE)(MAJOR_REV) << 4) | ((BYTE)(MINOR_REV));
if (tst_rev != rev) {
write_EEPROM(EEP_REVISION, tst_rev);
inv_rev = ~tst_rev;
write_EEPROM(EEP_INV_REVISION, inv_rev);
}
}
//==========================================================================
BYTE get_Default_Label_Number(void) {
return read_EEPROM(EEP_DEF_LBL_NO);
}
//==========================================================================
void set_Default_Label_Number(BYTE value) {
write_EEPROM(EEP_DEF_LBL_NO, value);
}
//==========================================================================
BYTE get_Motor_Speed(BYTE idx) {
return read_EEPROM((EEP_LABEL_1 + ((idx - 1) * 8)));
}
//==========================================================================
void set_Motor_Speed(BYTE idx, BYTE value) {
write_EEPROM((EEP_LABEL_1 + ((idx - 1) * 8)), value);
}
//==========================================================================
BYTE get_Pick_Delay(BYTE idx) {
return read_EEPROM((EEP_LABEL_1 + ((idx - 1) * 8)) + 1);
}
//==========================================================================
void set_Pick_Delay(BYTE idx, BYTE value) {
write_EEPROM((EEP_LABEL_1 + ((idx - 1) * 8)) + 1, value);
}
//==========================================================================
BYTE get_Label_Timeout(BYTE idx) {
return read_EEPROM((EEP_LABEL_1 + ((idx - 1) * 8)) + 2);
}
//==========================================================================
void set_Label_Timeout(BYTE idx, BYTE value) {
write_EEPROM((EEP_LABEL_1 + ((idx - 1) * 8)) + 2, value);
}
//==========================================================================
BYTE get_Handshake_Protocol(void) {
return read_EEPROM(EEP_PROTOCOL);
}
//==========================================================================
void set_Handshake_Protocol(BYTE value) {
write_EEPROM(EEP_PROTOCOL, value);
} |
|