欢迎来到天天文库
浏览记录
ID:40542681
大小:76.00 KB
页数:10页
时间:2019-08-04
《AT45db081的spi读写程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/***************************************************************功能:实现存储器EEPROMAT45db081的数据读写操作,同时了解硬件spi读写操作作者:ZDP时间:2005-11-30版本:V1.0***************************************************************/#include#include#includeunsignedintCount1msInc;unsignedintAT45
2、0XXPageAddr;voidSYSCLK_Init(void);voidPORT_Init(void);voidSPI0_Init(void);voidTimer0_Init(void);#defineSYSCLK11059200#defineDF_RESETP4&=~0x10;P4
3、=0x10;//AT45DB081复位#defineDF_RDY_BUSYP4
4、=0x20;while(!(P4&0x20));//等待AT45DB081准备好#defineDF_CHIP_SELECTP4&=~0x4;//AT45DB081片选开#defineDF_CHIP_NOSELECTP
5、4
6、=0x4;//AT45DB081片选关#defineRAM_CHIP_SELECT_BANK0ES0=1;P4=0xF4;#defineRAM_CHIP_SELECT_BANK1P4=0xF5;#defineBUFFER_10x00//buffer1#defineBUFFER_20x01//buffer2#defineBUFFER_1_WRITE0x84//buffer1write#defineBUFFER_2_WRITE0x87//buffer2write#defineBUFFER_1_READ0x54//buffer1read(changeto0xD4forSPImode
7、0,3)#defineBUFFER_2_READ0x56//buffer2read(changeto0xD6forSPImode0,3)#defineB1_TO_PAGE_WITH_ERASE0x83//buffer1tomainmemorypageprogramwithbuilt-inerase#defineB2_TO_PAGE_WITH_ERASE0x86//buffer2tomainmemorypageprogramwithbuilt-inerase#defineB1_TO_PAGE_WITHOUT_ERASE0x88//buffer1tomainmemorypagepro
8、gramwithoutbuilt-inerase#defineB2_TO_PAGE_WITHOUT_ERASE0x89//buffer2tomainmemorypageprogramwithoutbuilt-inerase#definePAGE_PROG_THROUGH_B10x82//mainmemorypageprogramthroughbuffer1#definePAGE_PROG_THROUGH_B20x85//mainmemorypageprogramthroughbuffer2#defineAUTO_PAGE_REWRITE_THROUGH_B10x58//autop
9、agerewritethroughbuffer1#defineAUTO_PAGE_REWRITE_THROUGH_B20x59//autopagerewritethroughbuffer2#definePAGE_TO_B1_COMP0x60//mainmemorypagecomparetobuffer1#definePAGE_TO_B2_COMP0x61//mainmemorypagecomparetobuffer2#definePAGE_TO_B1_XFER0x53//mainmemorypagetobuffer1transfer#definePAGE_TO_B2_XFER0x
10、55//mainmemorypagetobuffer2transfer#defineSTATUS_REGISTER0x57#defineMAIN_MEMORY_PAGE_READ0x52//mainmemorypageread(changeto0xD2forSPImode0,3)voidSendSPIByte(unsignedcharch){SPIF=0;SPI0DAT=ch;while(SPIF==0);//等待写结束}unsignedcharGetSPIByte(void){
此文档下载收益归作者所有