日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]/******************************************************************************//*正常操作電壓為2.7~3.6V,實(shí)驗(yàn)中發(fā)現(xiàn)當(dāng)電壓超過4.25V后讀出的狀態(tài)字節(jié)為9A(正常 */ /*的狀態(tài)字節(jié)值為9D),并且讀寫數(shù)據(jù)均不

/******************************************************************************/

/*正常操作電壓為2.7~3.6V,實(shí)驗(yàn)中發(fā)現(xiàn)當(dāng)電壓超過4.25V后讀出的狀態(tài)字節(jié)為9A(正常 */
/*的狀態(tài)字節(jié)值為9D),并且讀寫數(shù)據(jù)均不準(zhǔn)確,所以應(yīng)當(dā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. */
/* 2005-06-02*/
/******************************************************************************/
#pragma optimize(5)
#i nclude
#i nclude

#define UCHAR unsigned char
#define UINT unsigned int

sbit SPI_CS = P2^0;
sbit SPI_SCK = P2^2;
sbit SPI_SO = P2^3;
sbit SPI_SI = P2^4;

unsigned char SPI_HostReadByte(void){
unsigned char i,rByte=0;

for(i=0;i<8;i++){
SPI_SCK=0;
SPI_SCK=1;

rByte<<=1;
rByte|=SPI_SO;
}
return rByte;
}
void SPI_HostWriteByte(unsigned char wByte){
unsigned char i;

for(i=0;i<8;i++){
if((wByte< else{SPI_SI=0;}

SPI_SCK=0;
SPI_SCK=1;
}
}
/******************************************************************************/
/*Status Register Format: */
/* ----------------------------------------------------------------------- */
/* | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 | */
/* |--------|--------|--------|--------|--------|--------|--------|--------| */
/* |RDY/BUSY| COMP | 0 | 1 | 1 | 1 | X | X | */
/* ----------------------------------------------------------------------- */
/* bit7 - 忙標(biāo)記,0為忙1為不忙。 */
/* 當(dāng)Status Register的位0移出之后,接下來的時鐘脈沖序列將使SPI器件繼續(xù)*/
/* 將最新的狀態(tài)字節(jié)送出。 */
/* bit6 - 標(biāo)記最近一次Main Memory Page和Buffer的比較結(jié)果,0相同,1不同。 */
/* bit5 */
/* bit4 */
/* bit3 */
/* bit2 - 這4位用來標(biāo)記器件密度,對于AT45DB041B,這4位應(yīng)該是0111,一共能標(biāo)記 */
/* 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 - 頁地址,0~2047 */
/* BFA - 指定BUFFER中的起始寫入地址 */
/* pHeader - 指定數(shù)據(jù)的首地址 */
/* len - 指定數(shù)據(jù)的長度 */
/******************************************************************************/
void AT45DB041B_ContinuousArrayRead(UINT PA,UINT BFA,unsigned char *pHeader,UINT len){
unsigned int i;

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 SPI_CS=1;
}
/******************************************************************************/
/*描述: */
/* 將指定數(shù)據(jù)寫入從某個地址(0~263)開始的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ù)的長度1~264 */
/******************************************************************************/
void AT45DB041B_BufferWrite(UCHAR buffer,UINT BFA,UCHAR *pHeader,UINT len){
unsigned int i;

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 SPI_CS=1;
}
/******************************************************************************/
/*描述: */
/* 將指定數(shù)據(jù)寫入從某個地址(0~263)開始的頁中:包含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 - 頁地址,0~2047 */
/* 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;

AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
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;
}
/******************************************************************************/
/*描述: */
/* 與上一個函數(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(i++<1000){if(AT45DB041B_StatusRegisterRead()&0x80){break;}}

SPI_CS=0;
SPI_HostWriteByte(0x88+buffer);
SPI_HostWriteByte((unsigned char)(PA>>7));
SPI_HostWriteByte((unsigned char)(PA<<1));
SPI_HostWriteByte(0x00);

for(i=0;i SPI_CS=1;
}

void main(void){
unsigned char i;
UCHAR data test[32];

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);

memset(test,0x88,32);
AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(2,2047,0,test,32);
memset(test,0x55,32);
AT45DB041B_ContinuousArrayRead(2047,0,test,32);
while(1){}
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉