📄 main.c
字号:
}
}
}
else if(lrcDisFlag) /* display the lyric */
{ /* the lowest priority */
lrcDisFlag = 0;
lrcCnt = 0;
LCD_print12_fast(0,0,lrcdata);
LCD_print12_fast(54,36,time);
lcdUpdateDisplay();
}
#if 1
if(KEY_PLAY_STATE() == 0 /*&& keylen==0*/)//播放暂停键 //key PLAY/PAUSE
{
Delay(100);
if(KEY_PLAY_STATE() == 0)
{
while(KEY_PLAY_STATE() == 0);
if(flag)
{
flag=0;
printf_P(("Pause\r\n"));
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(("Playing\r\n"));
if(lrc == 0 || HanziEnable == 0)
{
Print_ICON_12(18,0,Playing);
lcdUpdateDisplay();
}
else
{
Print_ICON_12(42,36,Playing);
lcdUpdateDisplay();
}
}
Delay(1000);
}
}
else if((KEY_VOLD_STATE() == 0) && keylen==0) //音量- //Volume down
{
Delay(100);
if(KEY_VOLD_STATE() == 0)
{
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(("Turn volume down to: %s\r\n"),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((KEY_VOLU_STATE() == 0) && keylen==0) //音量+ //Volume up
{
Delay(100);
if(KEY_VOLU_STATE() == 0)
{
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(("Turn volume up to: %s\r\n"),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(KEY_DOWN_STATE() == 0) //下一首
#else
if(KEY_DOWN_STATE() == 0) //下一首 next songs
#endif
{
Delay(50000);
if(KEY_DOWN_STATE() == 0)
{
while(KEY_DOWN_STATE() == 0);
songs++;
if(songs > totalsongs)songs=1;
{
free(buffer);
goto next;
}
}
}
else if(KEY_UP_STATE() == 0) //上一首 previous songs
{
Delay(5000);
if(KEY_UP_STATE() == 0)
{
while(KEY_UP_STATE() == 0);
if(songs == 1)songs=totalsongs;
else songs--;
{
free(buffer);
goto next;
}
}
}
else if((KEY_MODE_STATE() == 0) && keylen==0) //模式 //mode key
{
Delay(100);
if(KEY_MODE_STATE() == 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();
srand(T0TC);//产生随机数的种子
}
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(("Set mode -> repet all\r\n"));break;
case REPET_ONE:Print_ICON_12(72,0,RepetOne);printf_P(("Set mode -> repet one\r\n"));break;
case RANDOM :Print_ICON_12(72,0,Shuffle);printf_P(("Set mode -> shuffle\r\n"));break;
default:break;
}
lcdUpdateDisplay();
}
else
{
switch(mode)
{
case REPET_ALL:Print_ICON_12(18,36,RepetAll);printf_P(("Set mode -> repet all\r\n"));break;
case REPET_ONE:Print_ICON_12(18,36,RepetOne);printf_P(("Set mode -> repet one\r\n"));break;
case RANDOM :Print_ICON_12(18,36,Shuffle);printf_P(("Set mode -> shuffle\r\n"));break;
default:break;
}
lcdUpdateDisplay();
}
}
}
}
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;
}
}
#endif
return 0;
}
#endif
/*** Main Program ***/
#if 0
#else
int main(void)
{
char temp;
//unsigned char buffer[512];
// unsigned char * pBuf;
// unsigned int i,j;
#ifdef __DEBUG_RAM
MEMMAP = 0x2; //remap
#endif
#ifdef __DEBUG_FLASH
MEMMAP = 0x1; //remap
#endif
#ifdef __IN_CHIP
MEMMAP = 0x1; //remap
#endif
PINSEL0 = (PINSEL0 & 0xFFFF0000) | 0x05 | 0x50;
/* 设置系统各部分时钟 */
/* Set system timers for each component */
PLLCON = 1;
#if (Fpclk / (Fcclk / 4)) == 1
VPBDIV = 0;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
VPBDIV = 2;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
VPBDIV = 1;
#endif
#if (Fcco / Fcclk) == 2
PLLCFG = ((Fcclk / Fosc) - 1) | (0 << 5);
#endif
#if (Fcco / Fcclk) == 4
PLLCFG = ((Fcclk / Fosc) - 1) | (1 << 5);
#endif
#if (Fcco / Fcclk) == 8
PLLCFG = ((Fcclk / Fosc) - 1) | (2 << 5);
#endif
#if (Fcco / Fcclk) == 16
PLLCFG = ((Fcclk / Fosc) - 1) | (3 << 5);
#endif
PLLFEED = 0xaa;
PLLFEED = 0x55;
while((PLLSTAT & (1 << 10)) == 0);
PLLCON = 3;
PLLFEED = 0xaa;
PLLFEED = 0x55;
/* 设置存储器加速模块 */
/* Set memory accelerater module*/
MAMCR = 0;
#if Fcclk < 20000000
MAMTIM = 1;
#else
#if Fcclk < 40000000
MAMTIM = 2;
#else
MAMTIM = 3;
#endif
#endif
MAMCR = 2;
LCD_BL_GPIO();
LCD_BL_OUT();
LCD_BL_CLR();
LED_GPIO();
LED_OUT();
LED_CLR();
KEY_PLAY_GPIO();
KEY_PLAY_IN();
KEY_UP_GPIO();
KEY_UP_IN();
KEY_DOWN_GPIO();
KEY_DOWN_IN();
KEY_VOLD_GPIO();
KEY_VOLD_IN();
KEY_VOLU_GPIO();
KEY_VOLU_IN();
KEY_MODE_GPIO();
KEY_MODE_IN();
#if 1
#if 0
/* enable reset-button (mt) */
/* AT91F_RSTSetMode( AT91C_BASE_RSTC , AT91C_RSTC_URSTEN ); */
*AT91C_RSTC_RMR = ( 0xA5000000 | AT91C_RSTC_URSTEN );
*AT91C_PMC_PCER = (1 << AT91C_ID_PIOA) | /* Enable Clock for PIO */
(1 << AT91C_ID_IRQ0) | /* Enable Clock for IRQ0 */
(1 << AT91C_ID_US0); /* Enable Clock for USART0 */
#endif
uart0_init(); /* Initialize Serial Interface */
uart0_puts("\r\nsystem start!");
printf(" --by bozai");
Time0Init();
//init_timer();
//portIni();
printf_P(("\r\n************************************************"));
printf_P(("\r\n SD mp3 player V2.4 for LPC2132 platform (Keil ARM) "));
printf_P(("\r\n Design by Michael Zhang (bozai) 章其波"));
printf_P(("\r\n************************************************\r\n"));
if(VS1003B_Init())
{
printf_P(("\r\nVS1003 config fialed!\r\n"));//配置VS1003
}
else
{
printf_P(("\r\nVS1003 config OK!\r\n"));
}
#if 0
if(CH375_CheckExist())printf_P("Found CH375!\r\n");
else printf_P("CH375 not exist!\r\n");
#endif
printf_P(("LCD initialize OK!"));
lcdInit();
//lcdTest();
#if 0
lcdClrDisBuf();
LCD_print12_P(0,0,("Pls select\nNext for Udisk\nPREV for SD\n-- by bozai"));
lcdUpdateDisplay();
printf_P("Pls select the device:\r\n Next for Udisk\r\n PREV for SD\r\n -- by bozai\r\n");
while(pPIO->PIO_PDSR & NEXT && pPIO->PIO_PDSR & PREV);
if(pPIO->PIO_PDSR & NEXT)
{
lcdClrDisBuf();
LCD_print12_P(0,0,("Pls insert SD card!"));
lcdUpdateDisplay();
printf_P(("\r\nPlease insert SD card!"));
while(MMC_SD_Init());
printf_P(("\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
{
lcdClrDisBuf();
LCD_print12_P(0,0,("Pls insert Udisk!"));
lcdUpdateDisplay();
printf_P(("\r\nPlease insert Flash disk!"));
while(CH375_IniDisk());
printf_P(("\r\nFlash disk initialize OK!"));
FAT_ReadSector = CH375_ReadOneSector;//device read
FAT_WriteSector = CH375_WriteOneSector;//device write
FAT_ReadCapacity = CH375_ReadDiskSize;
}
#endif
lcdClrDisBuf();
LCD_print12_P(0,0,("Pls insert SD card!"));
lcdUpdateDisplay();
printf_P(("\r\nPlease insert SD card!"));
while(MMC_SD_Init());
printf_P(("\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(("\r\nDisk size is: %ld MB"),FAT_ReadCapacity()/1024/2);
if(FAT_Init())
{
printf_P(("\r\nFAT initialize fialed! Or System error!"));
printf_P(("\r\nYou may try to turn off the power and then power on."));
printf_P(("\r\nOtherwise pls check that whether your card is correctly fomated"));
lcdClrDisBuf();
LCD_print12_P(0,0,("Wrong FAT!\nSystem halted!\nPls reset the\nsystem! -bozai"));
lcdUpdateDisplay();
while(1);
}//初始化FAT文件系统
else
{
printf_P(("\r\nFAT initialize OK!"));
}
if(GBK_Ini())
{
lcdClrDisBuf();
LCD_print12_P(0,0,("Firmware lost!\nPress start to\ncontinue!\n --By bozai"));
lcdUpdateDisplay();
printf_P(("\r\nFirmware lost!\r\nPress start to continue!"));
HanziEnable = 0;
}
else
{
lcdClrDisBuf();
LCD_print12_P(0,0,("固件正常!\nDesign by\nbozai-章其波\n按开始键继续"));
lcdUpdateDisplay();
printf_P(("\r\n\r\n固件正常!"));
printf_P(("\r\nDesign by : Michael - 章其波(bozai) 2008-10-02 @ home"));
printf_P(("\r\nEmail: sudazqb@163.com MSN: zhangqibo_1985@hotmail.com"));
printf_P(("\r\n**************** ALL RIGHTS RESERVED! *****************"));
printf_P(("\r\n\r\n按开始键继续\r\n"));
HanziEnable = 1;
}
while(KEY_PLAY_STATE() != 0);
#if FIX_DIRECTORY
printf_P(("\r\nSearch the folder %s\r\n"),MUSIC_PATH);
Search(MUSIC_PATH,&MusicInfo,&totalsongs,&type);//搜索歌曲
#else
printf_P(("\r\n\r\nSearch & record folder information....."));
printf_P(("\r\nNOTE: MAX folder amount is %d for we only use %dBytes ram to store the info\r\n"),RECORD_ADDR_END/4 -1,RECORD_ADDR_END);
SearchInit();
Search(0,&MusicInfo,&totalsongs,&type);//搜索歌曲
#endif
iprintf("Search & find %d songs\r\n",totalsongs);
PlayMusicwithKey();
iprintf("\r\nno songs to play\r\n");
while (1) /* Loop forever */
{
if(uart0_kbhit())
{
temp = uart0_getc();
if(temp == '\r' || temp == '\n')
{
uart0_putc('\r');
uart0_putc('\n');
}
else
uart0_putc(temp);
}
} // while
#endif
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -