#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

unsigned char word=0x00;

ISR(USART_TXC_vect)
{
 cli();
/*---------------------------*/
 while(!(UCSRA&(1<<UDRE)));
 UDR=word; 
 
/*---------------------------*/
 sei();
}

int main(void)
{
 /*Port C - buttons*/
 DDRC=0x00;
 PORTC=0xFF;

 /*Port B - control LEDs*/
 DDRB=0xFF;
 PORTB=0x00; 

 /*Speed: 9600 BOD*/
 UBRRH=0;
 UBRRL=51;

 /*Inicial UCSRA*/
 UCSRA=0x00;

 /*UCSRB*/
 UCSRB=0x00;
 UCSRB=(1<<TXCIE)|(1<<TXEN);

 /*UCSRC: 8 bit; 2 stop-bit*/
 UCSRC=(1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);

 while(!(UCSRA&(1<<UDRE)));
 UDR=word;

 sei();

 while(1)
 {
   if((PINC&(1<<PC0))==0) word|=(1<<0);
   else word&=~(1<<0);

   if((PINC&(1<<PC1))==0) word|=(1<<1);
   else word&=~(1<<1);

   if((PINC&(1<<PC2))==0) word|=(1<<2);
   else word&=~(1<<2);

   PORTB=word;
   _delay_ms(100);
 }

 return 0;
}
