Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2152385
  • 博文数量: 361
  • 博客积分: 10828
  • 博客等级: 上将
  • 技术积分: 4161
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-20 14:34
文章分类

全部博文(361)

文章存档

2011年(132)

2010年(229)

分类:

2010-02-05 15:06:47

系统中由于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) |
给主人留下些什么吧!~~