UINT8 Page_Erase(UINT8 Adress)
{
if(FSTAT&0x10) //check to see if FACCERR is set
{
FSTAT=FSTAT|0x10; //write 1 to FACCERR to clear
}
(*((volatile UINT8*)(Adress)))=0xaa; //write to somewhere in flash
FCMD=0x40; // set command type sector erase
FSTAT=FSTAT|0x80; //put FCBEF at 1
_asm NOP;
_asm NOP;
_asm NOP;
_asm NOP; //wait four cycles
if(FSTAT&0x30) //check to see if FACCERR or FPVIOL are set
{
return 0x00; //if so ,Error
}
while (!(FSTAT&0x40)); //wait for command to complete
return 0x01;
}
UINT8 Program_Byte(UINT16 Adress,UINT8 data)
{
if(FSTAT&0x10) //check to see if FACCERR is set
{
FSTAT=FSTAT|0x10; //write 1 to FACCERR to clear
}
(*((volatile UINT16*)(Adress)))=data; //write data to somewhere in flash
FCMD=0x20; // set command type byte program
FSTAT=FSTAT|0x80; //put FCBEF at 1
_asm NOP;
_asm NOP;
_asm NOP;
_asm NOP; //wait four cycles
if(FSTAT&0x30) //check to see if FACCERR or FPVIOL are set
{
return 0x00; //if so ,Error
}
while (!(FSTAT&0x40)); //wait for command to complete
return 0x01;
}