Skip to content

Instantly share code, notes, and snippets.

@electronut
electronut / atmega168-serial.c
Last active December 17, 2015 12:29
ATmega168 serial communications (transmit only) - most code is from the data sheet.
#define BAUD 9600
#define MYUBRR F_CPU/16/BAUD-1
void USART_Init(unsigned int ubrr)
{
/*Set baud rate */
UBRR0H = (unsigned char)(ubrr>>8);
UBRR0L = (unsigned char)ubrr;
/*Enable receiver and transmitter */
UCSR0B = (1<<RXEN0)|(1<<TXEN0);