Skip to content

Instantly share code, notes, and snippets.

/.ino

Created September 20, 2016 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ffd12d2277839bc376325ca2de92b276 to your computer and use it in GitHub Desktop.
Save anonymous/ffd12d2277839bc376325ca2de92b276 to your computer and use it in GitHub Desktop.
#define BAUD 115200UL
#define BAUD_TOL 5
#include <util/setbaud.h>
FILE uart_output;
void uart_init(void) {
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= (1 << U2X0);
#else
UCSR0A &= ~(1 << U2X0);
#endif
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); // 8-bit data
UCSR0B = (1 << RXEN0) | (1 << TXEN0); // enable RX and TX
}
inline void uart_putchar(char c, FILE *) {
loop_until_bit_is_set(UCSR0A, UDRE0);
UDR0 = c;
}
void setup() {
uart_init();
fdev_setup_stream(&uart_output, uart_putchar, NULL, _FDEV_SETUP_WRITE);
fprintf(&uart_output, "Hello, World!\r\n");
}
void loop() {
}
Sketch uses 712 bytes (2%) of program storage space. Maximum is 32,256 bytes.
Global variables use 39 bytes (1%) of dynamic memory, leaving 2,009 bytes for local variables. Maximum is 2,048 bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment