sysprog-basic/include/uart.c

36 lines
776 B
C
Raw Normal View History

2023-12-09 11:27:55 +01:00
#include "uart.h"
void uart_init() {
/* This make stuff not work, idk
// set baud rate
UBRR0H = (MYUBRR>>8);
UBRR0L = MYUBRR;
*/
/* Enable receiver and transmitter */
UCSR0B |= (1<<RXEN0) | (1<<TXEN0);
/* Set frame format: 8data, 2stop bit */
UCSR0C |= (1<<UCSZ01)|(3<<UCSZ00);
//Lokales interrupt enable
UCSR0B |= (1 << RXCIE0);
}
void uart_printc(char c) {
/* Wait for empty transmit buffer */
while ( !( UCSR0A & (1<<UDRE0)) )
{
// wartet nur
}
/* Put data into buffer, sends the data */
UDR0 = c;
}
void uart_prints(char* s) {
while(*s)
uart_printc(*s++);
uart_printc('\n');
}
char uart_getc() {
while (UCSR0A & (1 << RXC0));
return UDR0;
}