djc
Advanced Member level 1
#define USART_BAUDRATE 9600
#define F_CPU 8000000UL
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL ))) - 1)
void usart_init(){
UCSRB |= (1<<RXCIE) | (1<<RXEN) | (1<<TXEN); //Turn on reception circuitry
UCSRC |= (1<<URSEL) | (1<<UCSZ0) | (1<<UCSZ1); //Use 8 bit character sizes
UBRRL = BAUD_PRESCALE; //
UBRRH = (BAUD_PRESCALE >>8);
}
unsigned int usart_getch(){
while((UCSRA & (1<<RXC)) == 0); // DO nothing until data have been received and is ready to be read
return (UDR);
}
This is the part of the code. Copied from one of the websites. Is this configuration ok?