我要把 sst29sf040当作 数据存储器 使用,89c52的WR接sst29sf040的WE端,89c52的RD接sst29sf040的OE端,单片机(89c52 )的P2.7口和它的CE端相连,P2.6--P2.0和它的A14--A8相连,P07--P00通过373与A7--A0相连,而sst29sf040的A18--A15接地 以下是我的程序:程序运行后发现外部地址0x0030上,没有写上数据0x20,用示波器检测各个管脚都有信号,但不知正确与否. #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
void wait(uchar p,uchar q); int Check_SST_29SF040(); void ByteProgram(uchar SrcByte,uint Dst); int Erase_One_Sector(uint Dst); uchar ByteRead(uint addr);
void main() { Erase_One_Sector(0); // while(1) //{ ByteProgram(0x20,0x0030); ByteRead(0x0030); // } } 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 Check_SST_29SF040() { uchar SST_id1; uchar SST_id2; int ReturnStatus; /* Issue the Software ID code to 29sf040*/ 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]= 0x90; wait(61,74); /*delay 10ms*/ /*read the product ID from29sf040*/ /* set up address to be 0000h */ SST_id1 = XBYTE[0x0000] ; /* get first ID byte???????????????*/ SST_id2 = XBYTE[0x0001];/* set up address to be 0001h */ if ((SST_id1 ==SST_ID)&&(SST_id2 == SST_29SF040)) { ReturnStatus = 0; } else ReturnStatus = -1; /* Issue the Soffware Product ID Exit code thus returning the 29EE020 */ /* to the read operating mode */ /* set up address to be 555h */ XBYTE[0x0555] = 0xAA; /* write data 0xAA to the address */ /* set up address to be 2AAh */ XBYTE[0x02AA] = 0x55; /* write data 0x55 to the address */ /* set up address to be 555h */ XBYTE[0x0555] =0xF0; /* write data 0xF0 to the address */ wait(61,74); /*delay 10ms*/ return(ReturnStatus);
} 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--); }
|