#include <avr/io.h>
#include <util/delay.h>

void USART_Transmit( unsigned char data )
{
  /* Wait for empty transmit buffer */
  while ( !( UCSRA & (1<<UDRE)) )
        ;
  /* Put data into buffer, sends the data */
  UDR = data;
}

void USART_Transmit_uInt( unsigned int data ){
	//USART_Transmit((unsigned char)(data >> 24));
	//USART_Transmit((unsigned char)(data >> 16));
	USART_Transmit((unsigned char)(data >> 8));
	USART_Transmit((unsigned char)(data));
}

int main(void){
	DDRA = 0xff;
	PORTA = 0xf0;
	PORTA |= (1<<PA3);
	PORTA &= ~(1<<PA6);
	
	// enable TX (send)
	UCSRB = (1<<TXEN);
	// parity odd (UPM0 and UPM1), 2 stop-bits (USBS), send 8 bits 
	UCSRC = (1<<URSEL)|(1<<UPM1)|(1<<UPM0)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
	// USRR = 19 -> 38400 bps
	UBRRL = 0x19;
	
	unsigned int value=0;
		
	while(1){
		USART_Transmit_uInt(value++);
		_delay_ms(1);
	}
	
	UCSRB = 0x00;
	return 0;
}

