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

📄 mp3_play.c

📁 mega64 + VS1003 + SD卡
💻 C
📖 第 1 页 / 共 2 页
字号:
				else if(VS1003B_ReadDecodeTime() != decodetime)
				{
					decodetime = VS1003B_ReadDecodeTime();
					min = decodetime/60;
					sec = decodetime%60;
					if(lrc)
					{ 
						if(min>99);
						else if(HanziEnable)
						{
							time[0] = min/10 + 0x30;
							time[1] = min%10 + 0x30;
							time[3] = sec/10 + 0x30;
							time[4] = sec%10 + 0x30;
							LCD_print12_fast(54,36,time);
						} 
						else
						{
							time[0] = min/10 + 0x30;
							time[1] = min%10 + 0x30;
							time[3] = sec/10 + 0x30;
							time[4] = sec%10 + 0x30;
							LCD_print12_fast(30,36,time);
						}
						while(1)
						{
							if(LrcStruct_pp->time/1000 <= decodetime && LrcStruct_pp != 0)
							{
								lrcaddr = LrcStruct_pp->eeaddr;
								while(1)
								{
									if(lrcaddr<MAXLRCDATSIZE)temp = lrcdatbuf[lrcaddr++];
									else temp = eeprom_read_byte(lrcaddr++ - MAXLRCDATSIZE);

									if(temp == 0)
									{
										break;
									}
									if(lrcCnt<MAX_LRC_DISP-1)lrcdata[lrcCnt++] = temp;
								}
								lrcdata[lrcCnt] = '\n';
								LrcStruct_pp = LrcStruct_pp->next;
							}
							else
							{
								if(lrcCnt && HanziEnable)
								{
									lcdClrDisBuf(); 
									lrcdata[lrcCnt] = '\0';
								//	printf_P(PSTR("\r\n[%s] %s"),time,lrcdata);
									//putsLrc(time,lrcdata);	/* faster string put */

									lrcDisFlag = 1;	/* we do not display the lyric now, it will display at next time */
													/* then it will not take many time to process the lyric          */
													/* otherwise, when playing 320Kbps file, glitch may occurs       */
									
									//LCD_print12_fast(0,0,lrcdata);
									//LCD_print12_fast(54,36,time);
								}
								else if(lrcCnt)
								{
									lrcdata[lrcCnt] = '\0';
								//	printf_P(PSTR("\r\n[%s] %s"),time,lrcdata);
									LCD_print12_fast(30,36,time);
								}
								break;
							}
						}
						lcdUpdateDisplay();
					}
					else
					{
						if(min>99);
						else
						{
							time[0] = min/10 + 0x30;
							time[1] = min%10 + 0x30;
							time[3] = sec/10 + 0x30;
							time[4] = sec%10 + 0x30;
							LCD_print12(30,36,time);
							lcdUpdateDisplay();
						} 
					}
				}
				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 0
/**********************************************************************************************************/ 
/* the following code if for uart control  */
				else if(UCSR0A & (1<<RXC0))
				{
					temp = UDR0;
					switch(temp)
					{
						case 'x':
						case 'X':
						case 0x41:	/* volume up */
									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\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 '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(key_value & KEY_VALID)
				{
					if((key_value&(KEY_VALUE_MASK|KEY_LONG)) == KEY_STOP)
					{
						key_value = 0;
						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();
							}
						}

					}
					else if((key_value&KEY_VALUE_MASK) == KEY_MODE)
					{
						if(key_value&KEY_LONG)
						{
							LCD_BL_INV;
							key_value &= ~KEY_VALID;
						}
						else
						{
							key_value = 0;
							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();
							}  
						}
						//key_value = 0;
					}
					else if((key_value&(KEY_VALUE_MASK|KEY_LONG)) == KEY_NEXT)
					{
						key_value = 0;
						songs++;
						if(songs > totalsongs)songs=1;
						{
							free(buffer);
							goto next;
						}
					}
					else if((key_value&(KEY_VALUE_MASK|KEY_LONG)) == KEY_PREV)
					{
						key_value = 0;
						if(songs == 1)songs=totalsongs;
						else songs--;
						{
							free(buffer);
							goto next;
						}
					}
					else if((key_value&(KEY_VALUE_MASK|KEY_LONG)) == KEY_UP)
					{
						key_value = 0;
						if(vol_temp == 31);
						else  
						{
							vol_temp++;
							vol = pgm_read_byte(&Volume_Table[vol_temp]);
							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((key_value&(KEY_VALUE_MASK|KEY_LONG)) == KEY_DOWN)
					{
						key_value = 0;
						if(vol_temp == 0);
						else 
						{
							vol_temp--;
							vol = pgm_read_byte(&Volume_Table[vol_temp]);
							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
					{
						key_value &= ~KEY_VALID;
					}
				}
			}
			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;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -