tabby/avr/uart.c

38 lines
605 B
C
Raw Normal View History

#include <stdio.h>
2016-05-27 15:27:46 -05:00
#include <avr/io.h>
#include <avr/interrupt.h>
#include <tabby/avr/uart.h>
#define F_CPU 16000000UL
#define BAUD TABBY_AVR_UART_BAUD
#include <util/setbaud.h>
void uart_init() {
2016-05-27 15:49:27 -05:00
UBRR1H = UBRRH_VALUE;
UBRR1L = UBRRL_VALUE;
#if USE_2X
2016-05-27 15:49:27 -05:00
UCSR1A |= _BV(U2X1);
#else
2016-05-27 15:49:27 -05:00
UCSR1A &= ~(_BV(U2X1));
#endif
2016-05-27 15:49:27 -05:00
UCSR1C = _BV(UCSZ11) | _BV(UCSZ10);
UCSR1B = _BV(RXEN1) | _BV(TXEN1);
}
void uart_putchar(char c, FILE *fh) {
2016-05-27 15:49:27 -05:00
loop_until_bit_is_set(UCSR1A, UDRE1);
2016-05-27 15:49:27 -05:00
UDR1 = c;
}
char uart_getchar(FILE *fh) {
2016-05-27 15:49:27 -05:00
loop_until_bit_is_set(UCSR1A, RXC1);
2016-05-27 15:49:27 -05:00
return UDR1;
}