下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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
7、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 at45db
8、041b_continuousarrayread(uint pa,uint bfa,unsigned char *pheader,uint len) unsigned int i=0; while(i+7); spi_hostwritebyte(unsigned char)(pa8); spi_hostwritebyte(unsigned char)bfa); for(i=0;i4;i+)spi_hostwritebyte(0x00); for(i=0;ilen;i+)pheaderi=spi_hostreadbyte(); spi_cs=1; /*/ /*描述: */ /* 将指定数据写入从
9、某个地址(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 in
10、t i; while(i+8); spi_hostwritebyte(unsigned char)bfa); for(i=0;ilen;i+)spi_hostwritebyte(pheaderi); spi_cs=1; void memorytobuffer(unsigned int maddr)unsigned int i;while(i+7); spi_hostwritebyte(unsigned char)(maddr1);spi_hostwritebyte(0x0); spi_cs=1; ./*/ /*描述: */ /* 将指定数据写入从某个地址(0263)开始的页中:包含2个动作,首
11、先将指定数据*/ /* 写入到buffer 1或者buffer 2中,其中可以指定buffer中的起始写入地址,此写入*/ /* 动作不影响buffer中其它地址中的数据,然后再将buffer中的整个数据写入到某指*/ /* 定页中(带预擦除)。 */ /*参数: */ /* buffer - 选择buffer,01h选择buffer 1,02h选择buffer 2 */ /* pa - 页地址,02047 */ /* bfa - 指定buffer中的起始写入地址 */ /* pheader - 指定数据的首地址 */ /* len - 指定数据的长度 */ /*/ void at45db04
12、1b_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+7); spi_hostwritebyte(unsigned char)(pa1); 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; mems
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025湖南长沙浏阳市人民医院公开招聘编外合同制人员8人备考笔试题库及答案解析
- 深度解析(2026)《GBT 25987-2010装甲防暴车》(2026年)深度解析
- 深度解析(2026)《GBT 25931-2010网络测量和控制系统的精确时钟同步协议》
- 福建漳州市2026届国企类选优生招聘(第四批)开考岗位参考考试题库及答案解析
- 2025广西百色市乐业县专业森林消防救援队伍招聘13人备考笔试试题及答案解析
- 2025重庆广播新闻中心政务服务团队人员招聘9人参考考试题库及答案解析
- 深度解析(2026)GBT 25691-2010《土方机械 开斗式铲运机 容量标定》
- 深度解析(2026)《GBT 25656-2010信息技术 中文Linux应用编程界面(API)规范》(2026年)深度解析
- 2025西安交通大学第一附属医院医学影像科招聘劳务派遣助理护士参考考试试题及答案解析
- 共享经济合同纠纷与法律规制研究-基于网约车平台与驾驶员的劳动关系认定
- 2025年烟花爆竹经营单位安全管理人员考试试题及答案
- 2025天津大学管理岗位集中招聘15人参考笔试试题及答案解析
- 2025广东广州黄埔区第二次招聘社区专职工作人员50人考试笔试备考题库及答案解析
- 2025年云南省人民检察院聘用制书记员招聘(22人)考试笔试参考题库及答案解析
- 2026届上海市青浦区高三一模数学试卷和答案
- 2026年重庆安全技术职业学院单招职业技能测试题库附答案
- 环卫设施设备采购项目投标方案投标文件(技术方案)
- 微创机器人手术基层普及路径
- 24- 解析:吉林省长春市2024届高三一模历史试题(解析版)
- 2025年黑龙江省公务员《申论(行政执法)》试题含答案
- 福建省福州市仓山区2024-2025学年三年级上学期期末数学试题
评论
0/150
提交评论