//UART Functions for Mega 48 only //Roger Traylor 12.7.15 //For controlling the UART and sending debug data to a terminal as an aid //in debugging. Note that RX and TX lines are marked relative to the device //they are located on. #include #include #include //F_CPU is set in makefile, don't set it here. #define USART_BAUDRATE 9600 #define BAUDVALUE ((F_CPU/(USART_BAUDRATE * 16UL)) - 1 ) #include char uart_tx_buf[40]; //holds string to send to crt char uart_rx_buf[40]; //holds string that recieves data from uart //****************************************************************** // uart_putc // // Takes a character and sends it to USART0 // void uart_putc(char data) { while (!(UCSR0A&(1<>8 ); //load upper byte of the baud rate into UBRR UBRR0L = BAUDVALUE; //load lower byte of the baud rate into UBRR } //****************************************************************** //****************************************************************** // uart_getc //Modified to not block indefinately in the case of a lost byte // char uart_getc(void) { uint16_t timer = 0; while (!(UCSR0A & (1<= 16000){ return(0);} //what should we return if nothing comes in? //return the data into a global variable //give uart_getc the address of the variable //return a -1 if no data comes back. } // Wait for byte to arrive return(UDR0); //return the received data } //******************************************************************