欢迎来到天天文库
浏览记录
ID:12763415
大小:21.58 KB
页数:19页
时间:2018-07-18
《sd卡读写程序(sd card read and write program)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、sd卡读写程序(SDcardreadandwriteprogram)SDcardreadandwriteprogramObjective:TostudytheSDcard//operationDesign/software1,usingSPIcommunication//SDcard2,gotoSD//inorderto0-255atotalof256data,andthenreadbackLCD1602display//hardwarerequirements:S11ON//dialswitchJumperJ18//allconnected#include2、4.h>//dsPIC30F6014standardheaderfile_FOSC(CSW_FSCM_OFF&XT_PLL4);//4doublercrystaloscillator,Failsafeclockclosed_FWDT(WDT_OFF);//closethewatchdogtimer_FBORPOR(PBOR_OFF&MCLR_EN);//resetprohibitedMCLRresetenable._FGS(CODE_PROT_OFF);//codeprotectionagainst#defineCSPORTGbits.RG9//SDcardselectio3、npindefinition#defineRSLATBbits.LATB4//definitionLCDcontrolbits(noteherecanonlyregisterwithLATB,youcannotdirectlyusethePORTBregister)#defineRWLATBbits.LATB5#defineeLATBbits.LATB6Unsignedchar__attribute__((address(0x900)))lcd[3]={0,0,0};Void(spi_init);//declarationsysteminitialfunctionVoid(4、spi_low);//thatproduceslowbaudrate(usingtheSDcardinitializationfunction)Void(spi_high);//thatproducehighbaudratefunction(SDcardinitializationafteruse)Unsignedchar(sd_reset);//thattheSDcardinitializationfunctionUnsignedcharSD_SendCommand(unsignedcharCMDunsigned,longARG);//writeSDcardcommand5、functionstatementUnsignedcharSPI_WriteByte(unsignedcharVAL);//writeabytefunctionstatementUnsignedcharSPI_ReadByte(void);//thatreceiveabytefunctionUnsignedcharSD_WriteSingleBlock(unsignedlongsector);//thatsingleBLOCKdatawriteSDcardfunctionUnsignedcharSD_ReadSingleBlock(unsignedlongsector);/6、/readSDcarddatafunctionsingleBLOCKstatementVoid(lcd_display);//stateresultsdisplayfunctionVoid(delay);//statedelayfunction(shownby)//systeminitializationfunctionVoidspi_init(){TRISG=0x00d0;//settheSDIoutput,CoutputportfortheotherTRISB=0X0000;//setfortheoutputportBTRISD=0X0000;//setfortheou7、tputportDSPI2CON=0x0278;//idlebusishigh,fosc/64SPI2STAT=0x8000;//theendofsamplingtheoutputdataofinputdata,therisingedgeofdatatransmission}WriteaLCDprogram****************************************//*************************//writeabyteofdatafunctionAfterchanging
2、4.h>//dsPIC30F6014standardheaderfile_FOSC(CSW_FSCM_OFF&XT_PLL4);//4doublercrystaloscillator,Failsafeclockclosed_FWDT(WDT_OFF);//closethewatchdogtimer_FBORPOR(PBOR_OFF&MCLR_EN);//resetprohibitedMCLRresetenable._FGS(CODE_PROT_OFF);//codeprotectionagainst#defineCSPORTGbits.RG9//SDcardselectio
3、npindefinition#defineRSLATBbits.LATB4//definitionLCDcontrolbits(noteherecanonlyregisterwithLATB,youcannotdirectlyusethePORTBregister)#defineRWLATBbits.LATB5#defineeLATBbits.LATB6Unsignedchar__attribute__((address(0x900)))lcd[3]={0,0,0};Void(spi_init);//declarationsysteminitialfunctionVoid(
4、spi_low);//thatproduceslowbaudrate(usingtheSDcardinitializationfunction)Void(spi_high);//thatproducehighbaudratefunction(SDcardinitializationafteruse)Unsignedchar(sd_reset);//thattheSDcardinitializationfunctionUnsignedcharSD_SendCommand(unsignedcharCMDunsigned,longARG);//writeSDcardcommand
5、functionstatementUnsignedcharSPI_WriteByte(unsignedcharVAL);//writeabytefunctionstatementUnsignedcharSPI_ReadByte(void);//thatreceiveabytefunctionUnsignedcharSD_WriteSingleBlock(unsignedlongsector);//thatsingleBLOCKdatawriteSDcardfunctionUnsignedcharSD_ReadSingleBlock(unsignedlongsector);/
6、/readSDcarddatafunctionsingleBLOCKstatementVoid(lcd_display);//stateresultsdisplayfunctionVoid(delay);//statedelayfunction(shownby)//systeminitializationfunctionVoidspi_init(){TRISG=0x00d0;//settheSDIoutput,CoutputportfortheotherTRISB=0X0000;//setfortheoutputportBTRISD=0X0000;//setfortheou
7、tputportDSPI2CON=0x0278;//idlebusishigh,fosc/64SPI2STAT=0x8000;//theendofsamplingtheoutputdataofinputdata,therisingedgeofdatatransmission}WriteaLCDprogram****************************************//*************************//writeabyteofdatafunctionAfterchanging
此文档下载收益归作者所有