#define F_CPU 16000000UL            // required for setbaud & other libraries
#define BAUD 38400UL                // desired baud
#define BAUD_TOL 2                  // desired baud rate tolerance (+/- %)

#include <avr/io.h>
#include <util/setbaud.h>

void USART0_Init(void){

    // Set the BAUD rate

    UBRR0H = UBRRH_VALUE;
    UBRR0L = UBRRL_VALUE;
    #if USE_2X                       // USE_2X defined by setbaud.h based on inputs
    UCSR0A |= (1 << U2X0);
    #else
    UCSR0A &= ~(1 << U2X0);
    #endif

    // Set the Mode & Frame Parameters

    UCSR0C = 0x06;                   // Asynchronous, 8-data, No parity, 1-stop

    // Enable USART0 Transmitter and Receiver

    UCSR0B = (1 << TXEN0) | (1 << RXEN0);

}