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

📄 fatyampp.c

📁 e1c0df5d-c8bc-48a5-bc02-a2b7c51c0dbf是做mp3的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "fatyampp.h"SIGNAL(SIG_INTERRUPT2)				// Need this for wake up from sleep{	asm volatile ("nop");}SIGNAL(SIG_INTERRUPT1)				// remote control key pressed{//	unsigned int ref_count;//	unsigned int remote_key_count;//	cbi(GICR, INT1);		// no further INT1 interrupts during routine/*	cbi(PORTD, PD3);		// disable pullup	sbi(DDRC, PC4);			// decharge cap...	cbi(PORTC, PC4);	delayms(2);	remote_key_count=0;	cbi(PORTC, PC4);	sbi(PORTC, PC4);		// charge cap via PC4 pullup	while (bit_is_clear(PINC, PC4)) remote_key_count++;	// and wait until cap is charged	sbi(DDRC, PC4);	cbi(PORTC, PC4);			// discharge cap	sbi(DDRD, PD3);			// switch PD3 to low to	cbi(PORTD, PD3);		// deactivate button resistor	delayms(2);			// wait until cap discharged	ref_count=0;	cbi(DDRC, PC4);	sbi(PORTC, PC4);		// charge cap via PC4 pullup for reference	while (bit_is_clear(PINC, PC4)) ref_count++;//	remote_key_count = remote_key_count - ref_count;	cbi(DDRD, PD3);			// switch PD3 to input	sbi(PORTD, PD3);		// for interrupt recognition	cbi(DDRC, PC4);			// PC4 as input	cbi(PORTC, PC4);*//*	sbi(DDRE, PD3);	sbi(PORTD, PD3);	delayms(10);	cbi(PORTD, PD3);	cbi(DDRE, PD3);*/#ifdef REMOTE	cli();				// no interuupts during routine	remote_key_count=0;	while (bit_is_clear(PIND, PD3)) remote_key_count++;	if (remote_key_count < 100) remote_key = 1;#if (PLAYER == 1)	if (remote_key_count > 0x9000 ) remote_key=4;						// stop	if (remote_key_count < 0x3fff) remote_key=3;							// ff	if (remote_key_count > 0x6000 && remote_key_count < 0x7fff ) remote_key=2;	// rew#else	if (remote_key_count > 0x4400 && remote_key_count < 0x47ff) remote_key=2;	if (remote_key_count > 0x8800 && remote_key_count < 0x8dff) remote_key=3;	if (remote_key_count > 0xa600 && remote_key_count < 0xaaff) remote_key=4;#endif	if (remote_key == 0) remote_key=5;	sei();				// re-enable interrupts#else	asm volatile ("nop");#endif}SIGNAL(SIG_OVERFLOW1)				// timer interrupt - display, various timers{	outp(TI1_H, TCNT1H);			// reload timer	outp(TI1_L, TCNT1L);	keytime++;	batt_timer++;	if (batt_timer > 20) check_battery();	lcd_upd++;	if (lcd_upd>LCDUPDATEFREQ)	{		update_display();		lcd_upd=0;	}	if (voltimer > 0)	{		voltimer --;		if (voltimer == 0) lcd_clrscr();		lcd_upd++;			// do a more frequent lcd update during volume setting	}	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);	}	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_firmwarew 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(1,1);			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(){	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();	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	wdt_disable();					// disable the watchdog	sei();						// global interrupt enable	cbi(PORTB, RESET_PIN);				// keep VS1001 reset		lcd_off();	outp(0x00, TCCR0);	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);sldo:   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	}	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;	unsigned char *p;	unsigned char ibuf[6];	unsigned int time;	wdt_reset();	lcd_gotoxy(0,0);	if (voltimer)					// are we in volume change?	{		lcd_clrscr();				// yes, display volume bar		lcd_putchar('\n');		lcd_progputs(PSTR("    volume\n"));		lcd_bar(82-(((volume)*82)/(255)), 82);	}	else						// no, normal display	{		// play mode		if (is_playing == PLAY) lcd_progputs(PSTR("play "));		else if (is_playing == PAUSE) lcd_progputs(PSTR("pause"));		else lcd_progputs(PSTR("stop "));		lcd_gotoxy(6, 0);		// status display: loudness, repeat mode, battery state, keylock state		if (loudness)			lcd_invert();		lcd_progputs(PSTR("\x3\x4"));		lcd_normal();				if (playmode>0)		{			lcd_putchar(0x12);			if (playmode == 1)				lcd_putchar(0x17);			else				lcd_putchar(0x18);		}		else			lcd_gotoxy(10,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		{			if (lobatt == 1) lcd_progputs(PSTR("\x8\x9"));			else lcd_progputs(PSTR("\xB\xC"));		}				lcd_putchar(0x05);		if (locked)			lcd_putchar(0x0F);		else			lcd_putchar(0x06);		lcd_putchar('\n');		// ID3 tag / filename scrolling		if (artalbpos < 0)		{			artalbpos = 0;			artalbdir *= -1;		}		if (artalbpos > (strlen(artalb)-14))		{			artalbpos = strlen(artalb)-14;			artalbdir *= -1;		}		if (strlen(artalb) < 14) artalbpos = 0;		if (titlepos < 0)		{			titlepos = 0;			titledir *= -1;		}		if (titlepos > (strlen(filename)-14))		{			titlepos = strlen(filename)-14;			titledir *= -1;		}		if (strlen(filename) < 14) titlepos = 0;		p = artalb + artalbpos;		lcd_puts(p);		lcd_putchar('\n');		p = filename + titlepos;		lcd_puts(p);		lcd_putchar('\n');		// playing progress bar		if (is_playing>=1) lcd_bar(((played*82)/playlength), 82);		else lcd_bar(0, 82);//		if (dircluster != 0)//			lcd_puts(dirname);//		else//		lcd_progputs(PSTR("\n Hallo   "));				// time display		lcd_gotoxy(9, 4);		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_putchar('\n');		lcd_putchar('\n');	}	lcd_update = 0;}void browse_menu(){	char menu_item, first_item;	register int i;	lcd_clrscr();	menu_item = 1;	first_item = 1;	while (cmd != CMD_STOP)	{		wdt_reset();		if (is_playing == PLAY)			playloop();				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:				set_playmode();				break;						case MENU_LOUDNESS:				set_loudness();				break;			case MENU_CONTRAST:				set_contrast();				break;			case MENU_BLIGHT:				set_blight();				break;							case MENU_BLMODE:				set_blmode();				break;							case MENU_AUTOLOCK:				set_autolock();				break;							case MENU_TIMEDISP:				set_timedisp();				break;			}			break;		case CMD_NEXT:			menu_item++;			if (menu_item > MENU_ITEMS) menu_item = MENU_ITEMS;			if (menu_item > 5) first_item = menu_item -4;			break;		case CMD_PREV:			menu_item--;			if (menu_item < 1) menu_item = 1;			if (menu_item < first_item) first_item = menu_item;			break;		}		lcd_gotoxy(0,0);		lcd_progputs(PSTR("     menu\n"));		for (i=first_item; i<(first_item+5); i++)		{			if (i > MENU_ITEMS) break;			if (i == menu_item) lcd_invert();			lcd_progputs(menu+(i-1)*15);			lcd_putchar('\n');			lcd_normal();		}	}	lcd_clrscr();	update_display();}void set_playmode(){	int key;	lcd_clrscr();	lcd_gotoxy(3,1);	lcd_progputs(PSTR("play mode\n"));	lcd_gotoxy(2,3);	lcd_progputs(PSTR("repeat "));	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_NEXT:				if (playmode < 2)					playmode++;				break;						case CMD_PREV:				if (playmode > 0)					playmode--;				break;		}		lcd_gotoxy(9,3);		if (playmode == 0)			lcd_progputs(PSTR("off"));		else if (playmode == 1)			lcd_progputs(PSTR("one"));		else lcd_progputs(PSTR("all"));	}	eeprom_wb(EE_PLAYMODE, playmode);	lcd_clrscr();}void set_loudness(){	int key;	lcd_clrscr();	lcd_gotoxy(3,1);	lcd_progputs(PSTR("loudness\n"));	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_NEXT:				loudness=1;				vs1001_write(VS1001_MODE, 0x0080 * (loudness != 0));				break;						case CMD_PREV:				loudness=0;				vs1001_write(VS1001_MODE, 0x0080 * (loudness != 0));				break;		}		lcd_gotoxy(6,3);		if (loudness == 0)			lcd_progputs(PSTR("off"));		else			lcd_progputs(PSTR("on "));	}	eeprom_wb(EE_LOUDNESS, loudness);	lcd_clrscr();}void set_timedisp(){	int key;	lcd_clrscr();	lcd_gotoxy(1,1);	lcd_progputs(PSTR("time display\n"));	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_NEXT:				timedisp=0;				break;						case CMD_PREV:				timedisp=1;				break;		}		lcd_gotoxy(3,3);		if (timedisp == 1)			lcd_progputs(PSTR("elapsed  "));		else			lcd_progputs(PSTR("remaining"));	}	eeprom_wb(EE_TIMEDISP, timedisp);	lcd_clrscr();}void set_contrast(){	int contrast, key;	lcd_clrscr();	lcd_gotoxy(1,1);	lcd_progputs(PSTR("lcd contrast\n"));	contrast =  eeprom_rb(EE_CONTRAST);	if (contrast < 20 || contrast > 0x58) contrast = 0x40;	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();				// let there be light...		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_VOLUP:				delayms(100);			case CMD_NEXT:				contrast++;				if (contrast > 0x58) contrast = 0x58;				break;			case CMD_VOLDOWN:				delayms(100);			case CMD_PREV:				contrast--;				if (contrast < 0x20) contrast = 0x20;				break;		}		lcd_gotoxy(0, 3);		lcd_bar(((contrast-0x20)*82) / 58, 82);		lcd_contrast(contrast);	}	eeprom_wb(EE_CONTRAST, contrast);	lcd_clrscr();}void set_blight(){	int key;	unsigned char ibuf[2];	lcd_clrscr();	lcd_gotoxy(0,1);	lcd_progputs(PSTR("backlight time\n"));	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_VOLUP:				delayms(100);			case CMD_NEXT:				if (bltime < 20)					bltime++;				break;						case CMD_VOLDOWN:				delayms(100);			case CMD_PREV:				if (bltime > 1)					bltime--;				break;		}		lcd_gotoxy(2,3);		utoa(bltime, ibuf, 10);		lcd_putchar(' ');		lcd_puts(ibuf);		lcd_putchar(' ');		lcd_progputs(PSTR("sec.  "));	}	eeprom_wb(EE_BLTIME, bltime);	lcd_clrscr();}void set_blmode(){	int key;	unsigned char ibuf[2];	lcd_clrscr();	lcd_gotoxy(0,1);	lcd_progputs(PSTR("backlight mode\n"));	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_VOLUP:				delayms(100);			case CMD_NEXT:				if (blmode < 5)					blmode++;				break;						case CMD_VOLDOWN:				delayms(100);			case CMD_PREV:				if (blmode > 0)					blmode--;				break;		}		lcd_gotoxy(1,3);		switch (blmode)		{			case 0:				lcd_progputs(PSTR("     off    "));				break;			case 1:				lcd_progputs(PSTR(" dimmed on  "));				break;			case 2:				lcd_progputs(PSTR("  full on   "));				break;			case 3:				lcd_progputs(PSTR("auto on/off "));				break;			case 4:				lcd_progputs(PSTR("auto dim/off"));				break;			case 5:				lcd_progputs(PSTR("auto on/dim "));				break;		}	}	eeprom_wb(EE_BLMODE, blmode);	lcd_clrscr();}void set_autolock(){	int key;	unsigned char ibuf[2];	lcd_clrscr();	lcd_gotoxy(3,1);	lcd_progputs(PSTR("autolock\n"));	while (key != CMD_PLAY)	{		wdt_reset();		if (is_playing == PLAY)			playloop();		backlight_on();		locktimer = 0;		lcd_upd = 0;		key = get_key();		switch (key)		{			case CMD_VOLUP:				delayms(100);			case CMD_NEXT:				if (locktime < 20)					locktime++;				break;

⌨️ 快捷键说明

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