📄 microyampp.c
字号:
lcd_clrscr(); lcd_gotoxy(0,14); lcd_progputs(name); } while (key != CMD_PLAY) { if (is_playing == PLAY) playloop(); backlight_on(); wdt_reset(); locktimer = 0; lcd_upd = 0; key = get_key(); switch (key) { case CMD_VOLUP: delayms(100); case CMD_NEXT: if (*value < max) (*value)++; break; case CMD_VOLDOWN: delayms(100); case CMD_PREV: if (*value > min) (*value)--; break; } lcd_gotoxy(0,42); if (strings) // don't show stupid numbers if we have strings! { lcd_progputs(strings+((*value)*15)); } else if ((*value == 0) && (value == &locktime)) lcd_progputs(PSTR(" off ")); else if ((min == CONTRAST_MIN) && (max == CONTRAST_MAX)) lcd_contrast(contrast); // apply contrast setting immediately else { utoa(*value, ibuf, 10); if ((value == &bltime) || (value == &locktime)) // times should have a unit... lcd_gotoxy(40, 42); else lcd_gotoxy(56, 42); lcd_puts(ibuf); if ((value == &bltime) || (value == &locktime)) lcd_progputs(PSTR(" sec. ")); } if (value == &loudness) // apply loudness change directly vs1001_write(VS1001_MODE, 0x0080 * (loudness != 0)); } eeprom_wb(eeprom, *value); set_background_image(MENU_IMG); return;}unsigned char get_key(){ const char cmdtbl[4] = {CMD_PLAY, CMD_STOP, CMD_NEXT, CMD_PREV};// const char cmdlongtbl[4] = {0, 0, 0, 0}; const char cmdholdtbl[4] = {CMD_MENU, CMD_OFF, CMD_VOLUP, CMD_VOLDOWN}; unsigned char reskey; reskey = 0; if (lastkey == WAIT_RELEASE) { if (bit_is_set(PINE, PINE0) && bit_is_set(PIND, PIND1) && bit_is_set(PIND, PIND4) && bit_is_set(PIND, PIND5) && (remote_key == 0)) { lastkey = 0; } return (0); } if (lastkey == BUTTON_LOCK) { if (keytime > 3) { if (locked) { locktimer = 0; locked = 0; } else locked = 1; lastkey = WAIT_RELEASE; return (0); } } else if (lastkey != 0) { if (bit_is_set(PINE, PINE0) && bit_is_set(PIND, PIND1) && bit_is_set(PIND, PIND4) && bit_is_set(PIND, PIND5)) { if (keytime > 0 && keytime < 10) reskey = cmdtbl[lastkey-1];// if (keytime > 10 && keytime < 20)// reskey = cmdlongtbl[lastkey-1]; } if ((keytime > 17) || (locked && (keytime > 25)) || (locked && voltimer)) { reskey = cmdholdtbl[lastkey-1]; } } if (voltimer) { if (reskey == CMD_NEXT) reskey = CMD_VOLUP; if (reskey == CMD_PREV) reskey = CMD_VOLDOWN; } if (lastkey == 0) keytime = 0; if (lastkey && voltimer && !reskey) voltimer = 19; lastkey = 0; if (bit_is_clear(PIND, PIND1) && bit_is_clear(PIND, PIND5)) lastkey = BUTTON_LOCK; else { if (bit_is_clear(PINE, PINE0)) lastkey = BUTTON_PLAY; if (bit_is_clear(PIND, PIND4)) lastkey = BUTTON_FF; if (bit_is_clear(PIND, PIND5)) lastkey = BUTTON_REW; if (bit_is_clear(PIND, PIND1)) lastkey = BUTTON_STOP; } if (locked && (reskey != CMD_VOLUP && reskey != CMD_VOLDOWN)) reskey = 0; if (reskey != 0) { locktimer = 0; backlight_on(); } if (reskey == 0 && remote_key != 0) { switch (remote_key) { case 3: reskey = CMD_PREV; break; case 2: reskey = CMD_NEXT; break; case 4: if (is_playing == PLAY) reskey = CMD_STOP; else reskey = CMD_PLAY; break; } lastkey = WAIT_RELEASE; } return reskey;}void play_file(unsigned int startcl, unsigned long length){ if (is_playing == PLAY) return; if (is_playing == PAUSE) { is_playing = PLAY; return; } played = 0; // reset play status vars playcl = startcl; // startcluster of song playlength = length; // how many bytes to play? is_playing = PLAY; // we are playing... vs1001_reset(loudness);}void check_battery(){ unsigned char tmp, tmp1, percent; if (is_playing==PLAY) playloop(); batt_timer = 0; set_cpu_speed(0); // max cpu speed remote_key = 0; sbi(DDRB, PB3); // Pin B3 output sbi(PORTB, PB3); // charge cap delayms(5); TCCR2 = 0; // Timer 2 off sbi(TIFR, TOV2); // clear timer 2 overflow flag TCNT2 = 0; // clear timer 2 value cli(); TCCR2 = 6; // start timer 2, prescaler / 256 cbi(PORTB, PB3); // input & HI-Z cbi(DDRB, PB3); // PB3 comparator input loop_until_bit_is_set(ACSR, ACO); TCCR2 = 0; tmp = TCNT2; sei(); if (is_playing==PLAY) playloop(); // lobatt = tmp; percent = lobatt / 10; tmp1 = (2 * lobatt) / 3; if ((tmp > tmp1 - percent) && ( tmp < tmp1 + percent + 1)) remote_key = 2; // ff tmp1 = lobatt >> 1; if ((tmp > tmp1 - percent) && ( tmp < tmp1 + percent + 1)) remote_key = 3; // rew tmp1 = lobatt / 5; if ((tmp > tmp1 - percent) && ( tmp < tmp1 + percent + 1)) remote_key = 4; // stop / play if ((!remote_key) && (abs(lobatt - tmp) > 1)) lobatt = tmp; // take measure value as reference set_cpu_speed(CLKDIV);}void initialize() // self-explaining, isn't it?{ unsigned int i, ii; unsigned char ibuf[8]; wdt_disable(); outp(0x00, DDRA); // enable pullups on outp(0xFF, PORTA); // CF address port outp(0xFF, DDRC); // CF addres port outp(0xF0, PORTC); // set to high cbi(PORTB,LED_PIN); sbi(DDRB, LED_PIN); // pin PB0 is output for LED or backlight sbi(PORTB,RESET_PIN); // RESET- hi sbi(DDRB, RESET_PIN); // pin PB1 is output, RESET- cbi(PORTB, RESET_PIN); // perform a device reset on the vs1001 delayms(50); sbi(PORTB, RESET_PIN); outp(0xFF,PORTD); outp(0xC0,DDRD); cbi(DDRE, PINE0); sbi(PORTE,PINE0); // pin PE0 is keyboard input, enable pullup cbi(DDRE,PINE1); // set pin as input sbi(PORTE,PINE1); // activate pullup cbi(SFIOR, PUD); //Pullups Enable outp(0x40,ACSR); // enable analog comparator with internal 1.1 V reference outp(0, TCCR1A); outp(4, TCCR1B); // prescaler /256 tPeriod = 32 uS// TCNT1 = (u16)-(F_CPU / 2560); // load counter value outp(TI1_H, TCNT1H); // load counter value hi outp(TI1_L, TCNT1L); // load counter value lo sbi(TIMSK, TOIE1); // enable timer1 interrupt outp(0xff, OCR0); outp((1<<WGM00) | (1 << COM01) | (1 << CS00), TCCR0); // Timer 0 CTC mode, CLK/1 backlight_on(); read_eeprom_settings(); // read settings from eeprom contrast = eeprom_rb(EE_CONTRAST); // get contrast setting from eeprom if (contrast < CONTRAST_MIN || contrast > CONTRAST_MAX) contrast = CONTRAST_DEF; set_cpu_speed(1); #ifdef COLOR lcd_init(); // init lcd... lcd_color(0x00, 0xff); // white on black#else lcd_init(0);#endif lcd_contrast(contrast); // max: 0x58 lcd_clrscr(); vs1001_init_io(); // init vs1001... vs1001_setcomp(F_VS1001); vs1001_reset(loudness); vs1001_vol = 0; // initial volume setting vs1001_setvolume(volume,0); vs1001_nulls(8); send_sinewave_beeps(); i = 5; // sometimes CF doesn't respond properly while (get_disk_parms() && i) // on first attempt { i--; delayms(100); }// if ((i == 0) || (maxsect == 0) || (heads == 0) || (sectors_per_track == 0)) // read cf parameters if ((i == 0) || (maxsect == 0)) // read cf parameters { beep(62,1000); // couldn't get cf params, so power_down(); // good bye... }// ultoa(maxsect, ibuf, 10);// lcd_gotoxy(0,0);// lcd_puts(ibuf);// delayms(3000); // delayms(10); #ifndef MMC CFWriteAdr(CF_SECCOUNT, 2); // Standby Timer to 50 ms CFWriteAdr(CF_STACOM, 0xE3); // execute IDLE CFWaitReady();#endif/* if (bit_is_clear(PIND, PIND4) && bit_is_clear(PIND, PIND5)) // top buttons pressed during reset { lcd_clrscr(); lcd_gotoxy(16,28); lcd_progputs(PSTR("release\n buttons")); while (bit_is_clear(PIND, PIND4) || bit_is_clear(PIND, PIND5)); prepare_flash(); // update the player firmware }*/ dir_finished = 0; // we didn't play the current directory playlistcl = 0xffff; dircluster = (eeprom_rb(EE_DIRCLUSTER) << 8) + eeprom_rb(EE_DIRCLUSTER+1); // which dir are we in? if (dircluster == 0xffff) dircluster = 0; // insane value, set to default actfilenum = get_next_direntry(dircluster, 0, 1, TYPE_M3U, NOID3); // do we have a m3u playlist? if (actfilenum == 0xffff) // no { playlistcl = actfilenum; actfilenum = (eeprom_rb(EE_FILENR) << 8) + eeprom_rb(EE_FILENR+1); // get last played track no from eeprom actfilenum--; if (actfilenum > 512) actfilenum = 0; actfilenum = get_next_direntry(dircluster, actfilenum, 1, TYPE_MP3, DOID3); // fetch the file info } else { playlistdirid = actfilenum; // there's a playlist! playlistcl = filecluster; playlistlength = dirfilesize; playlistptr = 0; // todo: could get that one from eeprom playlistid = 0; }/* if ( actfilenum == 0xffff); { beep(64,3000); power_down(); }*/ lastcmd = CMD_STOP; // some initial values lastkey = 0; keytime = 0; locktimer = 0; locked = 0; remote_key = 0; artalbdir = titledir = 1; artalbpos = titlepos = 0; scrolltimer = SCROLLSPEED; is_playing = 0; // play status sleeptimer = 0; // timer for auto sleep mode lcd_clrscr(); set_background_image(STOP_IMG); // display a fancy image sei(); // global interrupt enable}void set_background_image(unsigned char image){ unsigned int tmpfilenum, i, ii, cci; unsigned int skincluster, rgbcluster, tmpcluster, tmpattrib; unsigned long tmpsize; unsigned char ibuf[4]; tmpcluster = filecluster; // save file parameters tmpattrib = attrib; tmpsize = dirfilesize; tmpfilenum= 0; skincluster = dircluster; // todo: take extra directory for skin bmps while ((tmpfilenum != 0xffff) && strncasecmp_P(filename, back_images+(image-1)*12, strlen(filename))) { tmpfilenum = get_next_direntry(skincluster, tmpfilenum, 1, TYPE_RGB, NOID3); } rgbcluster = filecluster; // get bitmap file cluster filecluster = tmpcluster; // restore data of mp3 file dirfilesize = tmpsize; attrib = tmpattrib; if (tmpfilenum != 0xffff) // bitmap file found { if (is_playing) playloop(); // feed audio data; cci = 0; ReadSector(data+ ((unsigned long) rgbcluster * secpercluster + cci)); lcd_wrcmd(LCD_CMD_MADCTL); lcd_wrdata(MADCTL_VERT_FLIP); lcd_window(0,0,127,127); lcd_wrcmd(LCD_CMD_RAMWR); i = ii = 0; while (ii < 0x4000) { lcd_wrdata(secbuf[i]); i++; ii++; if (i == 512) { wdt_reset(); i = 0; cci++; if (is_playing==PLAY) playloop(); // feed audio data; if ((cci==secpercluster) && ii < 0x4000) // next cluster? { rgbcluster = get_next_cluster(rgbcluster); cci = 0; } if (rgbcluster != 0xffff) ReadSector(data + ((unsigned long) rgbcluster * secpercluster + cci)); // read next sector } } lcd_wrcmd(LCD_CMD_MADCTL); lcd_wrdata(MADCTL_HORIZ);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -