void EraseChip( unsigned short u16Address )
{
PSCTL = 0x03;
WriteByteToFlash( u16Address & 0xFE00, 0x00);
PSCTL = 0x00;
}
unsigned char PrgCode(unsigned short iAddress, unsigned short u16Len, unsigned char *pu8Data)
{
unsigned char cStatus;
unsigned short Cnt;
unsigned int iRealAddr;
for (Cnt=0; Cnt<u16Len; Cnt++)
{
iRealAddr = iAddress + Cnt;
PSCTL = 0x01;
WriteByteToFlash(iRealAddr, pu8Data[Cnt]);
PSCTL = 0x00;
if (*(unsigned char code *)iRealAddr != pu8Data[Cnt])
{
cStatus = 0xFF;
break;
}
}
return cStatus;
}
void WriteByteToFlash(unsigned short iAddress, unsigned char cData)
{
unsigned char data cByte = cData;
FLKEY = 0XA5;
FLKEY = 0XF1;
*(unsigned char xdata *)iAddress = cByte;
}