#include <avr/io.h>

void usart1_setup_ver1(void)
{ // TX enable | RX enable
 UCSR1B = (1<<TXEN1) | (1<<RXEN1);
 // parity none, 1 stop bit, 8 data
 UBRR1H = 0;  // 38400 bps at 16MHz
 UBRR1L = 25;
}

int usart1_getc_ver1(void)
{
  while( (UCSR1A & (1<<RXC1))==0 );
 return UDR1;
}

int usart1_putc_ver1(char data)
{
 while( (UCSR1A & (1<<UDRE1))==0 );
 UDR1 = data;
 return data;
}

char message0[]="Type 50 characters to echo\r\n=>";
char message1[]="\r\n---- repeat ----\r\n";
//////////////////////////////////////////////////////////////
int main(void)
{
 int  i;
 char cc;
 
 usart1_setup_ver1();

 while(1){
  for(i=0; i<sizeof(message0); i++)
   usart1_putc_ver1( message0[i] );
   
  for(i=0; i<50; i++){
   cc = usart1_getc_ver1();
   usart1_putc_ver1(cc);
  }

  for(i=0; i<sizeof(message1); i++)
   usart1_putc_ver1( message1[i] );
 }
}

