void main() { uchar *p; p="by Jasper"; Init(); IsReset=0; IsReset=eeprom_read(100); if(!IsReset) //首次进入输入密码和显示欢迎界面 { Confirm(); LCD_clear(); delay_ms(200); LCD_write_str(5,0,"welcome"); while(*p) { LCD_write_char(i,1,*p); p++; i++; delay_ms(100); } } LCD_clear(); //正式进入系统 LCD_write_str(0,0,"1bell2led3motor"); LCD_write_str(0,1,"4fix_password"); while(1) { eeprom_write(100,0); if(select=='1') //蜂鸣器模式 { LCD_clear(); LCD_write_str(0,0,"buzz..send * or"); LCD_write_str(0,1,"shutdown to exit"); Bell(); } if(select=='2') LED(); //led模式 if(select=='3') Motor(); //电机模式 if(select=='4') Write_password(); //修改密码模式 } }
LCD_value0(INT8U x,INT8U y,FP32 f) { INT8U str[8]; //不能定义为 char* str,数组长度一定要大于浮点数的总位数 sprintf(str,"%.0f",f); //1 表示小数位数 小数太多 自动四舍五入 LCD_write_str( x, y, str); return 0; }
/*led*/ void LED() { uchar left=0x01; uchar right=0x80; LCD_clear(); LCD_write_str(0,0,"led.."); LCD_write_str(0,2,"1(2):control"); while(1) { Driver_595(left,right); if(select=='2') { LCD_write_str(6,0,"MODE:2"); left<<=1; right>>=1; } else {
static THD_FUNCTION(ThreadLCD, arg) { (void) arg; chRegSetThreadName("ThreadLCD"); int delay = 700; i2c_init(); liquid_crystal_t lcd; LCD_init(&lcd, delay_ms, write, 4, 4); LCD_backlight_on(&lcd); while (1) { LCD_clear(&lcd); LCD_write_str(&lcd, "Hello world!"); chThdSleepMilliseconds(delay); } }
void display_volume(){ // Assume vol is two digits char buf[2]; uint8_t i; i = vol; buf[1] = i%10 + '0'; buf[0] = i/10 + '0'; // clear screen LCD_write(RS_ADDR, 0x01); if(i == 0){ LCD_write_str("Mute",LCD_DDRAM_LINE1_ADDR+6); }else{ LCD_write_nstr(buf,2,LCD_DDRAM_LINE1_ADDR+7); } LCD_write(RS_ADDR,LCD_DDRAM_LINE2_ADDR+3); while(i-- > 0) LCD_write(RS_DATA,255); }
void LCD_alignment(int16_t str, uint8_t adress) { uint8_t buffer[] = {' ',' ',' ',' '}; itoa(str, buffer, 10); if (str < 0) { if (str > (-10)) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } else if (str > (-100)) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } else if (str >(-1000)) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } else if (str <=(-1000)) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } } else { if (str < 10) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } else if (str < 100) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } else if (str < 1000) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } else if (str >= 1000) { kursor_adress(adress); LCD_write_str(buffer); LCD_write_str(" "); } } }
void GUI_Thread (void const *argument) { /** This GUI makes the assumes that, during operation, the SD card will not be removed and the contects of the SD card will not be changed. It also assumes that all of mp3 files are on the top dir and there's subdirs are not supported. */ osEvent sig; uint32_t spin_delay = 0, lcd_timeout = 0; // get the list of mp3s len = get_files("", &cur_fp); // see if there's at least one song if (cur_fp != NULL) { // if so, display the song display_stats(); } else { // otherwise display an error msg and quit LCD_write_str("<No Songs Found>", LCD_DDRAM_LINE1_ADDR); LCD_write_str("MP3 Halted :( ", LCD_DDRAM_LINE2_ADDR); return; } while(1) { // check if the player is done playing sig = osSignalWait(GUI_SIG_NEXT, 0); if ( (sig.status == osEventSignal) && (sig.value.signals & GUI_SIG_NEXT) ) { if (cur_fp->next != NULL) { ++count; cur_fp = cur_fp->next; display_stats(); if (GUI_Status == GUI_STATUS_PLAYING) { PLAYER_PLAY(cur_fp->fname); cur_song = cur_fp->fname; } } else { sta_stop(); GUI_Status = GUI_STATUS_STOPPED; } // emulate a button press so the screen would light up btn_pressed = 1; } /* light up the screen if any of the buttons were pressed */ if (btn_pressed) { // light up the screen PWM1->_2_CMPB = LCD_PWM_HIGH; // reset timeout lcd_timeout = 0; btn_pressed = 0; if(vol_btn_pressed){ display_volume(); vol_displayed = 1; vol_btn_pressed = 0; }else{ display_stats(); vol_displayed = 0; } } // assume lcd_timeout is longer than vol_timeout else if (lcd_timeout == VOL_DELAY) { // switch to song screen // Also default display to song if(vol_displayed){ display_stats(); vol_displayed = 0; } } else if (lcd_timeout == DELAY_MUL) { // timeout, so we dimm the screen PWM1->_2_CMPB = LCD_PWM_LOW; } ++lcd_timeout; // will take a while before uint32_t rolls over /* spin animation */ if (GUI_Status == GUI_STATUS_PLAYING) { if (spin_delay == SPIN_SPD) { spin_index = (spin_index + 1) % 4; spin_delay = 0; } else { ++spin_delay; } } if(!vol_displayed){ display_song(); LCD_write_nstr_f((char*)&spin_str[spin_index], 1, LCD_DDRAM_LINE1_ADDR+LCD_MAX_WIDTH-1); } osDelay(GUI_DELAY); } }