Sei sulla pagina 1di 1

#include <avr/io.

h> // HABILITAR LAS ENTRADAS Y SALIDAS DEL MICROCONTROLADOR


// SUBRUTINA QUE CONFIGURA EL USART

int valor;

void configura_usart(void)
{ UBRRH=0X00;// DEFINIMOS UNA VELOCIDAD DE
UBRRL=0X0C;
UCSRA=0X00;
UCSRB=0X18;
UCSRC=0X86;
}

void usart_tx(unsigned char dato)


{
do
{ valor=UCSRA & 0X20;
} while (valor==0x00);
//while(!(UCSRA & (1<<UDRE)));
UDR=dato;
}

int main(void)

{ // CREO UN ARRAY DE CARACTERES


unsigned char dato[35]={'C','O','M','U','N','I','C','A','C','I','O','N',' ',
'S','E','R','I','A','L',13,' ',' ',' ','
','A','S','I','N','C','R','O','N','A',13};

uint8_t pulso; // VARIABLE PARA EL PULSADOR


int i; // CONTADOR
DDRC=0X00; // PUERTO C COMO ENTRADA PARA EL PULSADOR
DDRB=0XFF; //SALIDA PARA EL LED INDICADOR
PORTB=0X00; // INICIAMOS APAGADO LED INDICADOR
configura_usart();// LLAMO A LA SUBRUTINA

while(1)
{
do
{ pulso=PINC & 0X01;
PORTB=0X00;
} while (pulso==0);
do
{ pulso=PINC & 0x01;
PORTB=0XFF;
} while (pulso==1);

for (i=0;i<34;i++)
{
usart_tx(dato[i]);
}
i=0;
}
}

Potrebbero piacerti anche