#include "serial.h" // File device stream for uart FILE uart_str = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW); volatile char serial_rx_index; // Buffer to hold received string volatile char serial_rx_buffer[16]; // Flag for ready when return entered volatile char serial_rx_ready; // Save character volatile char serial_rx_char; // Position in the serial_tx_buffer volatile char serial_tx_index; // Buffer to hold transmitting string volatile char serial_tx_buffer[16]; // Flag for ready once transmission is complete volatile char serial_tx_ready; // Current character to send volatile char serial_tx_char; /**** * Handle receiving ****/ ISR (USART0_RX_vect) { // Save received character serial_rx_char = UDR0; // Echo UDR0 = serial_rx_char; // Build the input string switch(serial_rx_char) { case '\r': // Hit return // Send newline putchar('\n'); // Null-terminate serial_rx_buffer[(int)serial_rx_index] = 0x00; // Set receive ready serial_rx_ready = 1; // Turn off interrupt until needed again UCSR0B &= ~(1< 0) { putchar(serial_tx_buffer[0]); UCSR0B |= (1<