2009-11-9 AVR echo
This code tested on ATmega16
#include <avr/io.h> #define FOSC 16000000UL #define BAUD 9600 #define MYUBRR FOSC/16/BAUD-1 void USART_Init( unsigned int ubrr) { UBRRH = (unsigned char)(ubrr>>8); UBRRL = (unsigned char)ubrr; UCSRB = (1<<RXEN)|(1<<TXEN); UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0); } int main() { char c; USART_Init( MYUBRR ); while(1) { while ( !(UCSRA & (1<<RXC))){}; c = UDR; while (!(UCSRA & (1<<UDRE))){}; UDR = c; } return 0; }