#include "usart.h"
/*
 * usart.c
 *
 * Created: 10.4.2012 13:36:11
 *  Author: Kain
 *
 *  2 stop bity, licha parita, 1200
 */

void USART_init(void)
{
  // Setup the UART baud rate
  UBRRH = (BAUD_RATE_UBRR >> 8);
  UBRRL = (0xff & BAUD_RATE_UBRR);

  // Enable the UART receiver and transceiver
  UCSRB = _BV(RXEN) | _BV(TXEN);
  // Set the frame format : 8 bits data, 2 bit stop, odd parity
  UCSRC = (1<<URSEL)|_BV(UCSZ1) | _BV(UCSZ0) | (1<<UPM1) | (1<<UPM0) | (1<<USBS);
}

void USART_write(uint8_t byte)
{
  while (!(UCSRA & (1 << UDRE)));
  UDR = byte;
}

void USART_writeBytes(uint8_t * data, uint16_t count) {
	while(count--) {
		USART_write(*data++);
	}
}

