




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/*功能:实现存储器EEPROM AT45db081的数据读写操作,同时了解硬件spi读写操作作者:ZDP时间:2005-11-30版本:V1.0*/#include #include #include unsigned int Count1msInc;unsigned int AT450XXPageAddr;void SYSCLK_Init (void);void PORT_Init (void);void SPI0_Init (void);void Timer0_Init (void);#define SYSCLK 11059200#define DF_RESET P4&=0x10; P4|=0x10; / AT45DB081复位#define DF_RDY_BUSY P4|=0x20; while(!(P4&0x20); / 等待AT45DB081准备好#define DF_CHIP_SELECT P4&=0x4; / AT45DB081片选开#define DF_CHIP_NOSELECT P4|=0x4; / AT45DB081片选关#define RAM_CHIP_SELECT_BANK0 ES0=1;P4 = 0xF4; #define RAM_CHIP_SELECT_BANK1 P4 = 0xF5; #define BUFFER_1 0x00 / buffer 1#define BUFFER_2 0x01 / buffer 2#define BUFFER_1_WRITE 0x84 / buffer 1 write#define BUFFER_2_WRITE 0x87 / buffer 2 write#define BUFFER_1_READ 0x54 / buffer 1 read (change to 0xD4 for SPI mode 0,3)#define BUFFER_2_READ 0x56 / buffer 2 read (change to 0xD6 for SPI mode 0,3)#define B1_TO_PAGE_WITH_ERASE 0x83 / buffer 1 to main memory page program with built-in erase#define B2_TO_PAGE_WITH_ERASE 0x86 / buffer 2 to main memory page program with built-in erase#define B1_TO_PAGE_WITHOUT_ERASE 0x88 / buffer 1 to main memory page program without built-in erase#define B2_TO_PAGE_WITHOUT_ERASE 0x89 / buffer 2 to main memory page program without built-in erase#define PAGE_PROG_THROUGH_B1 0x82 / main memory page program through buffer 1#define PAGE_PROG_THROUGH_B2 0x85 / main memory page program through buffer 2#define AUTO_PAGE_REWRITE_THROUGH_B1 0x58 / auto page rewrite through buffer 1#define AUTO_PAGE_REWRITE_THROUGH_B2 0x59 / auto page rewrite through buffer 2#define PAGE_TO_B1_COMP 0x60 / main memory page compare to buffer 1#define PAGE_TO_B2_COMP 0x61 / main memory page compare to buffer 2#define PAGE_TO_B1_XFER 0x53 / main memory page to buffer 1 transfer#define PAGE_TO_B2_XFER 0x55 / main memory page to buffer 2 transfer#define STATUS_REGISTER 0x57#define MAIN_MEMORY_PAGE_READ 0x52 / main memory page read (change to 0xD2 for SPI mode 0,3)void SendSPIByte(unsigned char ch) SPIF = 0; SPI0DAT = ch; while (SPIF = 0); / 等待写结束 unsigned char GetSPIByte(void) SPIF = 0; SPI0DAT = 0; while (SPIF = 0); return SPI0DAT; / 等待读结束/启用缓存1读void FlashBuffer1Read(unsigned int star_addr,unsigned int len, unsigned char *buffer) /从缓冲区1的指定位置(0-263)中读入指定字节 unsigned int i; DF_RDY_BUSY;/测芯片准备好? DF_CHIP_SELECT;/芯片选择 SendSPIByte(BUFFER_1_READ); /缓冲区1为54H SendSPIByte(0); SendSPIByte(unsigned char)(star_addr8); SendSPIByte(unsigned char)star_addr); SendSPIByte(0); for (i=0;i8); SendSPIByte(unsigned char)star_addr); SendSPIByte(0);for (i=0;i8); SendSPIByte(unsigned char)start_addr); for (i=0;i8); SendSPIByte(unsigned char)start_addr); for (i=0;i 7); SendSPIByte(unsigned char)(AT450XXPageAddr 7); SendSPIByte(unsigned char)(AT450XXPageAddr 7); SendSPIByte(unsigned char)(AT450XXPageAddr 7); SendSPIByte(unsigned char)(AT450XXPageAddr 7); SendSPIByte(unsigned char)(AT450XXPageAddr 7); SendSPIByte(unsigned char)(AT450XXPageAddr 7); SendSPIByte(unsigned char)(AT450XXPageAddr 8); SendSPIByte(unsigned char)start_addr); for (i=0;i 7); SendSPIByte(unsigned char)(AT450XXPageAddr 8); SendSPIByte(unsigned char)start_addr); for (i=0;i 7); SendSPIByte(unsigned char)(AT450XXPageAddr 8); SendSPIByte(unsigned char)start_addr); for (i=0;i 7); SendSPIByte(unsigned char)(AT450XXPageAddr 8); SendSPIByte(unsigned char)start_addr); for (i=0;ilen;i+) SendSPIByte(buffer); DF_CHIP_NOSELECT;void main (void) unsigned char xdata MyBuff270;unsigned char xdata MyBuff1270;unsigned char xdata *idata MyBuff11;unsigned int i,j;WDTCN = 0xde; / disable watchdog timerWDTCN = 0xad;SYSCLK_Init (); / initialize oscillatorTimer0_Init();PORT_Init (); / initialize crossbar and GPIOEA=1;DF_RESET;SPI0_Init (); / initialize SPI0/ RAM_CHIP_SELECT_BANK0;/ EMI0CF = 0x2F;/*-缓存读写测试-*/for(j=0;j264;j+) /初始化数组数据为:0-264 MyBuffj=j; FlashBuffer1Write(0,264,MyBuff); /写数据至数据缓存区1_nop_();for(j=0;j264;j+) /初始化数组数据全为:0 MyBuffj=0;FlashBuffer1Read(0,264,MyBuff); /读数据缓存区1数据至数组_nop_();/*-FLASH读写测试-*/for(i=0;i8; MyBuff1=i; /将页地址写入数组的前两个字节.for(j=2;j264;j+) MyBuffj=i; /向数组写数据共262个字节 AT450XXPageAddr=i; /指定待写页 FlashBuffer1Write(0,264,MyBuff);/将数组的内容写入缓存1 FlashBuffer1ProgAutoErase(); /将缓存的内容写入主存(带擦除) _nop_();for(i=0;i4096;i+) AT450XXPageAddr=i; /指定待读页 MyBuff11=0x0+i*264; /指定数据放置的XRAM的地址(首地址为0x0). PageToBuffer2(); /将主存内容读入缓存2 FlashBuffer2Read(0,264,MyBuff11); /将缓存2的内容读入XRAM _nop_(); /在此设断点观察XRAM中的数据是否与写入的数据相符._nop_(); /同时在此设一断点在全部读完主存后观察XRAM中的内容./*-其它测试-*/AT450XXPageAddr=0;FlashBuffer1Write(20,14,1234567890UUAA);FlashBuffer1Read(0,260,MyBuff1);FlashBuffer1Write(20,14,3234567890UUAA);FlashBuffer1Read(20,14,MyBuff); /在此处设置断点,观察MyBuff的内容FlashBuffer1ProgNoErase();PageToBuffer2();FlashBuffer2Read(20,14,MyBuff); Count1msInc=0;FlashBuffer2Read(100,14,MyBuff);Count1msInc=0;FlashBuffer1Write(20,14,1234567890UUAA);Count1msInc=0;FlashBuffer1Read(100,14,MyBuff);Count1msInc=0;FlashBuffer1ProgNoErase(); Count1msInc=0;PageToBuffer2();Count1msInc=0;FlashBuffer2Read(100,14,MyBuff);FlashProgViaBuffer1(100,14,MyBuff);/ErasingDataFlash();/EraseFlashPage(); FlashBuffer1Read(1,1, MyBuff); /从缓冲区1的指定位置(0-263)中读入指定字节FlashBuffer2Read(1,1,MyBuff); /从缓冲区2的指定位置(0-263)中读入指定字节FlashBuffer1Write(1,1,!);FlashBuffer2Write(1,1,1);GetFlashStatus();PageToBuffer1();PageToBuffer2();FlashBuffer1ProgNoErase();FlashBuffer2ProgNoErase();FlashBuffer1ProgAutoErase();FlashBuffer2ProgAutoErase();FlashProgViaBuffer1(1,1, MyBuff);FlashProgViaBuffer2(1,1, MyBuff);FlashAutoProgViaBuffer1(1,1, MyBuff);FlashAutoProgViaBuffer2(1,1, MyBuff);while(1);void SYSCLK_Init (void) int i; / delay counter OSCXCN = 0x67; / start external oscillator with / 11.0592MHz crystal for (i=0; i 256; i+) ; / Wait for osc. to start up while (!(OSCXCN & 0x80) ; / Wait for crystal osc. to settle OSCICN = 0x88; / select external
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 园艺主题酒店创新创业项目商业计划书
- 农产品期货交易咨询创新创业项目商业计划书
- 动物皮毛艺术品制作创新创业项目商业计划书
- 农产鲜品乐创新创业项目商业计划书
- 现场急救知识培训包扎课件
- 2025年教育行业数字化教材开发与多语言支持策略研究
- 2025年新能源汽车废旧电池回收利用产业链技术创新与产业竞争力研究报告
- 2025年城市轨道交通智慧运维系统在智慧城市建设中的关键作用报告
- 河南省三门峡市陕州区2022-2023学年大象版五年级上学期科学期中考试试题(含答案)
- 2026届云南省永德县第一中学化学高一第一学期期末学业质量监测模拟试题含解析
- 社区公共卫生护理考核试卷
- 现代海洋管理 知到智慧树网课答案
- 新疆维吾尔自治区五大名校2024年高考化学必刷试卷含解析
- GB/T 43680-2024生态系统评估陆地生态退化评估方法
- 应急救援基础知识
- 无人机实训室建设方案
- TGSC 006-2024 二氧化碳陆地封存工程选址指南
- 销售目标达成计划
- 食材验收标准培训课件
- 畜禽养殖知识讲座
- 高速公路收费员培训课件
评论
0/150
提交评论