From 2bd45f076ea7eb429bfee54fe1de240ff4b284e6 Mon Sep 17 00:00:00 2001 From: brett Date: Tue, 23 Apr 2024 20:51:02 -0500 Subject: should be finished, backing up --- final_project/serial.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 final_project/serial.c (limited to 'final_project/serial.c') diff --git a/final_project/serial.c b/final_project/serial.c new file mode 100644 index 0000000..bb5b58f --- /dev/null +++ b/final_project/serial.c @@ -0,0 +1,39 @@ +/* + * CFile1.c + * + * Created: 4/3/2024 10:21:26 AM + * Author: bsw9xd + */ +#include "serial.h" + +void usart_init() { + volatile int ubrr = (F_CPU / (16UL * BAUD)) - 1; //TODO: why is this volatile int??? + UCSR1A = 0; //async normal communication + UCSR1B = (1 << TXEN) | (1 << RXEN); + UCSR1C = (1 << UCSZ0) | (1 << UCSZ1); + + + UBRR1H = (unsigned char)(ubrr << 8); + UBRR1L = (unsigned char)ubrr; +} +void usart_txt(char data) { //transmit data + UDR1 = data; //buffer the data + while(~UCSR1A & (1 << TXC)); //wait until the transmission is complete + UCSR1A |= (1 << TXC); + +} +char usart_rxt() { + if(UCSR1A & (1 << RXC)) { + return UDR1; + } + return '\0'; +} + +char usart_rxt_blocking() { //TODO maybe replace usart_txt + while(!(UCSR1A & (1 << RXC))); //TODO simplify + return UDR1; +} + +void usart_txstr(char *str) { + for(int i = 0; str[i] != '\0'; i++) usart_txt(str[i]); +} -- cgit v1.2.3