/* * Setup the LCD controller. First, call the hardware initialization * function, then adjust the display attributes we want. */ void lcd_init(void) { hd44780_init(); /* * Clear the display. */ hd44780_outcmd(HD44780_CLR); hd44780_wait_ready(); /* * Entry mode: auto-increment address counter, no display shift in * effect. */ hd44780_outcmd(HD44780_ENTMODE(1, 0)); hd44780_wait_ready(); /* * Enable display, activate non-blinking cursor. */ hd44780_outcmd(HD44780_DISPCTL(1, 1, 0)); hd44780_wait_ready(); }
/* * Send character c to the LCD display. After a '\n' has been seen, * the next character will first clear the display. */ int lcd_putchar(char c, FILE *unused) { static bool nl_seen; if (nl_seen && c != '\n') { /* * First character after newline, clear display and home cursor. */ hd44780_wait_ready(); hd44780_outcmd(HD44780_CLR); hd44780_wait_ready(); hd44780_outcmd(HD44780_HOME); hd44780_wait_ready(); hd44780_outcmd(HD44780_DDADDR(0)); nl_seen = false; } if (c == '\n') { nl_seen = true; } else { hd44780_wait_ready(); hd44780_outdata(c); } return 0; }
void lcd_putString(char* string, char length) { char i; hd44780_outcmd(string[0]); //first byte delivered is the cursor position 0x80 line 1, 0xC0, line 2 for(i = 1; i < length; i++) lcd_putchar(string[i]); }
int main() { hd44780_init(); /* * Clear the display. */ hd44780_outcmd(HD44780_CLR); hd44780_wait_ready(1); // long wait /* * Entry mode: auto-increment address counter, no display shift in effect. */ hd44780_outcmd(HD44780_ENTMODE(1, 0)); hd44780_wait_ready(0); /* * Enable display, activate non-blinking cursor. */ hd44780_outcmd(HD44780_DISPCTL(1, 1, 0)); hd44780_wait_ready(0); EICRA = (1 << ISC00); EIMSK = (1 << INT0); sei(); while (1) { while (!update_needed) sleep_mode(); update_needed = 0; char buffer[16]; hd44780_outcmd(HD44780_CLR); hd44780_wait_ready(1); // long wait hd44780_outcmd(HD44780_DDADDR(4)); hd44780_wait_ready(0); sprintf(buffer, "%2d:%02d:%02d", hour, minute, second); char *s = buffer; while (*s) { hd44780_outdata(*s++); hd44780_wait_ready(0); } } }
/* * Initialize the LCD controller. * * The initialization sequence has a mandatory timing so the * controller can safely recognize the type of interface desired. * This is the only area where timed waits are really needed as * the busy flag cannot be probed initially. */ void hd44780_init(void) { SET(DDR, HD44780_RS); SET(DDR, HD44780_RW); SET(DDR, HD44780_E); ASSIGN(DDR, HD44780_D8, 0xFF); _delay_ms(150); /* 40 ms needed for Vcc = 2.7 V */ hd44780_outbyte(HD44780_FNSET(1, 0, 0), 0); _delay_ms(41); hd44780_outbyte(HD44780_FNSET(1, 0, 0), 0); _delay_ms(1); hd44780_outbyte(HD44780_FNSET(1, 0, 0), 0); _delay_us(370); hd44780_outcmd(HD44780_FNSET(1, 1, 0)); hd44780_wait_ready(false); hd44780_outcmd(HD44780_DISPCTL(0, 0, 0)); hd44780_wait_ready(false); }
/** Inicjalizacja urządzeń wejścia / wyjścia. */ void ioinit(void) { uint8_t i; hd44780_init(); hd44780_outcmd(HD44780_CLR); hd44780_wait_ready(); hd44780_outcmd(HD44780_ENTMODE(1, 0)); hd44780_wait_ready(); hd44780_outcmd(HD44780_DISPCTL(1, 1, 1)); hd44780_wait_ready(); hd44780_outcmd(HD44780_CGADDR(0)); for(i=0; i<64; i++) { hd44780_outdata(pgm_read_byte(&extraChar[i])); } TCCR1B = _BV(WGM12) | _BV(CS11); // licznik / 8 - wyzerwoanie na porownanie TIMSK = _BV(OCIE1A); // przerwanie na porownanie wartosci OCR1A = TAU1; // warto licznika porownania usart_init(UBRR_VALUE); onewire_init(); twi_init(); outputs_init(); top_off_init(); qbuttons_init(); ui_init(); BUZZER_DDR |= _BV(BUZZER_SWITCH); buzzer_off(); wdt_enable(WDTO_2S); }
/* * Initialize the LCD controller. * * The initialization sequence has a mandatory timing so the * controller can safely recognize the type of interface desired. * This is the only area where timed waits are really needed as * the busy flag cannot be probed initially. */ void hd44780_init(void) { DDRB = 0xFF; // Data port out DDRD = 0xF2; // (comment was obsolete) _delay_ms(15); /* 40 ms needed for Vcc = 2.7 V */ hd44780_outcmd(HD44780_FNSET(1, 0, 0)); _delay_ms(4.1); hd44780_outcmd(HD44780_FNSET(1, 0, 0)); _delay_ms(0.1); hd44780_outcmd(HD44780_FNSET(1, 0, 0)); hd44780_outcmd(HD44780_FNSET(1, 1, 0)); hd44780_wait_ready(); hd44780_outcmd(HD44780_FNSET(1, 1, 0)); hd44780_wait_ready(); hd44780_outcmd(HD44780_DISPCTL(0, 0, 0)); hd44780_wait_ready(); }
/** Główna funkcja programu */ int main(void) { FuncPtr FPtr; ioinit(); hd44780_clear(); hd44780_bl_on(); hd44780_cursor_off(); load_basic_settings(EEPROM_BASIC_SETTINGS_BEGIN); load_temp_sensors_settings(EEPROM_TEMP_SETTINGS_BEGIN); load_outputs_settings(EEPROM_OUTS_SETTING_BEGIN); load_timers_settings(EEPROM_TIMERS_SETTING_BEGIN); load_timersv_settings(EEPROM_TIMERSV_SETTING_BEGIN); load_topoff_settings(EEPROM_TOPOFF_SETTINGS_BEGIN); hd44780_printOnLcdDelay(PSTR(PROGRAM_FULL_NAME)); hd44780_clear(); sei(); rtc_get_time(); rtc_get_date(); gui_client_present(); log_write_record(LOG_EVENT_START,0,0,0); for (;;) { wdt_reset(); qbuttons_process(); ui_key_pressed(); if (key_pressed && alarms_notification_enabled() && alarms_is_active() ){ alarms_block_notification(); menu_set(1,1,0,0); key_pressed = NONE; } //########################### akcje wykonywane kiedy minie sekunda if (SF(FLAG_SECOND_PAST)) { SSF(FLAG_FORCE_LCD_REFRESH); temp_counter++; top_off_check_time(); top_off_process(); CSF(FLAG_SECOND_PAST); } //########################### akcje wykonywane kiedy minie pół sekundy if (SF(FLAG_HALF_SECOND_PAST)) { SSF(FLAG_FORCE_LCD_SEMI_REFRESH); if (alarms_is_active() && alarms_notification_enabled()) { buzzer_toggle(); } else { buzzer_off(); } CSF(FLAG_HALF_SECOND_PAST); } //######################################## odświeżenie wyswietlacza LCD if (system_flags & LCD_REFRESH_MASK) { //if (back_light_counter < LCD_BL_SHUTOFF_TIME) { hd44780_bl_on(); } FPtr=(FuncPtr)pgm_read_word(&FuncPtrTable[menu_func_index()]); hd44780_outcmd(HD44780_HOME); FPtr(); menu_dummy(); CSF(FLAG_FORCE_LCD_REFRESH); CSF(FLAG_FORCE_LCD_SEMI_REFRESH); } //########################### akcje wykonywane kiedy minie minuta if (SF(FLAG_MINUTE_PAST)) { //if (back_light_counter < 0xFF) { back_light_counter++; } //if (back_light_counter >= LCD_BL_SHUTOFF_TIME) { hd44780_bl_off(); } timers_process(); timersv_process(); if (alarms_block_notification_counter < ALARM_MAX_BLOCK_VALUE) { alarms_block_notification_counter++; } CSF(FLAG_MINUTE_PAST); } //########################### akcje wykonywane kiedy minie godzina if (SF(FLAG_HOUR_PAST)) { temp_register(); CSF(FLAG_HOUR_PAST); } //########################### akcje wykonywane jak minie dzień if (SF(FLAG_DAY_PAST)) { rtc_get_time(); rtc_get_date(); CSF(FLAG_DAY_PAST); } //########################### pomiar temeratury if (temp_counter > TEMP_SENSOR_READ_INTERVAL) { temp_read_temperature(); temp_counter = 0; } //######################################## obsługa interfejsu szeregowego gui_cm_process_char(); //######################################## aktualizacja stanu wyjść outputs_update(); } return 0; }
void lcd_clear() { hd44780_outcmd(HD44780_CLR); hd44780_wait_ready(); }