You are on page 1of 2

#define F_CPU 16000000UL

#define BAUD 9600

#define MYUBRR F_CPU/16/BAUD-1

#include <avr/io.h>
#include <util/delay.h>

void USART_Init(unsigned int ubrr);

void USART_Transmit(unsigned char data );

/*unsigned char USART_Receive();


*/
unsigned char X;

int main(void ){

USART_Init(MYUBRR);

while(1){
/*X = USART_Receive();
*/
X = c;
_delay_ms(10);
USART_Transmit(X);

_delay_ms(10);

void USART_Init(unsigned int ubrr){

UBRR0H = (unsigned char)(ubrr>>8);

UBRR0L = (unsigned char)ubrr;

UCSR0A &= ~_BV(U2X0);

UCSR0B = (1<<RXCIE0);

/*Enable transmitter */

UCSR0B = (1<<TXEN0)|(1<<RXEN0);

}
void USART_Transmit(unsigned char data){

/* Wait for empty transmit buffer */

while ( !( UCSR0A & (1<<UDRE0)) );

/* Put data into buffer, sends the data */

UDR0 = data;

/*unsigned char USART_Receive(){


*/
/* Wait for empty transmit buffer */

/*while ( !( UCSR0A & (1<<RXC0)) );


*/
/* Put data into buffer, sends the data */

/*return UDR0;}*/

You might also like