//UART Functions //Roger Traylor 11.l6.11 //For controlling the UART and sending debug data to a terminal //as an aid in debugging. #include #include #include #define USART_BAUDRATE 57600 //Compute baudvalue at compile time from USART_BAUDRATE and F_CPU #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 } //****************************************************************** // Usage examples: //uart_puts("."); //uart_puts(" "); //uart_puts("strength = "); //itoa((int)strength, str, 10); //uart_puts(str); //uart_puts(" "); //uart_init(); //uart_putc('\n'); //uart_puts("*****************\n"); //uart_puts("wrote first byte: "); //uart_puts(str); //uart_putc('\n');