我在使用flash sst29sf040作为数据存储器时,好像得要首先声明unsigned char data型的数组,然后才能一个一个写到sst29sf040内部,也就是AT89C52要消耗掉同样多的数据空间,才能将数据写进sst29sf040,难道必须这样吗?这样不还是会消耗AT89C52的程序空间,等于没有外扩ram吗?下面是我的程序 #define _SST_C_ #include "reg51.h" #include "sst.h" #include <intrins.h> #include <absacc.h>
#define FALSE 0 #define TRUE 1
#define SECTOR_SIZE 128 /*Must be 128 bytes for 29EE020*/
#define SST_ID 0xBF #define SST_29SF040 0X13 #define uchar unsigned char #define uint unsigned int uchar data buff[5]={0x4e,0xae,0x89 ,0x39,0x43};
void wait(uchar p,uchar q); void ByteProgram(uchar SrcByte,uint Dst); int Erase_One_Sector(uint Dst); uchar ByteRead(uint addr); void main() { uchar i; Erase_One_Sector(0); for (i=0;i<128;i++) { if(i<5) { ByteProgram(buff,0x0000+i); } else ByteProgram(i,0x0000+i); } Erase_One_Sector(128); for (i=0;i<128;i++) { if(i<5) { ByteProgram(buff,0x0080+i); } else ByteProgram(0x80+i,0x0080+i); } }
void ByteProgram(uchar data SrcByte,uint Dst) { XBYTE[0x0555] = 0xAA; XBYTE[0x02AA] = 0x55; XBYTE[0x0555] = 0xA0; XBYTE[Dst] = SrcByte; //Check_Toggle_Ready(Dst); wait(1,9);//等待25us } int Erase_One_Sector(uint Dst) {
/* Issue the Sector Erase command to 39SF040 */
XBYTE[0x0555] = 0xAA; /* set up address to be 555h */ /* write data 0xAA to the address */ XBYTE[0x02AA] = 0x55; /* set up address to be 2AAh */ /* write data 0x55 to the address */ XBYTE[0x0555] = 0x80; /* set up address to be 555h */ /* write data 0x80 to the address */ XBYTE[0x0555] = 0xAA; /* set up address to be 555h */ /* write data 0xAA to the address */ XBYTE[0x02AA] = 0x55; /* set up address to be 2AAh */ /* write data 0x55 to the address */ XBYTE[Dst] = 0x20; /* set up starting address to be erased */ /* write data 0x30 to the address */ wait(85,134); /* check DATABOOK for the most */ /* accurate value -- Tse */ }
uchar ByteRead(uint addr) { uchar GetData; GetData = XBYTE[addr]; return(GetData); } void wait(uchar p,uchar q) { uchar i,j; //(2*j+3)*i+4 for (i=p;i>0;i--)
for (j=q;j>0;j--); } |