AT45DB041存儲芯片讀寫程序,適用于51單片機 精品.doc_第1頁
AT45DB041存儲芯片讀寫程序,適用于51單片機 精品.doc_第2頁
AT45DB041存儲芯片讀寫程序,適用于51單片機 精品.doc_第3頁
AT45DB041存儲芯片讀寫程序,適用于51單片機 精品.doc_第4頁
AT45DB041存儲芯片讀寫程序,適用于51單片機 精品.doc_第5頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

/*這個程序原本是從論壇上下載的,但是用到51單片機中不能使用,只能一次寫一個字節(jié),經(jīng)過高手的修改,已經(jīng)能夠用在51中。20XX.07.27*/*/ /*正常操作電壓為2.73.6V,實驗中發(fā)現(xiàn)當電壓超過4.25V后讀出的狀態(tài)字節(jié)為9A(正常 */ /*的狀態(tài)字節(jié)值為9D),并且讀寫數(shù)據(jù)均不準確,所以應(yīng)當保證卡片的供電電壓不超過 */ /*4.25V。 */ /*SPI規(guī)范:Data is always clocked into the device on the rising edge of SCK a-*/ /* nd clocked out of the device on the falling edge of SCK.All instruction-*/ /* s,addresses and data are transferred with the most significant bit(MSB) */ /* first. */ /* 20XX-06-02*/ /*/ #include #include #include #include #define UCHAR unsigned char #define UINT unsigned int /=sfr P4 = 0xe8;/=sbit SPI_CS = P41; sbit SPI_SCK = P40; sbit SPI_SO = P43; sbit SPI_SI = P42; unsigned char aaa;void dyms20(void)unsigned char i;for(i=0;i30;i+) i+;unsigned char SPI_HostReadByte(void) unsigned char i,rByte=0; for(i=0;i8;i+) SPI_SCK=0; dyms20(); SPI_SCK=1; rByte=1; if(SPI_SO) rByte |= 0x01; else rByte &= 0x01; return rByte; void SPI_HostWriteByte(unsigned char wByte) unsigned char i; for(i=0;i8;i+) if(wBytei)&0x80)SPI_SI=1; elseSPI_SI=0; SPI_SCK=0; dyms20(); SPI_SCK=1; dyms20(); /*/ /*Status Register Format: */ /* - */ /* | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 | */ /* |-|-|-|-|-|-|-|-| */ /* |RDY/BUSY| P | 0 | 1 | 1 | 1 | X | X | */ /* - */ /* bit7 - 忙標記,0為忙1為不忙。 */ /* 當Status Register的位0移出之后,接下來的時鐘脈沖序列將使SPI器件繼續(xù)*/ /* 將最新的狀態(tài)字節(jié)送出。 */ /* bit6 - 標記最近一次Main Memory Page和Buffer的比較結(jié)果,0相同,1不同。 */ /* bit5 */ /* bit4 */ /* bit3 */ /* bit2 - 這4位用來標記器件密度,對于AT45DB041B,這4位應(yīng)該是0111,一共能標記 */ /* 16種不同密度的器件。 */ /* bit1 */ /* bit0 - 這2位暫時無效 */ /*/ unsigned char AT45DB041B_StatusRegisterRead(void) unsigned char i; SPI_CS=0; SPI_HostWriteByte(0xd7); i=SPI_HostReadByte(); SPI_CS=1; return i; /*/ /*描述: */ /* When the last bit in the main memory array has been read,the device will*/ /* continue reading back at the beginning of the first page of memory.As w-*/ /* ith crossing over page boundaries,no delays will be incurred when wrapp-*/ /* ing around from the end of the array to the beginning of the array. */ /*參數(shù): */ /* PA - 頁地址,02047 */ /* BFA - 指定BUFFER中的起始寫入地址 */ /* pHeader - 指定數(shù)據(jù)的首地址 */ /* len - 指定數(shù)據(jù)的長度 */ /*/ void AT45DB041B_ContinuousArrayRead(UINT PA,UINT BFA,unsigned char *pHeader,UINT len) unsigned int i=0; while(i+7); SPI_HostWriteByte(unsigned char)(PA8); SPI_HostWriteByte(unsigned char)BFA); for(i=0;i4;i+)SPI_HostWriteByte(0x00); for(i=0;ilen;i+)pHeaderi=SPI_HostReadByte(); SPI_CS=1; /*/ /*描述: */ /* 將指定數(shù)據(jù)寫入從某個地址(0263)開始的BUFFER中。 */ /*參數(shù): */ /* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */ /* 在該指令序列中,操作碼84H選擇BUFFER 1,87H選擇BUFFER 2 */ /* BFA - BUFFER中的起始地址,0263 */ /* pHeader - 待存數(shù)據(jù)的頭指針 */ /* len - 待存數(shù)據(jù)的長度1264 */ /*/ void AT45DB041B_BufferWrite(UCHAR buffer,UINT BFA,UCHAR *pHeader,UINT len) unsigned int i; while(i+8); SPI_HostWriteByte(unsigned char)BFA); for(i=0;ilen;i+)SPI_HostWriteByte(pHeaderi); SPI_CS=1; void memorytobuffer(unsigned int maddr)unsigned int i;while(i+7); SPI_HostWriteByte(unsigned char)(maddr1);SPI_HostWriteByte(0x0); SPI_CS=1; /*/ /*描述: */ /* 將指定數(shù)據(jù)寫入從某個地址(0263)開始的頁中:包含2個動作,首先將指定數(shù)據(jù)*/ /* 寫入到BUFFER 1或者BUFFER 2中,其中可以指定BUFFER中的起始寫入地址,此寫入*/ /* 動作不影響B(tài)UFFER中其它地址中的數(shù)據(jù),然后再將BUFFER中的整個數(shù)據(jù)寫入到某指*/ /* 定頁中(帶預(yù)擦除)。 */ /*參數(shù): */ /* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */ /* PA - 頁地址,02047 */ /* BFA - 指定BUFFER中的起始寫入地址 */ /* pHeader - 指定數(shù)據(jù)的首地址 */ /* len - 指定數(shù)據(jù)的長度 */ /*/ void AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(UCHAR buffer,UINT PA,UINT BFA,UCHAR *pHeader,UINT len) unsigned int i; memorytobuffer(PA); AT45DB041B_BufferWrite(buffer,BFA,pHeader,len); while(i+7); SPI_HostWriteByte(unsigned char)(PA1); SPI_HostWriteByte(0x00); SPI_CS=1; void main(void) unsigned char i; UCHAR xdata test32; i=AT45DB041B_StatusRegisterRead(); memset(test,0x77,32); AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(1,2047,0,test,32); memset(test,0x26,32); AT45DB041B_ContinuousArrayRead(2047,0,test,32); buf31=test0; mems

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論