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

📄 mp3.c

📁 用atmega64+vs1003(音频解码芯片)+SD制成的板子
💻 C
📖 第 1 页 / 共 2 页
字号:
	unsigned char i,bDot;
	uchar work;  
	unsigned int tt;
	unsigned long address;
	unsigned char *pp=m_c[1].LongName;  
	lyric.t_sec=0xffff;
	lyric.t_ms=0;
	if(lyric.filelen==0) return;
	   
	address=(unsigned long )(fatClustToSect(lyric.Clust)+lyric.sl)*512+(unsigned long) lyric.wl*64;;
	ReadSD64Byte(address,lbuf); 
 	if(!lyric.first){  
		i=0;
		while(lyric.filelen>0){
			  c=GetChar(lbuf);    
		 	 if(c!=0x0d){	
	    	  if(++i<=28)	*pp++=c;
			 }else{
				 if(lyric.filelen>0) GetChar(lbuf);  
 			     break;
		    }                      
		}
		*pp='\0'; 
		pp=m_c[1].LongName;  
	  ClrLyricScreen();
	 	PrintString(1,0,pp); 
		PrintString(2,0,GetSecondLine(pp));
	}
	lyric.first = 0;      
	tt=0; work=0;
	bDot=0;
	while(1){ 
		if(lyric.filelen==0)  return;
		c=GetChar(lbuf);     //读取一个字节   
		if(work==0)  {      //支持 [xx:xx.xx] 及[xx:xx]
	         if(c=='[')  work++;
		}else if(work==1){
			if((c>='0')&&(c<='9')){
				tt=tt*10+(c-'0');
			}else if(c==':'){
				lyric.t_sec=tt*60; tt=0;
			}else if(c=='.'){     
				lyric.t_sec+=tt; tt=0;
				bDot = 1;
			}else if(c==']'){           
				if(bDot==0){
					lyric.t_sec+=tt;	
					lyric.t_ms=0;
	         	}else{
	         		lyric.t_ms=tt/3;
	         	}
				break;
			} 
		}	
//		 if(c==0x0d) {  GetChar(); work=0;     }
	}

}

// 歌词显示控制
void LyricDisplayCtrl()
{  
	static unsigned int time=0xffff;
	static unsigned char ms=0;  
	unsigned int t1;   
	if(WorkFlag&bPlayOvr)   return;
	if(!(TimeFlag&bT32MS))  return;
		TimeFlag&=~bT32MS;
		t1=GetDecodeTime();   
		if(t1!=time){
			time=t1;  ms=0;	
			DispDecodeTime(3,0,time=t1); 
			DispVolume();
			if(WorkFlag&bLrc)
					 	LCD_writeIcon(3,50,2);  //显示LRC图标
			return;
		}
	if(!WorkFlag&bLrc)   return;
	ms++;
	if(((t1==lyric.t_sec)&&(ms>=lyric.t_ms))||(t1>lyric.t_sec))
	{   
		ReadLrcFileData();  //读取歌曲数据并显示
	}
}
// 

void  MenuOpter(void)
{               
	
	switch(MenuMode){
		
		case PLAY_MODE:   //STANDBY  
				 PlayFunc();
		break;
		case VIEW_MODE:
			 	FileView();
				break;		
		case STBY_MODE:
			  StandbyMode();
			  break;
		  
		case RADIO_MODE:  //收音模式	
			  RadioMode();	                   
		break;
	};
}                    
void StandbyMode(void)
{
	if(MenuCnt==0){
		ClearLcdBuff();
		SetInverseLine(0xff);	
		MenuCnt++;
	}
		if(TimeFlag|=bRtcUpdate){
		   TimeFlag&=~bRtcUpdate;
	 		  LCD_write_time(&rtc);
		}
		if(KeyVal==kPlay){
			  MenuMode=VIEW_MODE;
			  MenuCnt=0;
		}
	 	KeyVal=kNull;
		
}
void RadioMode(void)
{
	
	;
	
}

//文件目录浏览(此模式不放音)
void FileView(void)
{
  uchar i;
	if(MenuCnt==0){
		TotalFile=SerarchFile(CurDir,fileindex);	
 		ClearLcdBuff();
 		for(i=0;i<4;i++){
			  if(m_c[i].Type==0){
			  	LCD_writeIcon(i,0,1);  //显示文件夹图标
			  }else if(m_c[i].Type!=0xff){
			  	LCD_writeIcon(i,0,0);  //显示音乐符号图标
			  }
  			PrintString(i,12,m_c[i].LongName);
  		}
  	  if(SelIndex>(TotalFile-1)) SelIndex=0;
			 SetInverseLine(SelIndex);	
  		 MenuCnt++;
	}else{
		switch(KeyVal){
			case kPrev:
	    		if(SelIndex==0){
	    			 if(fileindex>1){
	    	 			  SelIndex=3;
	    	 			  if(fileindex>4){
	    	 			     fileindex-=4;
	    	 			  }else{
	    	 			   	  SelIndex=fileindex;
	    	 			   	  fileindex=1;
	    	 			  }
	    	 			  MenuCnt=0;
	    	 			} 
	    	 	}else    SelIndex--;
	    	 		SetInverseLine(SelIndex);	
	    	 		break;
				case kNext:	   
				 if(SelIndex+fileindex<TotalFile){
			     if(SelIndex==3){
			     	  SelIndex=0;
			     	  if(fileindex<TotalFile-4){
			     	    fileindex+=4;
			     	  }else{
			     	    fileindex=TotalFile;
			     	    SelIndex=0;	
			     	  }
			     	  MenuCnt=0;
			     }else  SelIndex++;
		      SetInverseLine(SelIndex);	
		    }
	       break;
		case kPlay:
				 ClearLcdBuff();
			  if((m_c[SelIndex].Type!=0)&&(m_c[SelIndex].Type!=0xff)){
					MenuMode=PLAY_MODE;     //是音乐文件
					SetInverseLine(0);
					filelength=m_c[SelIndex].FileLen;
					FindLrcFile(CurDir,m_c[SelIndex].ShortName);
					PrintString(0,0,m_c[SelIndex].LongName);
					StartPlay(m_c[SelIndex].Clust);  
				}else{   //进入子目录或返回上级目录
			 		if(IsFatherDir(m_c[SelIndex].ShortName)){
						 fileindex=FindDirIndex(m_c[SelIndex].Clust,CurDir);
						 if(fileindex==0) fileindex=1;
					}else{
						 fileindex=1;
				  } 
				  CurDir=m_c[SelIndex].Clust;
				  MenuCnt=0;	
				  SelIndex=0;
				}
	        break;
	      };
	     KeyVal=kNull;
	
   } 
}
void SetInverseLine(uchar line)
{
	if(line>3) {
    InverseLine=0;		
	}else{
		InverseLine=0x01;
		InverseLine<<=line;
	}
		TimeFlag|=bLcdUpdate;
}
 
void FindSysFile(void)  //查找系统文件
{
	unsigned long hzk,unit;
	GetSysFileClust(&hzk,&unit);
	WorkFlag&=~(bUnicode|bHzk12);
	if(hzk!=0)
	{
	    SaveHzk12Sector(hzk);
	    WorkFlag|=bHzk12;
	}else{
		PrintString(1,0,"Hzk Not Found!"); 
	}  
	if(unit!=0){   
		SaveUniCodeSector(unit);
		WorkFlag|=bUnicode;
	
	}else{
		PrintString(2,0,"Uni Not Found!"); 
	}
}

void PlayFunc(void)
{
		if(WorkFlag&bPlayOvr){
    	
		switch(PlayMode){
			case 0:      //循环
				if((SelIndex+fileindex)>=TotalFile){
			       StopPlay();MenuCnt=0;
			       MenuMode=STBY_MODE;	//歌曲循环完毕
			  	   return;
			  }
			  if(SelIndex<3){
			  	 SelIndex++;
			  }else{
			  	 fileindex++;
			  }
			  StopPlay();
				TotalFile=SerarchFile(CurDir,fileindex);	
				filelength=m_c[SelIndex].FileLen;
 				FindLrcFile(CurDir,m_c[SelIndex].ShortName);
				ClearLcdBuff();
				PrintString(0,0,m_c[SelIndex].LongName);
				StartPlay(m_c[SelIndex].Clust); 
				SetInverseLine(0);
				break;
			case 1:      //重复  
			  StopPlay();
				SerarchFile(CurDir,fileindex);	
				filelength=m_c[SelIndex].FileLen;
				FindLrcFile(CurDir,m_c[SelIndex].ShortName);
				ClearLcdBuff();
				PrintString(0,0,m_c[SelIndex].LongName);
				StartPlay(m_c[SelIndex].Clust); 
				SetInverseLine(0);
				break;
			case 2:      //随机
				break;
			case 3:      //列表
				break;  
			case 4:
				break;    //停止
			};
			WorkFlag&=~bPlayOvr;	
			return;
	}
	switch(KeyVal){
		case kPlay:
					WorkFlag^=bPause;
					break;
		case kVolUp:
			    if(vol<29){
			    	vol++;
					eeprom_write_byte((uchar *)kEepVol,vol);
					eeprom_busy_wait();
			    }else vol=29;	
			    vs1003_cmd_write(0x0b,pgm_read_word(voltbl+vol));
 				 DispVolume();
         break;
		case kVolDown:	
				if(vol>0){
					 vol--;
					 eeprom_write_byte((uchar *)kEepVol,vol);
					 eeprom_busy_wait();
				}else vol=0;	
				 vs1003_cmd_write(0x0b,pgm_read_word(voltbl+vol));
				 DispVolume();
		    	break;
		case kNext:
			 if((fileindex+SelIndex)>=TotalFile)   return;
			 	if(SelIndex<3){
			 		 SelIndex++;
			 	}else{
			  	fileindex++;
			  }
				StopPlay();
				TotalFile=SerarchFile(CurDir,fileindex);	
				if(m_c[SelIndex].Type==0xff){
					fileindex=TotalFile;
					SelIndex=0; 
					break;
				}
				filelength=m_c[SelIndex].FileLen;
 				FindLrcFile(CurDir,m_c[SelIndex].ShortName);
				ClearLcdBuff();
				PrintString(0,0,m_c[SelIndex].LongName);
				StartPlay(m_c[SelIndex].Clust); 
				SetInverseLine(0);
				break;
		case kPrev: 
				if(SelIndex!=0){
					 SelIndex--;
				}else{
					if(fileindex>1)	 
				     fileindex--;
				  else
				  	 break;   
			  }
				StopPlay();
			  SerarchFile(CurDir,fileindex);	
			  filelength=m_c[SelIndex].FileLen;
				FindLrcFile(CurDir,m_c[SelIndex].ShortName);
				ClearLcdBuff();
				PrintString(0,0,m_c[SelIndex].LongName);
				StartPlay(m_c[SelIndex].Clust);
				SetInverseLine(0);
				break; 
		case kStop:  //暂无此按键
			
				 break;		
		case kPlayHold:
			  if(MenuMode==PLAY_MODE){
			  	ClearLcdBuff();
				  MenuMode = VIEW_MODE;
				  MenuCnt=0;	    
				  WorkFlag|=(bPause|bReadOvr); //停止放音
	 		      WorkFlag&=~(bLrc|bDatRdy);	  	
				  vs1003_Reset();
			   }
			   break;				
		default:
				KeyVal =kNull;		  	
	  	};
	  	KeyVal=kNull;

}
void key_port(void)
{
	DDRB &= ~PLAY;
	DDRE &= ~PREVSONG;
	DDRE &= ~NEXTSONG;
	DDRE &= ~VOLDOWN;
	DDRE &= ~VOLUP;
//	PORTE=0XFF;
}

⌨️ 快捷键说明

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