sysprog-basic/include/uart.c

35 lines
753 B
C

#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++);
}
char uart_getc() {
while (UCSR0A & (1 << RXC0));
return UDR0;
}