serial.c 513 Bytes
#include <avr/io.h>

#define CPU_FREQ 16000000L

void init_serial(int speed){
	UBRR0 = CPU_FREQ/(((unsigned long int)speed)<<4)-1; //Set baud rate
	UCSR0B = (1<<TXEN0 | 1<<RXEN0); //Enable transmitter & receiver
	UCSR0C = (1<<UCSZ01 | 1<<UCSZ00); //Set 8 bits character and 1 stop bit
	UCSR0A &= ~(1 << U2X0); //Set off UART baud doubler
}
void send_serial(unsigned char c){
	loop_until_bit_is_set(UCSR0A, UDRE0);
	UDR0 = c;
}
unsigned char get_serial(void){
	loop_until_bit_is_set(UCSR0A, RXC0);
	return UDR0;
}