⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3_player_06.c

📁 MG64+VS1003+SDCARD+nokia5110 之多的MP3
💻 C
📖 第 1 页 / 共 4 页
字号:
										{
											Print_ICON_12(30,36,Speaker);
											LCD_print12(42,36,volume);
											lcdUpdateDisplay();
										}
									}
									break;
								
						case 'z':
						case 'Z':	 
						case 0x42:	/* volume down */
									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\nVolume: %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();
										}
									}
									break; 

						case '.':
						case '>':
						case 0x43:	/* next songs */
									songs++;
									if(songs > totalsongs)songs=1;
									free(buffer);
									goto next;
									break;
						
						case ',':
						case '<':
						case 0x44:	/*  previous songs */
									if(songs == 1)songs=totalsongs;
									else songs--;
									free(buffer);
									goto next;
									break;
						case 0x0d:
						case 0x0a:
						case 0x20:	/* play/pause */
									if(flag)
									{
										flag=0;
										printf_P(PSTR("\r\nPause"));
										if(lrc == 0 || HanziEnable == 0)
										{
											Print_ICON_12(18,0,Pause);
											lcdUpdateDisplay();
										}
									}
									else
									{
										flag=1;
										printf_P(PSTR("\r\nPlaying"));
										if(lrc == 0 || HanziEnable == 0)
										{
											Print_ICON_12(18,0,Playing);
											lcdUpdateDisplay();
										}
									}
									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                       */
/**********************************************************************************************************/ 
#endif
			#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>5)
							{
								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;

	VS1003B_Init();

	lcdInit();


	if(MCUCSR & 1<<BORF)
	{
		lcdClrDisBuf();
		LCD_print12_P(0,12,PSTR("Low Battery!!!"));
		lcdUpdateDisplay();
		while(1);
	}

	#if 0
	lcdClrDisBuf();
	LCD_print12_P(0,0,PSTR("  Mp3 Player\nX-mas Special\nFor   Sara Ye\n-- by Michael"));
	lcdUpdateDisplay();

	for(temp = 0;temp<40;temp++)
		Delay(0xffff);
	#endif
	
	OSCCAL = 0xff;

	lcdClrDisBuf();
	LCD_print12_P(0,0,PSTR("Pls insert SD card!"));
	lcdUpdateDisplay();
	while(MMC_SD_Init());
	
	FAT_ReadSector = MMC_SD_ReadSingleBlock;//device read
	FAT_WriteSector = MMC_SD_WriteSingleBlock;//device write
	FAT_ReadCapacity = MMC_SD_ReadCapacity;//read capacity


	if(FAT_Init())
	{
		lcdClrDisBuf();
		LCD_print12_P(0,0,PSTR("Wrong FAT!\nSystem halted!\nPls reset the\nsystem! -bozai"));
		lcdUpdateDisplay();
		while(1);
	}//初始化FAT文件系统
		
	if(GBK_Ini())
	{
		lcdClrDisBuf();
		LCD_print12_P(0,0,PSTR("Firmware lost!\nPress start to\ncontinue!\n    --By bozai"));
		lcdUpdateDisplay();
		HanziEnable = 0;
	}
	else 
	{
		lcdClrDisBuf();
		//LCD_print12_P(0,0,PSTR("  固件正常!\n MP3 for 叶敏\n -- by 章其波\n 按开始键继续"));
		LCD_print12_P(0,0,PSTR("固件正常!\nMP3 player\nby 赵亮,章其波按开始键继续"));
		lcdUpdateDisplay();
             
		HanziEnable = 1;
	}

#if STOP_KEY
	while(PINE & STOP);
#else
	while(PINE & MODE);
#endif

	
#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 + -