/* * 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(); }
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) { 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(); }
/* * 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); }