#include // register definitions #include // storing data in program memory #include // interrupt vectors #include // delay functions #include // C header for int types like uint8_t #include // C header for the bool type #include #include // Include stuff from the library #include "lib/iopins.h" #include "lib/usart.h" #include "lcd.h" #include "onewire.h" // Pins #define LED 13 #define OW_PIN D9 void _lcd_wait_bf(); void _lcd_write_byte(uint8_t bb); #if 0 // UART receive handler ISR(USART_RX_vect) { // "ECHO" function: uint8_t b = usart_rx(); usart_tx(b); // send back } #endif void main() { #if 0 usart_init(BAUD_115200); usart_isr_rx_enable(true); // enable RX interrupt handler #endif // configure pins as_output(LED); lcd_init(); lcd_clear(); lcd_puts(""); // globally enable interrupts (for the USART_RX handler) sei(); uint8_t addr[8]; char charbuf[21]; int dots = 0; while (1) { bool signal = ow_reset(OW_PIN); if (!signal) { lcd_clear(); lcd_puts("No 1-Wire detected..."); dots = 0; } else { ow_write(OW_PIN, 0x33); ow_read_arr(OW_PIN, addr, 8); lcd_clear(); char *p = charbuf; for(uint8_t i = 0; i < 4; i++) { p += sprintf(p, "%02X", addr[i]); if (i < 3) *p++ = ':'; } lcd_puts(charbuf); lcd_xy(0, 1); p = charbuf; for(uint8_t i = 0; i < 4; i++) { p += sprintf(p, "%02X", addr[4+i]); if (i < 3) *p++ = ':'; } lcd_puts(charbuf); ds1820_single_measure(OW_PIN); uint16_t cels = ds1820_read_temp_c(OW_PIN); if (cels == 850) { lcd_xy(12, 0); for(uint8_t i = 0; i <= dots; i++) { lcd_putc('.'); } dots = (dots+1)%3; } else { p = charbuf; p += sprintf(p, "%d", cels/10); *p++ = '.'; p += sprintf(p, "%d", cels%10); *p++ = 0xDF; *p++ = 'C'; *p++ = 0; lcd_xy(12, 0); lcd_puts(charbuf); } } pin_toggle(13); // blink the LED _delay_ms(100); } }