Hello,
Before using the emulation library, i would like to understand what is wrong in my code since i simply copied what i found either in C30 guide or in PIC24F Datasheets
PROG_Read is fine and works !
PROG_Write and PROG_Erase do not ?!
Any body to help me ? thank's a lot in advance
Philippe
int __attribute__ (( aligned (4), space (prog) )) FailSafe1 = 1;
/*---------------------------------------------------------------------------*/
void PROG_Write(int data)
{
int offset;
int i ;
// Set up NVMCON to write one word of data EEPROM
NVMCON = 0x4003;
// Set up a pointer to the EEPROM location to be written
__builtin_tblpage(&FailSafe1);
offset = __builtin_tbloffset(&FailSafe1);
// Write Data Value To Holding Latch
__builtin_tblwtl(offset, data);
// Disable Interrupts For 5 Instructions
asm volatile ("disi #5");
// Issue Unlock Sequence & Start Write Cycle
__builtin_write_NVM();
}
/*---------------------------------------------------------------------------*/
void PROG_Erase()
{
int offset;
// Set up NVMCON to erase one word of data EEPROM
NVMCON = 0x4043;
// Set up a pointer to the EEPROM location to be erased
__builtin_tblpage(&FailSafe1);
offset = __builtin_tbloffset(&FailSafe1);
__builtin_tblwtl(offset, 0XFFFF);
// Disable Interrupts For 5 Instructions
asm volatile ("disi #5");
// Issue Unlock Sequence & Start Write Cycle
__builtin_write_NVM();
}
/*---------------------------------------------------------------------------*/
void PROG_Read()
{
int offset;
int data,i ;
// Set up a pointer to the EEPROM location to be read
__builtin_tblpage(&FailSafe1);
offset = __builtin_tbloffset(&FailSafe1);
// Read the EEPROM data
data = __builtin_tblrdl(offset);
}
post edited by BulleTracker - 2009/03/11 19:07:50