资源描述:
《单片机原理图程序.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、//mian.c///////////////////////#include"config.h"xdataFILETmpFile;voidmain(){UINT32lba=0;UINT16i;UartInit();//初始化串口UartSendStr("**************************************r");UartSendStr("**************************************r");UartSendStr("**********
2、****************************r");UartSendStr("*********51MP3播放器演示程序**********r");UartSendStr("**************************************r");UartSendStr("**************************************r");UartSendStr("**************************************
3、r");UartSendStr("**************************************r");UartSendStr("初始化SPI接口r");InitSPI();//初始化SPI接口UartSendStr("初始化VS1003r");RstVs1003();UartSendStr("正弦测试r");//Sintest();DelayMs(300);UartSendStr("退出正弦测试r");SoftRstVs1003();UartSendSt
4、r("初始化CH375r");InitCH375();//初始化液晶LCD_Init();//显示logoLCD_SET_CURSOR(1,1);Print("mp3player",16);LCD_SET_CURSOR(2,1);Print("stuelab",16);SPI_HIGH_SPEED();//高速SPI接口UartSendStr("初始化文件系统r");InitFat(SectorBuf);UartSendStr("统计文件信息r");i=StatFileNum(2,"M
5、P3",SectorBuf);sprintf(SectorBuf,"根目录下MP3文件个数为%d.r",i);UartSendStr(SectorBuf);i=StatFileNum(2,"WMA",SectorBuf);sprintf(SectorBuf,"根目录下WMA文件个数为%d.r",i);UartSendStr(SectorBuf);i=StatFileNum(2,"",SectorBuf);sprintf(SectorBuf,"根目录下文件夹个数为%d.r",i);Uar
6、tSendStr(SectorBuf);UartSendStr("查找根目录下第一个MP3文件r");SearchFile(2,1,"MP3",SectorBuf,&TmpFile);UartSendStr("r开始播放r");//UartSendStr(TmpFile.short_name);lba=ClusToLba(TmpFile.start_clus);while(1){RdSDblock(lba++,SectorBuf);PlaySector();}}//spi.c/////
7、///#include"config.h"sbitSCK=P1^7;sbitSO=P1^5;sbitSI=P1^6;voidInitSPI(void){SCK=1;SO=1;SI=1;SPCR=0xdc+3;//主机模式,允许中断,时钟常高,4分频ES=0;//串口中断允许。SPI和UART共用同一个中断。EA=0;//中断总控位}voidSPIsendByte(unsignedchardat){SDAT=dat;while(!(SPSR&0x80));//等待发送完毕SPSR=0;//清除中断标志}u
8、nsignedcharSPIrecvByte(void){unsignedchardat;SDAT=0XFF;while(!(SPSR&0x80));//等待发送完毕SPSR=0;//清除中断标志dat=SDAT;//发送的过程中同时完成接收returndat;//returnSDAT;}voidSPIsendByte2(unsignedchartemp)//软件模拟SPI发送接口{chari;for(i=0;i<8;i++){SCK=0;