📄 mp3_player_06.c
字号:
}
}
break;
// case 0x2e:
// case 0x2c:
// case 'x':
// case 'z':
case 'M':
case 'm': /* mode select */
if(mode==REPET_ALL)
{
mode=REPET_ONE;
}
else if(mode==REPET_ONE)//next mode is shuffle
{
mode=RANDOM;
srandom(((unsigned long)TCNT1)<<16);//产生随机数的种子
}
else
{
mode=REPET_ALL;
}
if(lrc == 0 || HanziEnable == 0)
{
switch(mode)
{
case REPET_ALL:Print_ICON_12(72,0,RepetAll);printf_P(PSTR("\r\nSet mode -> repet all"));break;
case REPET_ONE:Print_ICON_12(72,0,RepetOne);printf_P(PSTR("\r\nSet mode -> repet one"));break;
case RANDOM :Print_ICON_12(72,0,Shuffle);printf_P(PSTR("\r\nSet mode -> shuffle"));break;
default:break;
}
lcdUpdateDisplay();
}
else
{
switch(mode)
{
case REPET_ALL:Print_ICON_12(18,36,RepetAll);printf_P(PSTR("\r\nSet mode -> repet all"));break;
case REPET_ONE:Print_ICON_12(18,36,RepetOne);printf_P(PSTR("\r\nSet mode -> repet one"));break;
case RANDOM :Print_ICON_12(18,36,Shuffle);printf_P(PSTR("\r\nSet mode -> shuffle"));break;
default:break;
}
lcdUpdateDisplay();
}
default: temp=0;
}
}
/* above is the code of uart control */
/**********************************************************************************************************/
#if STOP_KEY
if((PINE&STOP)==0 /*&& keylen==0*/)//播放暂停键 //key PLAY/PAUSE
{
blkeyflag = 0;
Delay(100);
if(!(PINE&STOP))
{
while(!(PINE&STOP));
if(flag)
{
flag=0;
printf_P(PSTR("\r\nPause"));
if(lrc == 0 || HanziEnable == 0)
{
Print_ICON_12(18,0,Pause);
lcdUpdateDisplay();
}
else
{
Print_ICON_12(42,36,Pause);
lcdUpdateDisplay();
}
}
else
{
flag=1;
printf_P(PSTR("\r\nPlaying"));
if(lrc == 0 || HanziEnable == 0)
{
Print_ICON_12(18,0,Playing);
lcdUpdateDisplay();
}
else
{
Print_ICON_12(42,36,Playing);
lcdUpdateDisplay();
}
}
Delay(1000);
}
}
else if(!(PINE&DOWN) && keylen==0) //音量- //Volume down
#else
if(!(PINE & DOWN) && keylen==0) //音量-
#endif
{
blkeyflag = 0;
Delay(100);
if(!(PINE & DOWN))
{
keylen=200;
if(vol_temp == 0);
else
{
vol_temp--;
vol = (uint8)(255-(((uint16)vol_temp)*255)/100);
vol = (vol<<8) +vol;
VS1003B_SetVolume(vol);
volume[0] = vol_temp/10 + 0x30;
volume[1] = vol_temp%10 +0x30;
printf_P(PSTR("\r\nTurn volume down to: %s"),volume);
if(lrc == 0 || HanziEnable == 0)
{
LCD_print12(72,36,volume);
lcdUpdateDisplay();
}
else
{
Print_ICON_12(30,36,Speaker);
LCD_print12(42,36,volume);
lcdUpdateDisplay();
}
}
}
}
else if(!(PINE & UP) && keylen==0) //音量+ //Volume up
{
blkeyflag = 0;
Delay(100);
if(!(PINE & UP))
{
keylen=200;
if(vol_temp == 99);
else
{
vol_temp++;
vol = (uint8)(255-(((uint16)vol_temp)*255)/100);
vol =(vol<<8) + vol;
VS1003B_SetVolume(vol);
volume[0] = vol_temp/10 + 0x30;
volume[1] = vol_temp%10 +0x30;
printf_P(PSTR("\r\nTurn volume up to: %s"),volume);
if(lrc == 0 || HanziEnable == 0)
{
LCD_print12(72,36,volume);
lcdUpdateDisplay();
}
else
{
Print_ICON_12(30,36,Speaker);
LCD_print12(42,36,volume);
lcdUpdateDisplay();
}
}
}
}
else if(!(PINE & NEXT)) //下一首 next songs
{
blkeyflag = 0;
Delay(50000);
if(!(PINE & NEXT))
{
while(!(PINE & NEXT));
songs++;
if(songs > totalsongs)songs=1;
{
free(buffer);
goto next;
}
}
}
else if(!(PINE & PREV)) //上一首 previous songs
{
blkeyflag = 0;
Delay(5000);
if(!(PINE & PREV))
{
while(!(PINE&PREV));
if(songs == 1)songs=totalsongs;
else songs--;
{
free(buffer);
goto next;
}
}
}
else if(((!(PINE & MODE)) || blkeyflag) && keylen==0 ) //模式 //mode key
{
// keycnt++;
Delay(50);
if(blkeyflag == 0)
{
blkeyflag = 1;
keycnt = 0;
}
else
{
if(!(PINE & MODE))
{
keycnt ++;
keylen=0xfff;
if(keycnt>20)
{
LCD_BL_INV;
blkeyflag = 0;
keylen=0xffff;
}
}
else
{
blkeyflag = 0;
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(((unsigned long)TCNT1)<<16);//产生随机数的种子
}
else
{
mode=REPET_ALL;
// LED1_OFF();
// LED2_OFF();
}
if(lrc == 0 || HanziEnable == 0)
{
switch(mode)
{
case REPET_ALL:Print_ICON_12(72,0,RepetAll);printf_P(PSTR("\r\nSet mode -> repet all"));break;
case REPET_ONE:Print_ICON_12(72,0,RepetOne);printf_P(PSTR("\r\nSet mode -> repet one"));break;
case RANDOM :Print_ICON_12(72,0,Shuffle);printf_P(PSTR("\r\nSet mode -> shuffle"));break;
default:break;
}
lcdUpdateDisplay();
}
else
{
switch(mode)
{
case REPET_ALL:Print_ICON_12(18,36,RepetAll);printf_P(PSTR("\r\nSet mode -> repet all"));break;
case REPET_ONE:Print_ICON_12(18,36,RepetOne);printf_P(PSTR("\r\nSet mode -> repet one"));break;
case RANDOM :Print_ICON_12(18,36,Shuffle);printf_P(PSTR("\r\nSet mode -> shuffle"));break;
default:break;
}
lcdUpdateDisplay();
}
}
}
Delay(100);
}
}
sector++;
free(buffer);
}
i=0;
p=FAT_NextCluster(p);
//p=FAT_NextCluster_NEW(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;
}
}
}
int main()
{
unsigned char temp;
DDRE = 0x00;
PORTE = 0xff;
PORTB |= 1<<PB0; /* we should make sure that AVR's SS pin is held high no mater the spi is master or slave*/
LCD_BL_CON;
LCD_BL_ON;
OSCCAL = 0xff;
Delay(0xffff);
COM_Initial(MYUBRR);//初始化串口
printf_P(PSTR("\r\n************************************************"));
printf_P(PSTR("\r\n SD & USB disk mp3 player V2.2 "));
printf_P(PSTR("\r\n Design by Michael Zhang (bozai) 章其波"));
printf_P(PSTR("\r\n************************************************\r\n"));
if(VS1003B_Init())
{
printf_P(PSTR("\r\nVS1003 config fialed!"));//配置VS1003
}
else
{
printf_P(PSTR("\r\nVS1003 config OK!"));
}
printf_P(PSTR("\r\nLCD initialize OK!"));
lcdInit();
CH375_PORT_INI();
if(CH375_CheckExist())
{
printf_P(PSTR("\r\nCH375 port initialize OK! & find the chip!"));
}
else printf_P(PSTR("\r\nCH375 chip not exist!"));
lcdClrDisBuf();
#if 0
LCD_print12_P(0,0,PSTR("Please press\nNEXT for SD\nPREV for USB\n --by bozai"));
lcdUpdateDisplay();
printf_P(PSTR("\r\n"));
printf_P(PSTR("\r\n******************************************************************************"));
printf_P(PSTR("\r\nPlease press:"));
printf_P(PSTR("\r\n \"NEXT\" key to choose SD card."));
printf_P(PSTR("\r\n \"PREV\" key to choose USB Disk!"));
printf_P(PSTR("\r\n \"UP\" to enter bootloader in 10 seconds!"));
printf_P(PSTR("\r\n Otherwise it will execute the bootloader code automaticly!\r\n"));
printf_P(PSTR("\r\nNOTE:You can also control this device use pc teminal through the uart"));
printf_P(PSTR("\r\n Space & Enter for PLAY/PAUSE"));
printf_P(PSTR("\r\n up for VOL+"));
printf_P(PSTR("\r\n down for VOL-"));
printf_P(PSTR("\r\n right for NEXT"));
printf_P(PSTR("\r\n left for PREV"));
printf_P(PSTR("\r\n m for MODE"));
printf_P(PSTR("\r\n******************************************************************************"));
printf_P(PSTR("\r\n"));
totalsongs = 0; /* here for loop variable */
while(PINE & NEXT && (PINE & PREV) && (PINE & UP))
{
if(UCSR0A & (1<<RXC0))
{
temp = UDR0;
if(temp == 0x42 || temp == 0x43 || temp == 0x44)break;
}
if (totalsongs++ == 10000)
{
goto BootLoader;
}
_delay_ms(1);
}
totalsongs = 0; /* clear it for the following code use */
if(!(PINE & NEXT) || temp == 0x43)
{
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("Pls insert SD card!"));
lcdUpdateDisplay();
printf_P(PSTR("\r\nPlease insert SD card!"));
while(MMC_SD_Init());
printf_P(PSTR("\r\nSD initialize OK!"));
FAT_ReadSector = MMC_SD_ReadSingleBlock;//device read
FAT_WriteSector = MMC_SD_WriteSingleBlock;//device write
FAT_ReadCapacity = MMC_SD_ReadCapacity;//read capacity
}
else if(!(PINE & PREV) || temp == 0x44)
{
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("Pls insert U disk!"));
lcdUpdateDisplay();
printf_P(PSTR("\r\nPlease insert U disk!"));
while(CH375_IniDisk());
printf_P(PSTR("\r\nUdisk Initialize OK!"));
FAT_ReadSector = CH375_ReadOneSector;
FAT_WriteSector = CH375_WriteOneSector;
FAT_ReadCapacity = CH375_ReadDiskSize;
}
else
{
BootLoader:
printf_P(PSTR("\r\nEnter bootloader for firmware upgrade!"));
printf_P(PSTR("\r\nPress reset to restart or download the firmware."));
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("Run bootloader for firmware upgrade\n --by bozai"));
lcdUpdateDisplay();
cli();
BootLoaderEntry();
}
#endif
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("Pls insert SD card!"));
lcdUpdateDisplay();
printf_P(PSTR("\r\nPlease insert SD card!"));
while(MMC_SD_Init());
printf_P(PSTR("\r\nSD initialize OK!"));
FAT_ReadSector = MMC_SD_ReadSingleBlock;//device read
FAT_WriteSector = MMC_SD_WriteSingleBlock;//device write
FAT_ReadCapacity = MMC_SD_ReadCapacity;//read capacity
printf_P(PSTR("\r\nDisk size is: %ld MB"),FAT_ReadCapacity()/1024/1024);
if(FAT_Init())
{
printf_P(PSTR("\r\nFAT initialize fialed! Or System error!"));
printf_P(PSTR("\r\nYou may try to turn off the power and then power on."));
printf_P(PSTR("\r\nOtherwise pls check that whether your card is correctly fomated"));
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("Wrong FAT!\nSystem halted!\nPls reset the\nsystem! -bozai"));
lcdUpdateDisplay();
while(1);
}//初始化FAT文件系统
else
{
printf_P(PSTR("\r\nFAT initialize OK!"));
}
if(GBK_Ini())
{
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("Firmware lost!\nPress start to\ncontinue!\n --By bozai"));
lcdUpdateDisplay();
printf_P(PSTR("\r\nFirmware lost!\r\nPress start to continue!"));
HanziEnable = 0;
}
else
{
lcdClrDisBuf();
LCD_print12_P(0,0,PSTR("固件正常!\nDesign by\nbozai-章其波\n按开始键继续"));
lcdUpdateDisplay();
printf_P(PSTR("\r\n\r\n固件正常!"));
printf_P(PSTR("\r\nDesign by : Michael - 章其波(bozai) 2007-11-22 in ZyXEL"));
printf_P(PSTR("\r\nEmail: sudazqb@163.com MSN: zhangqibo_1985@hotmail.com"));
printf_P(PSTR("\r\n**************** ALL RIGHTS RESERVED! *****************"));
printf_P(PSTR("\r\n\r\n按开始键继续\r\n"));
HanziEnable = 1;
}
#if STOP_KEY
while(PINE & STOP)
#else
while(PINE & MODE)
#endif
{
if(UCSR0A & (1<<RXC0))
{
temp = UDR0;
if(temp == 0x20 || temp == 0x0d || temp == 0x0a)break;
}
}
#if FIX_DIRECTORY
printf_P(PSTR("\r\nSearch the folder %s\r\n"),MUSIC_PATH);
Search(MUSIC_PATH,&MusicInfo,&totalsongs,&type);//搜索歌曲
#else
printf_P(PSTR("\r\n\r\nSearch & record folder information....."));
printf_P(PSTR("\r\nNOTE: MAX folder amount is %d for we only use %dBytes EEPROM to store the info\r\n"),(RECORD_ADDR_END-RECORD_ADDR_START)/4 -1,RECORD_ADDR_END-RECORD_ADDR_START);
SearchInit();
Search(0,&MusicInfo,&totalsongs,&type);//搜索歌曲
#endif
PlayMusicwithKey();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -