AT45DB041存储芯片读写程序,适用于51单片机.doc
《AT45DB041存储芯片读写程序,适用于51单片机.doc》由会员分享,可在线阅读,更多相关《AT45DB041存储芯片读写程序,适用于51单片机.doc(6页珍藏版)》请在三一办公上搜索。
1、/*这个程序原本是从论坛上下载的,但是用到51单片机中不能使用,只能一次写一个字节,经过高手的修改,已经能够用在51中。2011.07.27*/*/ /*正常操作电压为2.73.6V,实验中发现当电压超过4.25V后读出的状态字节为9A(正常 */ /*的状态字节值为9D),并且读写数据均不准确,所以应当保证卡片的供电电压不超过 */ /*4.25V。 */ /*SPI规范:Data is always clocked into the device on the rising edge of SCK a-*/ /* nd clocked out of the device on the fa
2、lling edge of SCK.All instruction-*/ /* s,addresses and data are transferred with the most significant bit(MSB) */ /* first. */ /* 2005-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
3、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_HostWriteB
4、yte(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| COMP | 0 | 1 | 1 |
5、 1 | X | X | */ /* - */ /* bit7 - 忙标记,0为忙1为不忙。 */ /* 当Status Register的位0移出之后,接下来的时钟脉冲序列将使SPI器件继续*/ /* 将最新的状态字节送出。 */ /* bit6 - 标记最近一次Main Memory Page和Buffer的比较结果,0相同,1不同。 */ /* bit5 */ /* bit4 */ /* bit3 */ /* bit2 - 这4位用来标记器件密度,对于AT45DB041B,这4位应该是0111,一共能标记 */ /* 16种不同密度的器件。 */ /* bit1 */ /* bit0 -
6、 这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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- AT45DB041 存储 芯片 读写 程序 适用于 51 单片机
![提示](https://www.31ppt.com/images/bang_tan.gif)
链接地址:https://www.31ppt.com/p-4146314.html