我不在audio_play(void)函数里用可以实现/读取指定区域背景 {MOD}和恢复指定区域背景 {MOD},但是在audio_play(void)里面就会报错,说的是“”MUSIC文件夹错误“”,不加这两函数的时候单独运行是可以正常播放的,
void app_read_bkcolor(u16 x,u16 y,u16 width,u16 height,u16 *ctbl)//读取指定区域背景 {MOD}
{
u32 x0,y0,ccnt;
ccnt=0;
for(y0=y;y0<y+height;y0++)
{
for(x0=x;x0<x+width;x0++)
{
ctbl[ccnt]=LCD_ReadPoint(x0,y0);
ccnt++;
}
}
}
void app_recover_bkcolor(u16 x,u16 y,u16 width,u16 height,u16 *ctbl)//恢复指定区域背景 {MOD}
{
u32 x0,y0,ccnt;
ccnt=0;
for(y0=y;y0<y+height;y0++)
{
for(x0=x;x0<x+width;x0++)
{
LCD_Drawpoint(x0,y0,ctbl[ccnt]);
ccnt++;
}
}
}
主函数部分代码
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //3õê¼»ˉÑóê±oˉêy
uart_init(115200); //3õê¼»ˉ′®¿ú2¨ìØÂêÎa115200
LED_Init(); //3õê¼»ˉLED
usmart_dev.init(84); //3õê¼»ˉUSMART
TFTLCD_Init(); //LCD3õê¼»ˉ
KEY_Init(); //°′¼ü3õê¼»ˉ
W25QXX_Init(); //3õê¼»ˉW25Q128
WM8978_Init(); //3õê¼»ˉWM8978
WM8978_HPvol_Set(40,40); //¶ú»úòôá¿éèÖÃ
WM8978_SPKvol_Set(0); //à®°èòôá¿éèÖÃ
my_mem_init(SRAMIN); //3õê¼»ˉÄú2¿Äú′æ3Ø
my_mem_init(SRAMCCM); //3õê¼»ˉCCMÄú′æ3Ø
exfuns_init(); //ÎafatfsÏà1رäá¿éêÇëÄú′æ
f_mount(fs[0],"0:",1); //1òÔØSD¿¨
POINT_COLOR=RED;
while(font_init()) //¼ì2é×Ö¿a
{
LCD_ShowString(30,50,200,16,16,"Font Error!");
delay_ms(200);
LCD_Fill(30,50,240,66,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
POINT_COLOR=RED;
Show_Str(60,50,200,16,"Explorer STM32F4¿a·¢°å",16,0);
Show_Str(60,70,200,16,"òôàÖ2¥·ÅÆ÷êμÑé",16,0);
Show_Str(60,90,200,16,"ÕyμãÔ-×ó@ALIENTEK",16,0);
Show_Str(60,110,200,16,"2014Äê5ÔÂ24èÕ",16,0);
Show_Str(60,130,200,16,"KEY0:NEXT KEY2
REV",16,0);
Show_Str(60,150,200,16,"KEY_UP
AUSE/PLAY",16,0);
bjgm=mymalloc(SRAMIN,16);
app_read_bkcolor(60,190,150,16,bjgm);
while(1)
{
audio_play();
}
}
audio函数部分代码
void audio_play(void)
{
u8 res;
DIR wavdir; //Ŀ¼
FILINFO wavfileinfo;//ÎļtDÅÏ¢
u8 *fn; //3¤ÎļtÃû
u8 *pname; //′ø·¾¶μÄÎļtÃû
u16 totwavnum; //òôàÖÎļt×üêy
u16 curindex; //í¼Æ¬μ±Ç°Ë÷òy
u8 key; //¼üÖμ
u16 temp;
u16 *wavindextbl; //òôàÖË÷òy±í
WM8978_ADDA_Cfg(1,0); //¿aÆôDAC
WM8978_Input_Cfg(0,0,0);//1رÕêäèëí¨μà
WM8978_Output_Cfg(1,0); //¿aÆôDACêä3ö
while(f_opendir(&wavdir,"0:/MUSIC"))//′ò¿aòôàÖÎļt¼D
{
Show_Str(60,190,240,16,"MUSIC文件夹错误!",16,0); //就是提示这个错误,我不加那两个函数可以正常播放,文件夹不会有错,搞不懂为什么加上那两函数这里就报错了
delay_ms(200);
LCD_Fill(60,190,240,206,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
totwavnum=audio_get_tnum("0:/MUSIC"); //μÃμ½×üóDD§Îļtêy
while(totwavnum==NULL)//òôàÖÎļt×üêyÎa0
{
Show_Str(60,190,240,16,"ûóDòôàÖÎļt!",16,0);
delay_ms(200);
LCD_Fill(60,190,240,146,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
wavfileinfo.lfsize=_MAX_LFN*2+1; //3¤ÎļtÃû×î′ó3¤¶è
wavfileinfo.lfname=mymalloc(SRAMIN,wavfileinfo.lfsize); //Îa3¤Îļt»o′æÇø·ÖÅäÄú′æ
pname=mymalloc(SRAMIN,wavfileinfo.lfsize); //Îa′ø·¾¶μÄÎļtÃû·ÖÅäÄú′æ
wavindextbl=mymalloc(SRAMIN,2*totwavnum); //éêÇë2*totwavnum¸ö×Ö½úμÄÄú′æ,óÃóú′æ·ÅòôàÖÎļtË÷òy
while(wavfileinfo.lfname==NULL||pname==NULL||wavindextbl==NULL)//Äú′æ·ÖÅä3ö′í
{
Show_Str(60,190,240,16,"Äú′æ·ÖÅä꧰ü!",16,0);
delay_ms(200);
LCD_Fill(60,190,240,146,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
//¼Ç¼Ë÷òy
res=f_opendir(&wavdir,"0:/MUSIC"); //′ò¿aĿ¼
if(res==FR_OK)
{
curindex=0;//μ±Ç°Ë÷òyÎa0
while(1)//è«2¿2éÑˉò»±é
{
temp=wavdir.index; //¼Ç¼μ±Ç°index
res=f_readdir(&wavdir,&wavfileinfo); //¶áè¡Ä¿Â¼ÏÂμÄò»¸öÎļt
if(res!=FR_OK||wavfileinfo.fname[0]==0)break; //′íÎóáË/μ½Ä©Î2áË,íË3ö
fn=(u8*)(*wavfileinfo.lfname?wavfileinfo.lfname:wavfileinfo.fname);
res=f_typetell(fn);
if((res&0XF0)==0X40)//衸ßËÄλ,¿′¿′êÇ2»êÇòôàÖÎļt
{
wavindextbl[curindex]=temp;//¼Ç¼Ë÷òy
curindex++;
}
}
}
curindex=0; //′ó0¿aê¼ÏÔê¾
res=f_opendir(&wavdir,(const TCHAR*)"0:/MUSIC"); //′ò¿aĿ¼
while(res==FR_OK)//′ò¿a3é1|
{
dir_sdi(&wavdir,wavindextbl[curindex]); //¸Ä±äμ±Ç°Ä¿Â¼Ë÷òy
res=f_readdir(&wavdir,&wavfileinfo); //¶áè¡Ä¿Â¼ÏÂμÄò»¸öÎļt
if(res!=FR_OK||wavfileinfo.fname[0]==0)break; //′íÎóáË/μ½Ä©Î2áË,íË3ö
fn=(u8*)(*wavfileinfo.lfname?wavfileinfo.lfname:wavfileinfo.fname);
strcpy((char*)pname,"0:/MUSIC/"); //¸′ÖÆ·¾¶(Ŀ¼)
strcat((char*)pname,(const char*)fn); //½«ÎļtÃû½óÔúoóÃæ
// LCD_Fill(60,190,240,190+16,WHITE);
app_recover_bkcolor(60,150,180,16,bjgm); //这里我将原来的清屏函数换成恢复背景 {MOD}
Show_Str(60,190,240-60,16,fn,16,0); //ÏÔ꾸èÇúÃû×Ö
audio_index_show(curindex+1,totwavnum);
key=audio_play_song(pname); //2¥·ÅÕa¸öòôÆμÎļt
if(key==KEY2_PRES) //éÏò»Çú
{
if(curindex)curindex--;
else curindex=totwavnum-1;
}else if(key==KEY0_PRES)//ÏÂò»Çú
{
curindex++;
if(curindex>=totwavnum)curindex=0;//μ½Ä©Î2μÄê±oò,×Ô¶ˉ′óí·¿aê¼
}else break; //2úéúáË′íÎó
}
[mw_shl_code=c,true] u16 *bjgm;
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //3õê¼»ˉÑóê±oˉêy
uart_init(115200); //3õê¼»ˉ′®¿ú2¨ìØÂêÎa115200
LED_Init(); //3õê¼»ˉLED
usmart_dev.init(84); //3õê¼»ˉUSMART
TFTLCD_Init(); //LCD3õê¼»ˉ
KEY_Init(); //°′¼ü3õê¼»ˉ
W25QXX_Init(); //3õê¼»ˉW25Q128
WM8978_Init(); //3õê¼»ˉWM8978
WM8978_HPvol_Set(40,40); //¶ú»úòôá¿éèÖÃ
WM8978_SPKvol_Set(0); //à®°èòôá¿éèÖÃ
my_mem_init(SRAMIN); //3õê¼»ˉÄú2¿Äú′æ3Ø
my_mem_init(SRAMCCM); //3õê¼»ˉCCMÄú′æ3Ø
exfuns_init(); //ÎafatfsÏà1رäá¿éêÇëÄú′æ
f_mount(fs[0],"0:",1); //1òÔØSD¿¨
POINT_COLOR=RED;
while(font_init()) //¼ì2é×Ö¿a
{
LCD_ShowString(30,50,200,16,16,"Font Error!");
delay_ms(200);
LCD_Fill(30,50,240,66,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
POINT_COLOR=RED;
Show_Str(60,50,200,16,"Explorer STM32F4¿a·¢°å",16,0);
Show_Str(60,70,200,16,"òôàÖ2¥·ÅÆ÷êμÑé",16,0);
Show_Str(60,90,200,16,"ÕyμãÔ-×ó@ALIENTEK",16,0);
Show_Str(60,110,200,16,"2014Äê5ÔÂ24èÕ",16,0);
Show_Str(60,130,200,16,"KEY0:NEXT KEY2REV",16,0);
Show_Str(60,150,200,16,"KEY_UPAUSE/PLAY",16,0);
bjgm=mymalloc(SRAMIN,16);
app_read_bkcolor(60,190,150,16,bjgm); //这两行我要是屏蔽了程序又能正常运行了,不会显示MUSIC文件夹错误
while(1)
{
audio_play();
}
}[/mw_shl_code]
一周热门 更多>