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