【转载】AT45D081/AT45DB021/AT45DB0xx驱动程序(C语言)用于大型
AT45D081/AT45DB021/AT45DB0xx驱动程序(C语言)用于大型存储的串行Flash
delay(unsigned int t) // SPI_SK上升沿数据有效 _/-SPI45D081_WriteBits(unsigned char byte,unsigned char num_of_bits){unsigned char count;byte=byte<<(8-num_of_bits);for(count=0;count<num_of_bits;count++){ SPI45D081_SK=0;byte<<=1;NOP();SPI45D081_DI=CY;NOP();SPI45D081_SK=1;NOP();}}// SPI_SK下降沿数据有效 -_unsigned char SPI45D081_ReadByte(){unsigned char count,byte;for(count=0;count<8;count++){ SPI45D081_SK=1;NOP();byte<<=1;SPI45D081_SK=0;NOP();if(SPI45D081_DO) byte++;NOP();}return(byte);}//Main Memory Page to Buffer 1 Transfervoid PageToBuffer1(unsigned int page){SPI45D081_SK=1; //?? startNOP();SPI45D081_CS=0; //startNOP();//send 8 bit opcode,Main Memory Page to Buffer 1 Transfer: 0x53SPI45D081_WriteBits(0x53,8);// fill 3 sk,don't care.SPI45D081_WriteBits(0x00,3);//send 12 bit address to 45D081SPI45D081_WriteBits( (unsigned char)(page>>8),4 );SPI45D081_WriteBits( (unsigned char)(page),8 );// fill 9 sk,don't care.SPI45D081_WriteBits( 0x00,4 );SPI45D081_WriteBits( 0x00,5 );//total 32 bitSPI45D081_CS=1; // enddelay(200);}//unsigned char ReadDataFromBuffer1(unsigned int address){unsigned char dat; SPI45D081_SK=1; //?? startNOP();SPI45D081_CS=0; //startNOP();//send 8 bit opcode:0x54SPI45D081_WriteBits(0x54,8);// fill 15 sk,8);SPI45D081_WriteBits(0x00,7);//send 9 bit address to 45D081 buffer1SPI45D081_WriteBits( (unsigned char)(address>>8),1 );SPI45D081_WriteBits( (unsigned char)(address),8 );//fill 8 bits blankSPI45D081_WriteBits( 0x00,8 );// receive datadat=SPI45D081_ReadByte() ;SPI45D081_CS=1; // endreturn(dat);}//注:该程序适用程度可靠,注意使用的方法和硬件连接方式 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |