#include #include #include #include "uart.h" #define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) #define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) #define BAUD_ERROR ((BAUD_REAL*1000)/BAUD) #if ((BAUD_ERROR<990) || (BAUD_ERROR>1010)) #error Choose another crystal. Baud error too high. #endif static void (*recv_handler)(unsigned char c) = NULL; ISR(USART_RX_vect) { cli(); if(recv_handler) recv_handler(UDR); sei(); } void uart_init() { // Enable receive and transmit UCSRB = (1<> 8; UBRRL = UBRR_VAL & 0xFF; } void uart_set_recv_handler(void (*handler)(unsigned char c)) { recv_handler = handler; } void uart_putc(const char c) { while ( !(UCSRA & (1<