在系统中由于NOR FLASH非易失性,线性,可随机存取,支持字节操作等特性,在很多项目中都会加入它。NOR FLASH的读写还是很简单的,根据DATASHEET里说明来写入命令就可以了。呵呵。里面的数据是参考DATASHEET,不明白的去看它。
#define write(addr,data) *((volatile unsigned short *)(addr<<1))=(unsigned short)data
#define read(addr) (*((volatile unsigned short *)(addr<<1)))
#define reset() write(0x0,0xf0f0)
unsigned int SST39VF160_CheckID(void)
{
reset();
write(0x5555,0xaa);
write(0x2aaa,0x55);
write(0x5555,0x90);
ManID=read(0x0000);
DevID=read(0x0001);
reset();
return ((ManID<<16)+DevID);
}
unsigned char SST39VF160_Erase(void)
{ //擦除FLASH
write(0x5555,0xaa);
write(0x2aaa,0x55);
write(0x5555,0x80);
write(0x5555,0xaa);
write(0x2aaa,0x55);
write(0x5555,0x10);
return 1;
}
unsigned char SST39VF160_WordPro(unsigned int addr,unsigned short data)
{ //写入两个字节,一个SHORT字
write(0x5555,0xaa);
write(0x2aaa,0x55);
write(0x5555,0xa0);
write(addr,data);
return wait();
}
unsigned char wait(void)
{
volatile unsigned short flashstatus,old;
old = *((volatile unsigned short *)0x0);
while(1)
{
flashstatus = *((volatile unsigned short *)0x0);
if((old&0x1000) == (flashstatus&0x1000))
break;
old=flashstatus;
}
return 1;
}
以上是一些功能函数,若你想实现FLASH的烧写,还得组合这些函数,设置一些标志,当擦除完成,烧写完成时,以便实时监控哦!
以下为芯片资料地址,来自老古开发网.
阅读(3720) | 评论(0) | 转发(0) |