本帖最后由 石头2010 于 2010-8-5 20:47 编辑
目的:想在0xfc_8000到0xfc_bfff中读写数据
MCU工作模式:单S12X 正常工作模式
实现代码:
void Flash_Sector_Erase(byte page, word addr)
{
byte old_ppage;
while(FCLKDIV_FDIVLD == 0);
while(FSTAT_CBEIF == 0); // 等待命令缓冲区为空
FSTAT |= 0x30; // 写1,清除PVIOL(保护位)和ACCERR(错误标志)
while(!(FPROT & 0x80)); // FLASH是否允许进行编程
old_ppage = PPAGE;
PPAGE = page;
*((volatile word *)(addr))= 0xff; // 0xff将被忽略
FCMD = 0x40; // 写入段擦除命令
FSTAT=0x80;
while(!(FSTAT&0x40));
PPAGE = old_ppage;
}
void Flash_Write(byte page,word addr,word data)
{
byte old_ppage;
while(FCLKDIV_FDIVLD == 0);
while(FSTAT_CBEIF == 0); // 等待命令缓冲区为空
FSTAT |= 0x30; // 写1,清除PVIOL(保护位)和ACCERR(错误标志)
while(!(FPROT & 0x80)); // FLASH是否允许进行编程
old_ppage = PPAGE;
PPAGE = page;
*((volatile word *)(addr))=data;
FCMD = 0x20; //置编程命令
FSTAT=0x80;
while(!(FSTAT&0x40));
PPAGE = old_ppage;
}
word Flash_Read(byte page,word addr1) {
byte old_ppage;
word data;
old_ppage = PPAGE;
PPAGE = page;
data = *((volatile word *)(addr1));
PPAGE = old_ppage;
return data;
}
main()
{
word temp;
Flash_Sector_Erase(0xfc,0x8000);
Flash_Write(0xfc,0x8000,0x1234);
temp = Flash_Read(0xfc,0x8000);
}
读取的数据不是0x1234;
请朋友们帮助我解决这个问题,非常急,也非常感谢! |