-
-
Save anonymous/ffd12d2277839bc376325ca2de92b276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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