Dear sir,
I am using ms9c12xdp512 16 bit mcu. I want to erase flash by sector(1024 bytes). But the function can not work. Can you help me?
main.c
{
INT8U data[2] = {48, 49};
writeByte(0xFA, (INT8U*)0xBFFE, data, 2); //Write data to PAGE_FA, check the memory, it worked.
eraserSector(0xFA, 0x8000, 16); //After calling this, it does not work, the data in 0XFABFFE is still there.
}
//erase by sector(1024 bytes)
void eraserSector(INT8U page, INT16U address, INT8U count){
INT16U i;
INT8U d;
INT8U oldPage;
oldPage = PPAGE;
while(!(FCLKDIV & 0x80));
if(PPAGE){
PPAGE = page;
d = page&0x0C;
d = d>>2;
FCNFG = 3-d;
}
for(i=0;i<count;i++, address += 1024){
while(!(FSTAT & 0x80));
while(FSTAT & 0x30){
FSTAT |= 0x30;
}
while(!(FPROT & 0x80));
__DINT;
*(INT16U*)address = 0xFFFF;
FCMD = 0x40;
FSTAT |= 0x80;
while( !FSTAT_CBEIF );
while( !FSTAT_CCIF );
__EINT;
}
PPAGE = oldPage;
}