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

📄 microyampp.c

📁 e1c0df5d-c8bc-48a5-bc02-a2b7c51c0dbf是做mp3的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "microyampp.h"SIGNAL(SIG_INTERRUPT2)				// Need this for wake up from sleep{	asm volatile ("nop");}SIGNAL(SIG_OVERFLOW1)				// timer interrupt - display, various timers{	outp(TI1_H, TCNT1H);			// reload timer	outp(TI1_L, TCNT1L);	keytime++;	batt_timer++;	lcd_upd++;	if (voltimer > 0)	{		voltimer --;	}	if (is_playing == 0)		sleeptimer++;	else		sleeptimer = 0;	if (scrolltimer > 0)		scrolltimer--;	else	{		scrolltimer = SCROLLSPEED;		artalbpos += artalbdir;		titlepos += titledir;		chganim++;		if (chganim > 5) chganim = 0;	}	if (blmode > 2) bltimer++;	if (((bltimer > (bltime*10)) && (blmode > 2)) || (blmode == 0))	{		if ((blmode == 0) || (blmode == 3) || (blmode == 4)) outp(0x00, OCR0);		else outp(0x3a, OCR0);//		cbi(PORTB, LED_PIN);	}	if ((locked == 0) && (locktime > 0))	{		locktimer++;		if ((locktimer > (locktime*10)) && (is_playing >= 1))		{//			locked = 1;			locktimer = 0;		}	}}/****************************************************** this routine prepares the firmware flash process* it locates the file firmware.bin and writes the* clusters from this file to array artalb* then flash_firmware is called to do the* actual firmware update*****************************************************//*void prepare_flash(){	unsigned int cc;	unsigned char ibuf[6];	cli();				// no interrupts, please!	actfilenum = 0;	while (actfilenum != 0xffff)	{		actfilenum = get_next_direntry(0, actfilenum, 1, TYPE_ANY, NOID3);		if (strncmp_P(filename, PSTR("firmware.bin"), 12) == 0)		{			lcd_clrscr();			lcd_gotoxy(8,14);			lcd_progputs(PSTR("please stand\n   by while\n   updating\n   firmware\n"));			cc=0;			while ((cc*secpercluster*512) < 16384)			{				artalb[2*cc]=(unsigned char) (filecluster & 0xff);				artalb[(2*cc)+1]=(unsigned char) (filecluster >> 8);				cc++;				filecluster = get_next_cluster(filecluster);			}			delayms(1000);			wdt_disable();			// disable watchdog during firmware update			beep(65, 500);			flash_firmware();			break;				// well...never coming back here...		}	}}*/void backlight_on(){//	sbi (PORTB, LED_PIN);	if ((blmode == 2) || (blmode == 3) || (blmode == 5)) outp(0xff, OCR0);	if ((blmode == 1) || (blmode == 4)) outp(0x80, OCR0);	bltimer = 0;}void power_down(){	send_sinewave_beeps();	outp(0, TCCR1B);				// stop timer1	lcd_off();	outp(0x00, TCCR0);	write_eeprom_data();				// save various settings	sbi(ACSR,ACD);                       		// Disable Analog Comparator	cbi(EMCUCR, ISC2);				// falling edge for INT2	sbi(GICR,INT2);			 		// enable external interrupt 2	cbi(PORTB, RESET_PIN);				// keep VS1001 reset		cbi(PORTB, LED_PIN);	cbi(CHARGE_PORT,CHARGE_PIN);			// disable pullup on charge input	cbi(DDRE,CHARGE_PIN);				// and switch to input for no current	outp(0x00,PORTA);	outp(0xff,DDRA);				// PORTA Output and LOW	outp(0xE0,PORTC);	outp(0xE0, DDRC);		wdt_disable();					// disable the watchdog	sei();						// global interrupt enablesldo:	lastcmd = SLEEP;	outp(0x30,MCUCR);				// enable deep sleep mode and disable	cbi(MCUCSR, SM2);				// select power down mode	cbi(EMCUCR, SM0);	outp(0, TCCR1B);				// stop timer1	asm volatile("sleep");				// Enter to Sleep mode	asm volatile("nop");	// wakeup going here	outp(0x20,MCUCR);				// enable idle mode	outp(4, TCCR1B);	keytime = 0;	while(keytime < 30)	{		asm volatile("sleep");			// Enter to idle mode		asm volatile("nop");		if bit_is_set(PINE,PINE0)		// Play key pressed ?			goto sldo;			// No, go to deep sleep again	}	lastcmd = 0;	outp(0xF0,PORTC);	outp(0x00,PORTA);	sbi(PORTB, RESET_PIN);				// VS1001 reset off	delayms(2);	wdt_enable(1);	while (1);					// reset player by watchdog}void update_display(){	char i, contrast, x;	unsigned char *p;	unsigned char ibuf[SCRLEN_MAX+1];	unsigned int time;	register unsigned char tmp;	if (lastcmd == CMD_STOP) return;		if (is_playing == PLAY)		playloop();		set_cpu_speed(0);				// max speed for lcd update	lcd_gotoxy(0,0);	lcd_color(0x00,0xff);	// status display: loudness, repeat mode, battery state, keylock state//	if (loudness)//	lcd_progputs(PSTR("\x3\x4"));	/*			if (playmode>0)	{		lcd_putchar(0x12);		if (playmode == 1)			lcd_putchar(0x17);		else			lcd_putchar(0x18);	}	else		lcd_gotoxy(80,0);	*/// recharging...//	if (bit_is_clear(PINE, PINE1))//	{//		if (chganim % 2) lcd_progputs(PSTR("\xB\xC"));//		else lcd_progputs(PSTR("  "));//		backlight_on();//	}//	else	// battery status//	{			tmp = (lobatt - 105) >> 1;		////		if (tmp < 1)//			lcd_progputs(PSTR("\x8\x9"));                 // low battery signs//		else		{			lcd_gotoxy(60,0);			itoa(lobatt,ibuf,10);			lcd_puts(ibuf);//			lcd_progputs(PSTR("\xB\xC"));                 // good battery signs//			lcd_wrcmd(0x40);                // ypos = 5//			lcd_wrcmd(0xBF);                // xpos = 57 pixel (0xb9)//			for( i=10; i > tmp ; i-- )//				lcd_wrdata(0x22);       // empty accu//			if(i < 10 && i > 3)//			{//				lcd_wrdata(0x3E);//				lcd_wrdata(0x3E);//			}//			lcd_wrcmd(0xC8);                // xpos = 67 pixel		}//	}	//	lcd_putchar(0x05);//	if (locked)//		lcd_putchar(0x0F);//	else//		lcd_putchar(0x06);//	lcd_putchar('\n');	// ID3 tag / filename scrolling	if  (is_playing==PLAY)		playloop();		if (artalbpos < 0)	{		artalbpos = 0;		artalbdir *= -1;	}	if (artalbpos > (strlen(artalb)-SCRLENART))	{		artalbpos = strlen(artalb)-SCRLENART;		artalbdir *= -1;	}	if (strlen(artalb) < SCRLENART) artalbpos = 0;	if (titlepos < 0)	{		titlepos = 0;		titledir *= -1;	}	if (titlepos > (strlen(filename)-SCRLENFILE))	{		titlepos = strlen(filename)-SCRLENFILE;		titledir *= -1;	}	if (strlen(filename) < SCRLENFILE) titlepos = 0;	if (is_playing==PLAY)			// feed audio data		playloop();		lcd_color(0xff,0x00);		// black on white	ibuf[SCRLENART]='\0';	p = artalb + artalbpos;	strncpy(ibuf, p, SCRLENART);	lcd_gotoxy(ARTALB_X, ARTALB_Y);	for (i=0; i<SCRLENART; i++) lcd_putchar(' ');  // clear line	x = 4;		if  (is_playing==PLAY)			// this is frequently needed for high bitrates...		playloop();			if (strlen(ibuf)<SCRLENART)		x = 64- (strlen(ibuf) / 2) * 8;	lcd_gotoxy(ARTALB_X, ARTALB_Y);	lcd_puts(ibuf);			p = filename + titlepos;	strncpy(ibuf, p, SCRLENFILE);	lcd_gotoxy(FILENAME_X, FILENAME_Y);	for (i=0; i<SCRLENFILE; i++) lcd_putchar(' ');  // clear line	x = 8;	if (strlen(ibuf)<SCRLENFILE)		x = 64- (strlen(ibuf) / 2) * 8;	lcd_gotoxy(FILENAME_X, FILENAME_Y);	lcd_puts(ibuf);	if  (is_playing==PLAY)		playloop();		lcd_color(0x00,0xff);		// white on black	lcd_gotoxy(PLAYBAR_X, PLAYBAR_Y);	// playing progress bar	if (is_playing>=1) 		lcd_bar((unsigned int) PLAYBAR_LENGTH << 8 | ((played*PLAYBAR_LENGTH)/playlength), (unsigned int) 0x4f << 8 | 0);	else 		lcd_bar((unsigned int) PLAYBAR_LENGTH << 8, (unsigned int) 0x4f << 8 | 0);	if (dircluster != 0)	{		lcd_gotoxy(64-(strlen(dirname) / 2) * 8,DIRNAME_Y);		lcd_puts(dirname);	}		// time display	lcd_gotoxy(TIME_X, TIME_Y);	if (is_playing==PLAY)		playloop();//	if (eeprom_rb(EE_TIMEDISP) == 0)//		time = (dirfilesize - played) / (file_bitrate * 8 * 125);//	else		time = played / (file_bitrate * 8 * 125);	utoa(time/60, ibuf, 10);	if ((time/60)<10) lcd_putchar('0');	lcd_puts(ibuf);	lcd_putchar(':');	utoa(time % 60, ibuf, 10);	if ((time % 60) < 10) lcd_putchar('0');	lcd_puts(ibuf);	lcd_update = 0;	set_cpu_speed(CLKDIV);				// cpuspeed / 2}void browse_menu(){	char menu_item, first_item, do_update;	register int i;		if (is_playing == PLAY)			playloop();					// feed audio data	set_cpu_speed(0);					// max cpu speed	set_background_image(MENU_IMG);	menu_item = 1;	first_item = 1;	do_update = 1;	while (cmd != CMD_STOP)	{		wdt_reset();		backlight_on();		locktimer = 0;					// prevent auto-lock while in menu		lcd_upd = 0;					// suppress normal lcd display		cmd = get_key();		switch (cmd)		{		case CMD_PLAY:			switch (menu_item)			{		        case MENU_PLAYMODE:				do_update = 1;				set_parameter(0, 2, &playmode, PSTR("   playmode   "), playmode_a, EE_PLAYMODE);//				set_playmode();				break;						case MENU_LOUDNESS:				do_update = 1;				set_parameter(0, 1, &loudness, PSTR("   loudness   "), NULL, EE_LOUDNESS);				break;			case MENU_CONTRAST:				do_update = 1;				contrast = eeprom_rb(EE_CONTRAST);				if (contrast < CONTRAST_MIN || contrast > CONTRAST_MAX) contrast = CONTRAST_DEF;				set_parameter(CONTRAST_MIN, CONTRAST_MAX, &contrast, NULL, NULL, EE_CONTRAST);				break;			case MENU_BLIGHT:				do_update = 1;				set_parameter(1, 20, &bltime, PSTR("backlight time"), NULL, EE_BLTIME);				break;							case MENU_BLMODE:				do_update = 1;				set_parameter(0, 5, &blmode, PSTR("backlight mode"), blmode_a, EE_BLMODE);				break;							case MENU_AUTOLOCK:				do_update = 1;				set_parameter(0, 20, &locktime, PSTR("autolock  time"), NULL, EE_LOCKTIME);				break;							case MENU_TIMEDISP:				do_update = 1;				set_parameter(0, 1, &timedisp, PSTR(" time display "), timedisp_a, EE_TIMEDISP);				break;			}			break;		case CMD_NEXT:			do_update = 1;			menu_item++;			if (menu_item > MENU_ITEMS) menu_item = MENU_ITEMS;			if (menu_item > MENU_SHOW) first_item = menu_item -6;			break;		case CMD_PREV:			do_update = 1;			menu_item--;			if (menu_item < 1) menu_item = 1;			if (menu_item < first_item) first_item = menu_item;			break;		}				if (is_playing == PLAY)			playloop();		if (do_update)		// redraw menu		{			set_cpu_speed(0);				// max cpu speed			for (i=first_item; i<(first_item+MENU_SHOW); i++)			{				lcd_gotoxy(MENU_X, MENU_Y+((i-first_item) * 14));				if (i > MENU_ITEMS) break;				if (i == menu_item) lcd_color(0xe0,0xff);				else lcd_color(0x00, 0xff);				lcd_progputs(menu+(i-1)*15);			}			do_update = 0;		}	}	if (lastcmd != CMD_STOP)		set_background_image(PLAY_IMG);	else		set_background_image(STOP_IMG);							// display a fancy image	update_display();}void set_parameter(unsigned char min, unsigned char max, unsigned char * value, PGM_P name, PGM_P strings, unsigned int eeprom){	int key;	unsigned char ibuf[2];	if ((min == CONTRAST_MIN) && (max == CONTRAST_MAX))		set_background_image(CONTRAST_IMG);	else	{

⌨️ 快捷键说明

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