請參考一下代碼:
uint16 ReadEEPData(uint8 *ptr)
{
uint8 i,j;
uint16 addr;
uint8 curBlock[EEP_SAVE_BYTE];
uint8 *bkDP;
bit bkEA = EA;
bit bWrited;
EA = 0;
FLASHCON = 1;
bkDP = ptr;
for(i=0; i<EEP_SAVE_BYTE; i++)
{
*ptr =0;
ptr++;
}
addr =EEP_SECTOR_USE;
j = 0;
for(i=0; i<EEP_SAVE_TIMES; i++)
{
bWrited = 0;
ptr = bkDP;
for(j=0; j<EEP_SAVE_BYTE; j++)
{
curBlock[j] = CBYTE[addr];
addr++;
if(curBlock[j]) bWrited = 1;
}
if(bWrited)
{
for(j=0; j<EEP_SAVE_BYTE; j++)
{
*ptr = curBlock[j];
ptr++;
}
}
else
{
break;
}
}
if(i == EEP_SAVE_TIMES)
{
EraseEEPSector(EEP_SECTOR_USE);
i = 0;
addr = EEP_SECTOR_USE;
}
else
{
addr -= EEP_SAVE_BYTE;
}
FLASHCON = 0;
EA = bkEA;
return(addr);
} |