/* * uart.h * * Created on: 14-May-2014 * Author: Harman */ #include #ifndef UART_H_ #define UART_H_ #define FOSC 4000000 //function to enable uart at specified baud rate void enable_uart(uint16_t BAUD) { UCSRA = (1 << U2X); UBRRH = (unsigned char) ((FOSC / 8 / BAUD - 1) >> 8); UBRRL = (unsigned char) (FOSC / 8 / BAUD - 1); UCSRB = (1 << RXEN) | (1 << TXEN); UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0); } //function to disable uart and flush the UDR register void disable_uart() { UCSRB &= ~((1 << RXEN) | (1 << TXEN)); } //function to send the data to uart void sendchar_uart(char c) { while (!(UCSRA & (1 << UDRE))); UDR = c; while (!(UCSRA & (1 << TXC))); UCSRA |= (1 << TXC); } //function to receive data from uart uint8_t getchar_uart() { // Wait until a byte has been received while (!(UCSRA & (1 << RXC))); UCSRA |= (1 << RXC); // Return received data return UDR; } void sendstring_uart(char v[]) { int i; for(i=0;i