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

📄 mp3_player_06.c

📁 MP3源码 内有SD2.0 驱动 FAT32 驱动
💻 C
字号:
/*****************************************************/
/*                mp3 player V2.1                                                   */
/* Description : A mp3 player support lrc sd & U disk                 */
/* Platform     : AVRStudio4.13 + WinAVR20070525  m64        */
/* Author       : Michael Zhang - 章其波                            */
/* Email         : sudazqb@163.com                                          */
/* MSN          : zhangqibo_1985@hotmail.com                          */
/* Date          : 2007-11-03                                                    */
/* NOT FOR COMMERCIAL USE,     ALL RIGHT RESERVED!         */
/*****************************************************/

/*********************  old  ***************************/
/*                   MP3/Wma/Midi播放器                      */
/*  环境WinAVR 20060421                                      */
/*  作者:Bozai(章其波)                                    */
/*  E-mail:sudazqb@163.com                                  */
/*  2006年12月12日                                           */
/*************************************************************/
/*  20080308: rearrange the file, rewrite the key process (use interrupt) & volume*/
/*  20080205: a bug fixed(about lyric search, name comparision error )  */
/*  20071211: add low battery indication & remove all uart output, add message for sara ye */
/*  20071210: modify code for zl0801's mp3 PCB */
/*  20071122: add teminal control code                                   */
/*  20071121: solve glitch problem when playing 320Kbps files            */
/*  20071109: add & modify function for any directory music file playing */
/*  20071103: add function for lyric display                             */

#include"sys_config.h"
//#include"IDE/IDE.h"

uint8 HanziEnable = 0;	/* Gloable variable to indicate wether the firmware are exist, and 1 means exist */

extern struct direntry MusicInfo;	/* Music file information, 32Bytes short directory record, contain the short name and others */
//extern struct direntry LrcInfo;	/* lyric file information, 32Bytes short directory record, the short name and others */


void (*BootLoaderEntry)(void) = 0xf800;	/* boot loader entry, bootloader size: 2048Bytes */

extern uint16 totalsongs;	/* total number of songs*/
extern uint8 type;			/* current song's file type, mp3 wma mid or wav */

volatile uint8 key_count;

volatile uint8 key_value;

	
//Timer initialization offer seed of the srandom()
void Timer1_Initial()
{
	key_value = 0;
	key_count = 0;
	TCNT1H=0x00;
	TCNT1L=0x00;
	TCCR1A=0x00;
	TCCR1B=0x01;
	TIMSK |= 1<<TOIE1;
 	sei();
}


SIGNAL(TIMER1_OVF_vect)
{
	//TCCR1B = 0;
	//printf_P(PSTR("\r\nvalue = %x"),key_value);
	if((key_value&KEY_VALID) ==0)
	{
		//printf_P(PSTR("\r\nkey not valid"));
		if((PINE&(STOP|MODE|NEXT|PREV|UP|DOWN)) == (STOP|MODE|NEXT|PREV|UP|DOWN))
		{
			//printf_P(PSTR("\r\nno key pressed"));
			if(key_value&KEY_LONG)
			{
				key_value = 0;
			}
			else if((key_value&KEY_PRESEED) && (key_count>KEY_VALID_TIME))
			{
				//printf_P(PSTR("\r\nkey released"));
				key_value |= KEY_RELEASED;
				key_value |= KEY_VALID;
				key_count = 0;
			}
			else
			{
				key_value = 0;
				key_count = 0;
			}
		}
		else if(key_value&KEY_PRESEED)
		{
			//printf_P(PSTR("\r\nkey used preseed"));
			if(key_count == KEY_LONG_TIME)
			{
				//printf_P(PSTR("\r\nlong key prseed"));
				key_value |= KEY_LONG|KEY_VALID;
				key_count= 0;
			}
			if((key_value&KEY_LONG)==0)
			{
				key_count++;
			}
		}
		else
		{
			if((PINE&STOP)!=STOP)
			{
				//printf_P(PSTR("\r\nstop key first pressed"));
				key_value = KEY_STOP;
				key_value |= KEY_PRESEED;
			}
			else if((PINE&MODE)!=MODE)
			{
				//printf_P(PSTR("\r\nmode key first pressed"));
				key_value = KEY_MODE;
				key_value |= KEY_PRESEED;
			}
			else if((PINE&NEXT)!=NEXT)
			{
				//printf_P(PSTR("\r\nnext key first pressed"));
				key_value = KEY_NEXT;
				key_value |= KEY_PRESEED;
			}
			else if((PINE&PREV)!=PREV)
			{
				//printf_P(PSTR("\r\nprev key first pressed"));
				key_value = KEY_PREV;
				key_value |= KEY_PRESEED;
			}
			else if((PINE&UP)!=UP)
			{
				//printf_P(PSTR("\r\nV+ key first pressed"));
				key_value = KEY_UP;
				key_value |= KEY_PRESEED;
			}
			else if((PINE&DOWN)!=DOWN)
			{
				//printf_P(PSTR("\r\nV- key first pressed"));
				key_value = KEY_DOWN;
				key_value |= KEY_PRESEED;
			}

		}
	}
	//TCCR1B = 0x01;
}


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;

	COM_Initial(MYUBRR);
	
	VS1003B_Init();

	lcdInit();

	Timer1_Initial();


	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\n --by 章其波\n按开始键继续"));
		lcdUpdateDisplay();
             
		HanziEnable = 1;
	}


	while(1)
	{
		if(key_value & KEY_VALID)
		{
		#if STOP_KEY
			if((key_value&KEY_VALUE_MASK) == KEY_STOP)
		#else
			if((key_value&KEY_VALUE_MASK) == KEY_MODE)
		#endif
			{
				key_value = 0;
				break;
			}
			else key_value = 0;
		}
	}


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