From 8598bb180745eed4f5b9ca8969bd55bb06d4da5e Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sat, 8 Mar 2025 14:53:48 +0800 Subject: Makefile and UART code. --- uart.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 uart.c (limited to 'uart.c') diff --git a/uart.c b/uart.c new file mode 100644 index 0000000..b2a1b59 --- /dev/null +++ b/uart.c @@ -0,0 +1,33 @@ +#include +#include + +#include "uart.h" + +void uart_init(void) +{ + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; +#if USE_2X + UCSR0A |= (1 << U2X0); +#else + UCSR0A &= ~(1 << U2X0); +#endif + UCSR0B = (1 << TXEN0) | (1 << RXEN0); + UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); +} + +void uart_write(char c) +{ + while (!(UCSR0A & (1 << UDRE0))) + ; + UDR0 = c; +} + +void uart_write_line(const char *s) +{ + for (; *s; s++) + uart_write(*s); + + uart_write('\r'); + uart_write('\n'); +} -- cgit v1.2.3