资源预览内容
第1页 / 共31页
第2页 / 共31页
第3页 / 共31页
第4页 / 共31页
第5页 / 共31页
第6页 / 共31页
第7页 / 共31页
第8页 / 共31页
第9页 / 共31页
第10页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
/mian.c/#include config.hxdata FILE TmpFile ;void main()UINT32 lba = 0;UINT16 i;UartInit(); /初始化串口UartSendStr(*rn);UartSendStr(*rn);UartSendStr(*rn);UartSendStr(*51MP3播放器演示程序*rn);UartSendStr(*rn);UartSendStr(*rn);UartSendStr(*rn);UartSendStr(*rn);UartSendStr(初始化SPI接口rn);InitSPI(); /初始化SPI接口UartSendStr(初始化VS1003rn);RstVs1003();UartSendStr(正弦测试rn);/Sintest();DelayMs(300);UartSendStr(退出正弦测试rn);SoftRstVs1003();UartSendStr(初始化CH375rn);InitCH375();/初始化液晶LCD_Init();/显示logoLCD_SET_CURSOR(1,1); Print( mp3 player ,16);LCD_SET_CURSOR(2,1); Print( stuelab ,16);SPI_HIGH_SPEED(); /高速SPI接口UartSendStr(初始化文件系统rn);InitFat (SectorBuf);UartSendStr(统计文件信息rn);i = StatFileNum(2, MP3, SectorBuf);sprintf(SectorBuf,根目录下MP3文件个数为%d .rn,i);UartSendStr(SectorBuf);i = StatFileNum(2, WMA, SectorBuf);sprintf(SectorBuf,根目录下WMA文件个数为%d .rn,i);UartSendStr(SectorBuf);i = StatFileNum(2, , SectorBuf);sprintf(SectorBuf,根目录下文件夹个数为%d .rn,i);UartSendStr(SectorBuf);UartSendStr(查找根目录下第一个MP3文件rn);SearchFile(2, 1, MP3, SectorBuf, &TmpFile);UartSendStr(rn开始播放rn);/UartSendStr(TmpFile.short_name);lba = ClusToLba(TmpFile.start_clus);while (1)RdSDblock(lba+,SectorBuf);PlaySector();/spi.c/#include config.h sbit SCK = P17; sbit SO = P15;sbit SI = P16;void InitSPI (void)SCK = 1;SO = 1;SI = 1;SPCR = 0xdc+3; /主机模式,允许中断,时钟常高,4分频ES = 0;/串口中断允许。SPI和UART共用同一个中断。EA = 0; /中断总控位void SPIsendByte (unsigned char dat)SDAT = dat;while (!(SPSR & 0x80); /等待发送完毕SPSR = 0; /清除中断标志unsigned char SPIrecvByte (void) unsigned char dat ;SDAT = 0XFF;while (!(SPSR & 0x80); /等待发送完毕SPSR = 0; /清除中断标志dat = SDAT; /发送的过程中同时完成接收return dat ;/return SDAT;void SPIsendByte2(unsigned char temp) /软件模拟SPI发送接口char i;for (i = 0; i 8; i+) SCK = 0 ;SO = (bit)(temp&0x80) ;SCK = 1 ;temp = 1;SO = 1 ;/*unsigned SPIrecvByte2(void) /软件模拟SPI接收接口char i ;unsigned char temp;for(i = 0; i 8; i+) temp 0; tmp-);void DelayUs(UINT16 ticks)while (ticks-);#include config.h vs1003.cchar tmp; void SoftWrVs1003Cmd(unsigned char addr,unsigned int cmd)SPCR = 0;/关闭SPI/SCK = 1; /SO = 1;/SI = 1;WaitVs1003();SelectCmdVs1003(); /片选DelayUs(5);SPIsendByte2(0x02);SPIsendByte2(addr);SPIsendByte2(unsigned char)(cmd8);SPIsendByte2(unsigned char)cmd);DelayUs(5);ReleaseCmdVs1003(); /释放SPCR = 0xdf; /打开SPIvoid WrVs1003Cmd (unsigned char addr,unsigned int cmd)WaitVs1003();SelectCmdVs1003(); /片选DelayUs(5);SPIsendByte(0x02);SPIsendByte(addr);SPIsendByte(unsigned char)(cmd8);SPIsendByte(unsigned char)cmd);DelayUs(5);ReleaseCmdVs1003(); /释放void SoftRstVs1003(void)/WrVs1003Cmd(0,0x0804); /具体功能见官方数据手册第28页(软件复位)SoftWrVs1003Cmd(0,0x0804);DelayMs(10);SoftWrVs1003Cmd(2,0x00f6); /低音DelayMs(1);SoftWrVs1003Cmd(3,0x9800); /倍频DelayMs(10);SoftWrVs1003Cmd(5,0xbb81); /采样率和通道数DelayMs(1);SoftWrVs1003Cmd(0x0b,0x2020); /音量DelayMs(1);void RstVs1003(void)SelectRstVs1003(); /硬件复位DelayMs(10);SPIsendByte(0xff);ReleaseRstVs1003(); DelayMs(10);WrVs1003Cmd(0x0b,0xffff); /音量DelayMs(1);SoftRstVs1003();/*void Sintest(void)WrVs1003Cmd(0,0x0820); /进入正弦测试WaitVs1003();SelectDatVs1003();DelayUs(5);SPIsendByte(0x53);SPIsendByte(0xef);SPIsendByte(0x6e);SPIsendByte(0x30);SPIsendByte(0);SPIsendByte(0);SPIsendByte(0);SPIsendByte(0);DelayUs(5);ReleaseDatVs1003();*/void PlaySector(void)UINT16 i ;SelectDatVs1003();for (i=0; i512;) /连续发32个字节(VS1003有32字节的缓冲区)WaitVs1003(); / 查忙 SPIsendByte(SectorBufi+);
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号