📄 mega8_player_v11.c
字号:
FAT_LoadPartCluster(p,i,buffer);//读一个扇区 //read a sector
count=0;
while(count<512)
{
if(flag==0){if(keylen){Delay(100);keylen--;}}
else if(type == MID){if(keylen){Delay(100);keylen--;}}
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 && flag) //根据需要送数据 //send data honoring DREQ
{
for(j=0;j<32;j++) //每次送32个数据 //32 Bytes each time
{
VS1003B_WriteDAT(buffer[count]);
count++;
}
if(keylen)keylen--; //用于键处理 //for key processing
if(sector == totalsect && count >= leftbytes) //如果文件已结束 //if this is the end of the file
{
if(type == MID)//waiting the midi file was decoded
{//对于mid音乐要接着送2048个零
count=0;
while(count<2048)//recommand 2048 zeros honoring DREQ goto next songs
{
if((VS1003B_PIN & _BV(VS1003B_DREQ))!=0 )
{
for(j=0;j<32;j++)
{
VS1003B_WriteDAT(0x00);
count++;
}
if(count == 2047)break;
}
}
}
i=SectorsPerClust;
break;
}//文件结束 //file ended
if(count == 511){break;}//512字节送完跳出 //break if a sector was sent
}
if((PIND&STOP)==0 /*&& keylen==0*/)//播放暂停键 //key PLAY/PAUSE
{
Delay(100);
if(!(PIND&STOP))
{
while(!(PIND&STOP));
if(flag)flag=0;
else flag=1;
Delay(1000);
}
}
else if(!(PIND&DOWN) && keylen==0) //音量- //Volume down
{
Delay(100);
if(!(PIND&DOWN))
{
keylen=200;
vol=vol+((uint16)(1<<8)+1);
if(vol>=0xFEFE) vol=0xFEFE;
else VS1003B_WriteCMD(0x0b,vol);
}
}
else if(!(PIND&UP) && keylen==0) //音量+ //Volume up
{
Delay(100);
if(!(PIND&UP))
{
keylen=200;
vol=vol-((uint16)(1<<8)+1);
if(vol<=0x0101) vol=0x0101;
else VS1003B_WriteCMD(0x0b,vol);
}
}
else if(!(PIND&NEXT)) //下一首 next songs
{
Delay(0x7fff);
if(!(PIND&NEXT))
{
Delay(0x7fff);
if(!(PIND&NEXT))
{
while(!(PIND&NEXT));
songs++;
if(songs > totalsongs)songs=1;
{
free(buffer);
// Delay(0xffff);
goto next;
}
}
}
}
else if(!(PIND&PREV)) //上一首 previous songs
{
Delay(0x7fff);
if(!(PIND&PREV))
{
Delay(0x7fff);
if(!(PIND&PREV))
{
while(!(PIND&PREV));
if(songs == 1)songs=totalsongs;
else songs--;
{
free(buffer);
// Delay(0xffff);
goto next;
}
}
}
}
else if((!(PIND&MODE)) && keylen==0) //模式 //mode key
{
Delay(100);
if(!(PIND&MODE))
{
keylen=0xffff;
if(mode==REPET_ALL)
{
mode=REPET_ONE;
LED1_ON();
LED2_OFF();
}
else if(mode==REPET_ONE)//next mode is shuffle
{
mode=RANDOM;
LED1_OFF();
LED2_ON();
srandom(((uint32)TCNT1)<<16);//产生随机数的种子
}
else
{
mode=REPET_ALL;
LED1_OFF();
LED2_OFF();
}
}
}
}
sector++;
free(buffer);
}
i=0;
p=FAT_NextCluster(p);//读下一簇数据 //read next cluster
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
if(mode==REPET_ALL)songs++;
if(songs>totalsongs)songs=1;
goto next;
}
}
}
//main function
int main()
{
uint8 retry = 0;
DDRD &= 0x03;//初始化端口
PORTD |= 0xfc;
LED1_CON();
LED1_OFF();
LED2_CON();
LED2_OFF();
OSCCAL = 0x00;//最小RC振荡频率 //in order to operate some low speed card the initialization should run at lowest speed
Delay(0xffff);
MMC_SD_Init();//初始化spi口 //SPI initialize
Delay(0xffff);
if(VS1003B_Init())
{
//LED1_ON();//配置VS1003 //config vs1003
while(1)
{
LED1_ON();
Delay(0xffff);
LED1_OFF();
Delay(0xffff);
}
}
Delay(0xffff);//提供足够的延时 //supply enough delay
Delay(0xffff);
Delay(0xffff);
Delay(0xffff);
Delay(0xffff);
while(MMC_SD_Reset())//初始化SD卡 //sd card initialize
{
retry++;
if(retry>20)
{
// LED2_ON();
while(1)
{
LED2_ON();
Delay(0xffff);
LED2_OFF();
Delay(0xffff);
}
}
}
OSCCAL = 0xff;//最大RC振荡频率 //normal operation maximum the frequency
Delay(0xffff); //wait for stable
if(FAT_Init())//初始化文件系统 支持FAT16和FAT32 //initialize file system FAT16 and FAT32 are supported
{
// LED1_ON();
// LED2_ON();
// while(1);
while(1)
{
LED1_ON();LED2_ON();
Delay(0xffff);
LED1_OFF();LED2_OFF();
Delay(0xffff);
}
}
Search(PATH,&MusicInfo,&totalsongs,&type);//搜索根目下的歌曲 不包含子目录
//也可以指定文件夹 如Search("\\new\\mp3",&MusicInfo,&totalsongs,&type);
//代表在根目录下的new文件夹下的mp3文件下的音乐文件
//search the songs in the root directery on the SD card
//You can also specify the directery where the songs are placed
//eg: Search("\\new\\mp3",&MusicInfo,&totalsongs,&type);
// means search the file in the foler C:\new\mp3
PlayMusic();//播放歌曲 //play songs
while(1)
{
while(1)
{
LED1_ON();LED2_OFF();
Delay(0xffff);
LED2_ON();LED1_OFF();
Delay(0xffff);
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -