#include #include #include #include "utils.h" #include "bitmanip.h" // USART // Table 20-1 : Baud Rate Calculation #define USART_BAUDRATE 115200 #define BAUD_PRESCALER (DIV_ROUND_CLOSEST(F_CPU, (16 * USART_BAUDRATE)) - 1) // Table 20-8 : Mode Selection (USART Mode SELect) #define ASYNCHRONOUS (0<> 8); // 20.11.5 : UBRRnL and UBRRnH – USART Baud Rate Registers UBRR0L = (unsigned char) BAUD_PRESCALER; UCSR0C |= ASYNCHRONOUS | PARITY_DISABLED | STOP_ONE_BIT | DATA_EIGHT_BIT; // 20.11.4 : set Frame Format UCSR0B |= RECEIVER_DISABLED | TRANSMITTER_ENABLED; // 20.11.3 : enable Receiver and/or Transmitter } void uart_tx(char c) { while (TEST(UCSR0A, UDRE0) == 0); // 20.11.2 : do nothing until UDR emission buffer is empty, if UDREn flag is 1, UCSRnA register is empty UDR0 = (unsigned char) c; // 20.11.1 : Put data into buffer, UDRn – USART I/O Data Register (read and write) } // write Z on serial port, at a 1Hz frequency // `screen /dev/ttyUSB0 115200` int main() { uart_init(); while (1) { uart_tx('Z'); _delay_ms(1000); } }