#include <MC9S08DZ60.h>
//初始化
void Flash_Init(void) {
FCDIV=0x31;
FPROT=0xFF;
FCNFG=0x00;
FSTAT = FSTAT | (FSTAT_FPVIOL | FSTAT_FACCERR);
if(!FCDIV&0x80)
{
FCDIV_DIVLD = 1;
}
while(!FSTAT&0x80);
}
//erase
void Flash_erase(unsigned int * address_1 ){
unsigned int * address;
if((FSTAT_FPVIOL==1)||(FSTAT_FACCERR==1)){
FSTAT=0x30;
}
address = (unsigned int *) address_1;
(* address) =0x00;
FCMD = 0x40; //Mass Erase
FSTAT = 0x80;
do{
_asm nop; _asm nop; _asm nop;
_asm nop;
}
while( !(FSTAT & 0x80));
while(!FSTAT_FCCF);
}
//写入数据
void Flash_write(unsigned int * __far address_1){
unsigned int * __far address;
address = (unsigned int * __far ) address_1;
if((FSTAT_FPVIOL==1)||(FSTAT_FACCERR==1)){
FSTAT=0x30;
}
FCMD=0x20;
* address = 0x12;
FSTAT_FCBEF=1;
FSTAT = 0x80;
do{
_asm nop;
_asm nop;
_asm nop;
_asm nop;
}
while( !(FSTAT & 0x80));
while(!FSTAT_FCBEF);
while(!FSTAT_FCCF);
}
以上是我自己写的一段代码,想求问下为什么写入flash 0x12这个数据不成功呢?谢谢各位了 |