#include #include "mystd.h" #include "utils.h" #define BAUD_RATE 115200 #define UBRR_VALUE ((F_CPU / (8UL * BAUD_RATE)) - 1) // uart is 115200 baud rate, 8 bits per word, no parrity and 1 stop bit // 115200 8N1 void uart_init(void) { // Set baud rate UBRR0H = (uint8_t)(UBRR_VALUE >> 8); UBRR0L = (uint8_t)(UBRR_VALUE); UCSR0A |= _BV(U2X0); // Enable transmitter UCSR0B = _BV(TXEN0); // Set frame format: 8 data bits, no parity, 1 stop bit UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); // Set TX (PD1) as output DDRD |= _BV(PD1); } void uart_tx(uint8_t data) { // wait for transmit buffer to be empty while (!(UCSR0A & _BV(UDRE0))) ; // load data into transmit register UDR0 = data; } int main(void) { uart_init(); while (true) { uart_tx('Z'); delay_ms(1000); } }