#include "vs1003.h" #include "myfun.h" #include "uart.h" #include "iospi.h" #include "tft.h" #include "znfat/znfat.h" unsigned int idata i=0,j=0,res=0,color=0,n=0,len=0,pos=0,old_pos=-1; unsigned long idata c=0; unsigned int vol_val=0; struct znFAT_Init_Args idata Init_Args; //初始化参数集合 struct FileInfo idata fileinfo; unsigned char buf[800]; sbit KEY_PRE=P1^7; sbit KEY_NEX=P1^6; sbit KEY_VUP=P1^3; sbit KEY_VDN=P1^4; sbit KEY_PAU=P1^5; #define COLOR(r,g,b) (((((((unsigned int)r)>>3)<<6) |(((unsigned int)g)>>2))<<5)|(((unsigned int)b)>>3)) //r红色分量 0~31 g绿色分量 0~63 b蓝色分量 0~31 void main() { UART_Init(); VS_Reset();//初始化VS1003 VS_sin_test(100); //正弦测试 TFT_Init(); TFT_Clear(0xffff); LoadPatch(); //为VS1003打补丁 znFAT_Device_Init(); //存储设备初始化 UART_Send_Str("SD卡初始化完毕\r\n"); znFAT_Select_Device(0,&Init_Args); //选择设备 res=znFAT_Init(); //文件系统初始化 if(!res) //文件系统初始化成功 { UART_Send_Str("Suc. to init FS\r\n"); UART_Put_Inf("BPB_Sector_No:",Init_Args.BPB_Sector_No); UART_Put_Inf("Total_SizeKB:",Init_Args.Total_SizeKB); UART_Put_Inf("BytesPerSector:",Init_Args.BytesPerSector); UART_Put_Inf("FATsectors:",Init_Args.FATsectors); UART_Put_Inf("SectorsPerClust:",Init_Args.SectorsPerClust); UART_Put_Inf("FirstFATSector:",Init_Args.FirstFATSector); UART_Put_Inf("FirstDirSector:",Init_Args.FirstDirSector); UART_Put_Inf("FSsec:",Init_Args.FSINFO_Sec); UART_Put_Inf("Next_Free_Cluster:",Init_Args.Next_Free_Cluster); UART_Put_Inf("FreenCluster:",Init_Args.Free_nCluster); } else //文件系统初始化失败 { UART_Put_Inf("Fail to init FS, Err Code:",res); while(1); //如果初始化失败,则死在这里 } res=znFAT_Open_File(&fileinfo,"/znmcu.bmp",0,1); //打开文件 if(!res) { UART_Send_Str("Suc. to open file \r\n"); UART_Send_Str("================================\n"); UART_Send_Str("File_Name:"); UART_Send_Str(fileinfo.File_Name);UART_Send_Enter(); UART_Put_Inf("File_Size:",fileinfo.File_Size); UART_Send_Str("File_CDate:"); UART_Put_Num(fileinfo.File_CDate.year); UART_Send_Str("年"); UART_Put_Num(fileinfo.File_CDate.month);UART_Send_Str("月"); UART_Put_Num(fileinfo.File_CDate.day); UART_Send_Str("日"); UART_Put_Num(fileinfo.File_CTime.hour); UART_Send_Str("时"); UART_Put_Num(fileinfo.File_CTime.min); UART_Send_Str("分"); UART_Put_Num(fileinfo.File_CTime.sec); UART_Send_Str("秒\r\n"); UART_Put_Inf("File_StartClust:",fileinfo.File_StartClust); UART_Put_Inf("File_CurClust:",fileinfo.File_CurClust); UART_Put_Inf("File_CurSec:",fileinfo.File_CurSec); UART_Put_Inf("File_CurPos:",fileinfo.File_CurPos); UART_Put_Inf("File_CurOffset:",fileinfo.File_CurOffset); UART_Send_Str("================================\n"); znFAT_ReadData(&fileinfo,0,54,buf); for(i=0;i<320;i++) { znFAT_ReadData(&fileinfo,fileinfo.File_CurOffset,720,buf); for(j=0;j<240;j++) { color=COLOR(buf[j*3+2],buf[j*3+1],buf[j*3+1]); TFT_Write_Data8(color>>8,color); } } } else { UART_Send_Str("fail to open file \r\n"); } //====================================================================== while(!znFAT_Open_File(&fileinfo,"/*.mp3",n++,1)) { TFT_PutString(0,1," "); TFT_PutString(0,3," "); TFT_PutString(0,1,fileinfo.File_Name); TFT_PutNum(0,3,fileinfo.File_Size); while(len=znFAT_ReadData(&fileinfo,fileinfo.File_CurOffset,800,buf)) { pos=fileinfo.File_CurOffset*10/fileinfo.File_Size; if(pos!=old_pos) {TFT_Draw_proBar(pos,0xf800);old_pos=pos;} VS_XDCS=0; //打开SDI,此时可以向VS1003写入音频数据 len/=32; for(i=0;i<len;i++) { VS_DREQ=1; while(!VS_DREQ); //VS1003的DREQ为高才能写入数据 for(j=0;j<32;j++) IOSPI_WriteByte(buf[i*32+j]); } VS_XDCS=1; //关闭SDI VS_Write_Reg(VS_WRAMADDR,0x18,0x04); //启动频谱数据传输 TFT_Clear_Half(0xffff); for(j=0;j<10;j++) //读取14个频谱值(VS1003输出14个频段的频) { TFT_Draw_Bar(9-j,VS_Read_Reg(VS_WRAM)/600,0x001f); } KEY_PRE=1; if(KEY_PRE==0) { delay(100); if(KEY_PRE==0) {if(n>1) n-=2; else n=0; break;} } KEY_NEX=1; if(KEY_NEX==0) { delay(100); if(KEY_NEX==0) {break;} } KEY_VUP=1; if(KEY_VUP==0) { delay(100); if(KEY_VUP==0) { VS_Write_Reg(VS_VOL,vol_val?vol_val-10:0,vol_val?vol_val-10:0) ;vol_val?vol_val-=10:vol_val;} } KEY_VDN=1; if(KEY_VDN==0) { delay(100); if(KEY_VDN==0) {VS_Write_Reg(VS_VOL ,vol_val+10,vol_val+10);vol_val+=10;} } KEY_PAU=1; if(KEY_PAU==0) { delay(100); if(KEY_PAU==0) { while(!KEY_PAU); while(KEY_PAU); } } } for(i=0;i<10;i++) TFT_Draw_proBar(i,0xffff); pos=0;old_pos=-1; VS_Flush_Buffer();//清空VS1003的数据缓冲区,此函数中最后将VS_XDCS置高,即关闭SDI } znFAT_Flush_FS(); //刷新文件系统 while(1); } |