34 lines
557 B
C
34 lines
557 B
C
#include <stdio.h>
|
|
|
|
#include <tabby/avr/uart.h>
|
|
|
|
#define F_CPU 16000000UL
|
|
#define BAUD TABBY_AVR_UART_BAUD
|
|
|
|
#include <util/setbaud.h>
|
|
|
|
void uart_init() {
|
|
UBRR0H = UBRRH_VALUE;
|
|
UBRR0L = UBRRL_VALUE;
|
|
|
|
#if USE_2X
|
|
UCSR0A |= _BV(U2X0);
|
|
#else
|
|
UCSR0A &= ~(_BV(U2X0));
|
|
#endif
|
|
|
|
UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
|
|
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
|
|
}
|
|
|
|
void uart_putchar(char c, FILE *fh) {
|
|
loop_until_bit_is_set(UCSR0A, UDRE0);
|
|
|
|
UDR0 = c;
|
|
}
|
|
|
|
char uart_getchar(FILE *fh) {
|
|
loop_until_bit_is_set(UCSR0A, RXC0);
|
|
|
|
return UDR0;
|
|
}
|