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

📄 main.c

📁 butterfly MP3源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
				buff_pos=0;		cluster_pos++; // increment for next time	}		// need to send data to mp3?	// send at most the rest of sector in memory.	while (bit_is_set(DREQ_PORT,DREQ_PIN) && (buff_pos<16)){		vs1001_send_32(FAT_buffer+(32*buff_pos++));	}		return;}    /***	handle_mmc*	@param		old status of MMC*	@return		new status of MMC**	Check for MMC  insertion/removal **/uint8 handle_mmc(uint8 MMC_present){	uint16	c;//	uint32  mmc_size=0;//	uint32	nextfile;		#ifdef SW_MMC_IDENTIFY	if (MMC_present == FALSE) {		MMC_Reset();	}	c = (((MMC_Check() & 0xFF00) == 0) ? TRUE : FALSE);	#else	c =  MMC_Detect();			// detect mmc	#endif		if (c && ( MMC_present == FALSE) ){ // mmc just inserted		gPowerSaveTimer=0; // don't time out I just put a card in.				// startup mmc, FAT and find first File		if (!init_mmc_fat()){ // mmc and Fat init okay..			MMC_present = TRUE;			//mmc_size = MMC_Capacity(); // get capacity in Bytes			//PRINT("MMC :");UART_Printfu32(mmc_size); 			//update_LCD();			gLCD_Refresh=TRUE;						if((FAT16_entryMIN==0) && (FAT16_entryMAX==-1)){// NO SONGS!				gMode= MODE_IDLE;				PRINT("NO MP3");EOL();			}else{				gFAT_entry = FAT16_entryMIN;				gMode= MODE_STOP;			}		}					}else if ((c == FALSE) && MMC_present ){	//mmc just removed		//	PRINT("No MMC\t");UART_Printfu16(c);EOL();		//	gFAT_entry=0; // reset FAT to beginning		gMode = MODE_IDLE;		gLCD_Refresh=TRUE;		gFile_good=FALSE;		MMC_present = FALSE;		//update_LCD();		gPowerSaveTimer=0; //don't time out we're changing cards	}	return MMC_present;}   /***	handle_interface	*	@return		none**	Scans for button presses and change activity accordingly**/void 	handle_interface(void){	char c;	uint32 nextfile;	c = getkey(); // get key press	if (c != KEY_NULL){ // check for button press				PRINT("KEY: ");UART_Printfu08(c);EOL();				switch (c){			case KEY_ENTER : 				// change mode.				if (gMode == MODE_PLAY){// currently playing					gMode = MODE_PAUSE; // stop				}else if (gMode == MODE_PAUSE){					if (FAT16_filetype == FILE_TYPE_DIR){						// scan a new directory....						// get lba from fat entry						gSector = FAT_scratch[13];						gSector <<= 8;						gSector += FAT_scratch[14];						gSector <<= 8;						gSector += FAT_scratch[15];						gSector <<= 8;						gSector += FAT_scratch[16];												// check for files and exit on no files(always 2 entries . and ..)						open_Dir(gSector);						//	return;						gFAT_entry = FAT16_entryMIN;											}else{						gMode = MODE_PLAY;					}									}else if (gMode == MODE_STOP){					if (FAT16_filetype == FILE_TYPE_DIR){						// scan a new directory....						// get lba from fat entry						gSector = FAT_scratch[13];						gSector <<= 8;						gSector += FAT_scratch[14];						gSector <<= 8;						gSector += FAT_scratch[15];						gSector <<= 8;						gSector += FAT_scratch[16];												// check for files and exit on no files(always 2 entries . and ..)						open_Dir(gSector);						//	return;						gFAT_entry = FAT16_entryMIN;											}else{						gMode = MODE_PLAY;						cue_file();					}									}else if ((gMode == MODE_IDLE) && gFile_good){					gMode = MODE_STOP;				}								// decoder will have shut down if stream has stoped.				// so we need to  restart				flush_decoder(SOFT_RESET); 				gLCD_Refresh=TRUE;								// TODO: add long short presses.								break;							case KEY_NEXT : // find next file				if (SCAN_JUMPTOSTART && (gFAT_entry==FAT16_entryMAX)){					gFAT_entry=FAT16_entryMIN;					gLCD_Refresh = TRUE;					cue_file();				}else{					nextfile = FAT_getNextSong(gFAT_entry,FAT16_dir_first_cluster);					if(nextfile){// get next song						gFAT_entry = nextfile;						gLCD_Refresh=TRUE;							cue_file();					}				}				break;							case KEY_PREV ://find previous file 				if (SCAN_JUMPTOSTART && (gFAT_entry==FAT16_entryMIN)){					gFAT_entry=FAT16_entryMAX;					gLCD_Refresh = TRUE;					cue_file();				}else{					nextfile = FAT_getPrevSong(gFAT_entry,FAT16_dir_first_cluster);					if(nextfile){// play next song						gFAT_entry = nextfile;						gLCD_Refresh = TRUE;						cue_file();					}				}				break;							case KEY_PLUS:				if (gMode == MODE_PAUSE && (FAT16_filetype != FILE_TYPE_DIR)){ 	// toggle Bass boost					gbass_boost = !gbass_boost;					gLCD_Refresh=TRUE;				}else if(((gMode == MODE_PAUSE) || (gMode == MODE_IDLE))				   && (FAT16_filetype == FILE_TYPE_DIR)	){					// go up a directory?					open_Dir(FAT16_parent_dir_first_cluster);										// no mmc? then go to options				}else if(gMode == MODE_PLAY){ 					// increase the volume					gmusic_vol++;					if (gmusic_vol>9)						gmusic_vol=9;											//PRINT("Volume :");UART_Printfu08(gmusic_vol); EOL();					vs_1001_setvolume(pgm_read_byte(volume_val+gmusic_vol), pgm_read_byte(volume_val+gmusic_vol));					//LCD_Vol(gmusic_vol);					//LCD_puts_f("VOL +",TRUE);					gLCD_Refresh=TRUE;				}				break;							case KEY_MINUS:				if ((gMode == MODE_PAUSE) || (gMode == MODE_IDLE)|| 					(gMode == MODE_STOP)){	// Power OFF					Power_off();				}else {					gmusic_vol--;					if (gmusic_vol>9) // overflow to 255						gmusic_vol=0;											//PRINT("Volume :");UART_Printfu08(gmusic_vol); EOL();					////LCD_puts_f("VOL -",TRUE);					vs_1001_setvolume(pgm_read_byte(volume_val+gmusic_vol), pgm_read_byte(volume_val+gmusic_vol));					gLCD_Refresh=TRUE;				}				break;							default	:	break;		}	}}   /***   update_LCD*	@return		none**	Update the display depending on mode.***/void 	update_LCD(void){	uint16	voltage;	uint8	percentage;	static uint8 vol = -1,mode = -1,second = -1;	static uint16 file = -1;	#ifdef ALPHA	if (gLCD_Refresh){    //  LCD_Blank();						// clear LCD		if (gMode == MODE_PLAY){   			if (file!=(uint16) gFAT_entry) LCD_FileName(FALSE);   			if (mode!=gMode) LCD_Play();   			if (vol !=gmusic_vol) LCD_Vol(gmusic_vol, gbass_boost);   			if (second !=(uint8) gPlayTimeSeconds) LCD_Time(gPlayTimeSeconds);		}else if (gMode == MODE_PAUSE){   			if (file!= (uint16) gFAT_entry) LCD_FileName(FALSE);   			if (mode!=gMode) LCD_Pause();   			if (vol !=gmusic_vol) LCD_Vol(gmusic_vol, gbass_boost);		}else if (gMode == MODE_STOP){   			if (file!= (uint16) gFAT_entry) LCD_FileName(FALSE);   			if (mode!=gMode) LCD_Stop();   			if (vol !=gmusic_vol) LCD_Vol(gmusic_vol, gbass_boost);         		}else if (gMode == MODE_IDLE){		   if (mode!=gMode) {			LCD_Blank();						// clear LCD			LCD_Tester(); 		// Print the welcome screen and info.						//display battery status			voltage = Power_check();			percentage = (voltage-PWR_ABS_MIN_V)*100/(PWR_MAX_V-PWR_ABS_MIN_V);			UART_Printfu08(percentage);			LCD_Battery(percentage);						// revert to filname after seconds 			gDisplayTimeOut=(2*STAT_DISPLAY_TIME)+1;			}		}				mode=gMode;		vol=gmusic_vol;		file= (uint16) gFAT_entry;		second =(uint8) gPlayTimeSeconds;				gLCD_Refresh =FALSE;	}#endif // ALPHA#ifdef NOKIA	if (gLCD_Refresh){	   if ((mode!=gMode) || (file!=(uint16) gFAT_entry)) LCD_Blank(); // clear LCD  		// Always display battery status		voltage = Power_check();		percentage = (voltage-PWR_ABS_MIN_V)*100/(PWR_MAX_V-PWR_ABS_MIN_V);		LCD_Battery(percentage);		if (gMode == MODE_PLAY){            LCD_FileName((file!=(uint16) gFAT_entry));   			LCD_Play();   			LCD_Vol(gmusic_vol, gbass_boost);   			LCD_Time(gPlayTimeSeconds);		}else if (gMode == MODE_PAUSE){     		   LCD_FileName((file!=(uint16) gFAT_entry));   			LCD_Pause();   			LCD_Vol(gmusic_vol, gbass_boost);            LCD_Time(gPlayTimeSeconds);		}else if (gMode == MODE_STOP){   			LCD_FileName((file!=(uint16) gFAT_entry));   			LCD_Stop();   			LCD_Vol(gmusic_vol, gbass_boost);         		}else if (gMode == MODE_IDLE){			LCD_Tester(); 		// Print the welcome screen and info.						// revert to filname after seconds 			gDisplayTimeOut=(2*STAT_DISPLAY_TIME)+1;					}      		mode=gMode;		vol=gmusic_vol;		file= (uint16) gFAT_entry;		second =(uint8) gPlayTimeSeconds;				gLCD_Refresh =FALSE;	}#endif // NOKIA}/***   main*	@return		int (never returns)**	The guts.**/int 	main(void) {	uint8	MMC_present,j;		/********************************	* 		Initialize 	********************************/	init_HW(); // Do hardware Initialization.	gMode=MODE_IDLE;	gLCD_Refresh=TRUE;   update_LCD();        // Hack to make sure NOKIA screen displayed b4 scanning MMC   gLCD_Refresh=TRUE;   	MMC_present = restore_player(); // Restore saved position.	gPowerSaveTimer =0;		/********************************	* 		Main Loop 	********************************/	while (1)	{			// check for button press		handle_interface();					// update lcd		update_LCD();		// check for MMC removal or insertion.		MMC_present = handle_mmc(MMC_present);				if (MMC_present){			// check mode ie playing idle sleep nommc			if(gMode == MODE_PLAY){ 				// keep streaming if mp3 decoder can take it 				// (up to 4 sectors at a time).				j=4;				while (bit_is_set(DREQ_PORT,DREQ_PIN) && j--)					streaming();			}else{				Power_idle();				if (gPowerSaveTimer >= AUTOPOWEROFF_TIMEOUT)					Power_off();			}		}		else{			Power_idle();			if (gPowerSaveTimer >= AUTOPOWEROFF_TIMEOUT)				Power_off();		}	}	return 0;}

⌨️ 快捷键说明

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