|
void AT45DB041B_ContinuousArrayRead(UINT PA,UINT BFA,unsigned char *pHeader,UINT len){ unsigned int i;
while(!(AT45DB041B_StatusRegisterRead()&0x80)); // while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}} SPI_CS=0;
SPI_HostWriteByte(0xe8); SPI_HostWriteByte((unsigned char)(PA>>7)); SPI_HostWriteByte((unsigned char)((PA<<1) (BFA>>8))); SPI_HostWriteByte((unsigned char)BFA); for(i=0;i<4;i++){SPI_HostWriteByte(0x00);} for(i=0;i<len;i++){pHeader=SPI_HostReadByte();} SPI_CS=1;
}
/*描述: */ /* 將指定數(shù)據(jù)寫(xiě)入從某個(gè)地址(0~263)開(kāi)始的BUFFER中。 */ /*參數(shù): */ /* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */ /* 在該指令序列中,操作碼84H選擇BUFFER 1,87H選擇BUFFER 2 */ /* BFA - BUFFER中的起始地址,0~263 */ /* pHeader - 待存數(shù)據(jù)的頭指針 */ /* len - 待存數(shù)據(jù)的長(zhǎng)度1~264 */
void AT45DB041B_BufferWrite(UCHAR buffer,UINT BFA,UCHAR *pHeader,UINT len){ unsigned int i;
while(!(AT45DB041B_StatusRegisterRead()&0x80)); //while(i++<255){if(AT45DB041B_StatusRegisterRead()&0x80){break;}} SPI_CS=0;
switch(buffer){ case 1:SPI_HostWriteByte(0x84);break; case 2:SPI_HostWriteByte(0x87);break; } SPI_HostWriteByte(0x00); SPI_HostWriteByte((unsigned char)(BFA>>8)); SPI_HostWriteByte((unsigned char)BFA); for(i=0;i<len;i++){SPI_HostWriteByte(pHeader);} SPI_CS=1; } /*描述: */ /* 將指定數(shù)據(jù)寫(xiě)入從某個(gè)地址(0~263)開(kāi)始的頁(yè)中:包含2個(gè)動(dòng)作,首先將指定數(shù)據(jù)*/ /* 寫(xiě)入到BUFFER 1或者BUFFER 2中,其中可以指定BUFFER中的起始寫(xiě)入地址,此寫(xiě)入*/ /* 動(dòng)作不影響B(tài)UFFER中其它地址中的數(shù)據(jù),然后再將BUFFER中的整個(gè)數(shù)據(jù)寫(xiě)入到某指*/ /* 定頁(yè)中(帶預(yù)擦除)。 */ /*參數(shù): */ /* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */ /* PA - 頁(yè)地址,0~2047 */ /* BFA - 指定BUFFER中的起始寫(xiě)入地址 */ /* pHeader - 指定數(shù)據(jù)的首地址 */ /* len - 指定數(shù)據(jù)的長(zhǎng)度 */
void AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(UCHAR buffer,UINT PA,UINT BFA,UCHAR *pHeader,UINT len){ // unsigned int i;
AT45DB041B_BufferWrite(buffer,BFA,pHeader,len); while(!(AT45DB041B_StatusRegisterRead()&0x80)); // while(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}} SPI_CS=0;
switch(buffer){ case 1:SPI_HostWriteByte(0x83);break; case 2:SPI_HostWriteByte(0x86);break; } SPI_HostWriteByte((unsigned char)(PA>>7)); SPI_HostWriteByte((unsigned char)(PA<<1)); SPI_HostWriteByte(0x00); SPI_CS=1;
}
/*描述: */ /* 與上一個(gè)函數(shù)的唯一區(qū)別是不帶預(yù)擦除。 */
void AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(UCHAR buffer,UINT PA,UINT BFA,UCHAR *pHeader,UINT len){ unsigned int i=0;
AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
while(!(AT45DB041B_StatusRegisterRead()&0x80)); // while(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}} SPI_CS=0; SPI_HostWriteByte(0x87+buffer); SPI_HostWriteByte((unsigned char)(PA>>7)); SPI_HostWriteByte((unsigned char)(PA<<1)); SPI_HostWriteByte(0x00); // for(i=0;i<len;i++){SPI_HostWriteByte(pHeader);} SPI_CS=1;
}
void main(void){
unsigned char i; UCHAR data test[32]; // SPI_RESET = 0; // SPI_WP = 0; // delay(2000);
// SPI_RESET = 1;// // SPI_WP = 1;//取消寫(xiě)保護(hù)
i=AT45DB041B_StatusRegisterRead();
for(i = 0; i < 32; i++) {test = i + 0x20;} AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(1,0,0,test,32); memset(test,0x26,32); AT45DB041B_ContinuousArrayRead(0,0,test,32);
for(i = 0; i < 32; i++) {test = i + 0x10;}
AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(2,1,0,test,32); memset(test,0x55,32); AT45DB041B_ContinuousArrayRead(1,0,test,32);
while(1){} }
|