请参考PE生成的代码:
/*
** ===================================================================
** Method : WriteSector (bean IntEEPROM)
**
** Description :
** The method writes the dword sector data to an EEPROM memory.
** This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static byte WriteSector(IEE1_TAddress AddrSec,dword Data32)
{
byte err; /* Temporary variable */
if (ESTAT_CBEIF == 0) { /* Is command buffer full ? */
return ERR_BUSY; /* If yes then error */
}
/* ESTAT: PVIOL=1,ACCERR=1 */
ESTAT = 48; /* Clear error flags */
*(volatile word *)(AddrSec) = (word)(Data32 >> 16); /* Array address and program data - higher part */
/* ECMD: ??=0,CMDB6=1,CMDB5=1,??=0,??=0,CMDB2=0,??=0,CMDB0=0 */
ECMD = 96; /* Sector modify command */
ESTAT_CBEIF = 1; /* Clear flag command buffer empty */
if ((ESTAT_PVIOL == 1)||(ESTAT_ACCERR == 1)) { /* Is protection violation or acces error detected ? */
return ERR_NOTAVAIL; /* If yes then error */
}
while (ESTAT_CBEIF == 0) {} /* Wait to buffer empty */
err=WriteWord(AddrSec + 2,(word)Data32); /* Write lower part */
if (err != ERR_OK) { /* Was attemp to write data to the given address errorneous? */
return err; /* If yes then error */
}
if (*(volatile word *)(AddrSec) != (word)(Data32 >> 16)) { /* Was attempt to write data to the given address errorneous? */
return ERR_VALUE; /* If yes then error */
}
return ERR_OK;
}
|