欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOC文档下载  

    AT45DB041存储芯片读写程序,适用于51单片机.doc

    • 资源ID:4146314       资源大小:31KB        全文页数:6页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    AT45DB041存储芯片读写程序,适用于51单片机.doc

    /*这个程序原本是从论坛上下载的,但是用到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 falling edge of SCK.All instruction-*/ /* s,addresses and data are transferred with the most significant bit(MSB) */ /* first. */ /* 2005-06-02*/ /*/ #include <reg52.h> #include <string.h> #include <intrins.h> #include <main.h>#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;i<30;i+) i+;unsigned char SPI_HostReadByte(void) unsigned char i,rByte=0; for(i=0;i<8;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;i<8;i+) if(wByte<<i)&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 | 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 - 这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. */ /*参数: */ /* PA - 页地址,02047 */ /* BFA - 指定BUFFER中的起始写入地址 */ /* pHeader - 指定数据的首地址 */ /* len - 指定数据的长度 */ /*/ void AT45DB041B_ContinuousArrayRead(UINT PA,UINT BFA,unsigned char *pHeader,UINT len) unsigned int i=0; while(i+<555)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+)pHeaderi=SPI_HostReadByte(); SPI_CS=1; /*/ /*描述: */ /* 将指定数据写入从某个地址(0263)开始的BUFFER中。 */ /*参数: */ /* buffer - 选择BUFFER,01H选择BUFFER 1,02H选择BUFFER 2 */ /* 在该指令序列中,操作码84H选择BUFFER 1,87H选择BUFFER 2 */ /* BFA - BUFFER中的起始地址,0263 */ /* pHeader - 待存数据的头指针 */ /* len - 待存数据的长度1264 */ /*/ void AT45DB041B_BufferWrite(UCHAR buffer,UINT BFA,UCHAR *pHeader,UINT len) unsigned int i; while(i+<555)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(pHeaderi); SPI_CS=1; void memorytobuffer(unsigned int maddr)unsigned int i;while(i+<2000)if(AT45DB041B_StatusRegisterRead()&0x80)break; SPI_CS=0;SPI_HostWriteByte(0x53); SPI_HostWriteByte(unsigned char)(maddr>>7); SPI_HostWriteByte(unsigned char)(maddr<<1);SPI_HostWriteByte(0x0); SPI_CS=1; ./*/ /*描述: */ /* 将指定数据写入从某个地址(0263)开始的页中:包含2个动作,首先将指定数据*/ /* 写入到BUFFER 1或者BUFFER 2中,其中可以指定BUFFER中的起始写入地址,此写入*/ /* 动作不影响BUFFER中其它地址中的数据,然后再将BUFFER中的整个数据写入到某指*/ /* 定页中(带预擦除)。 */ /*参数: */ /* buffer - 选择BUFFER,01H选择BUFFER 1,02H选择BUFFER 2 */ /* PA - 页地址,02047 */ /* BFA - 指定BUFFER中的起始写入地址 */ /* pHeader - 指定数据的首地址 */ /* len - 指定数据的长度 */ /*/ 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+<2000)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; 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; memset(test,0x88,32); AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(1,100,0,test,32); memset(test,0x55,32); AT45DB041B_ContinuousArrayRead(100,0,test,32); buf30=test1;while(1);/也可以在while(1)中调用读写

    注意事项

    本文(AT45DB041存储芯片读写程序,适用于51单片机.doc)为本站会员(仙人指路1688)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开