2016-05-25 23:44:21 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-05-27 15:27:46 -05:00
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
|
2016-05-25 23:44:21 -05:00
|
|
|
#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;
|
2016-05-25 23:44:21 -05:00
|
|
|
|
|
|
|
#if USE_2X
|
2016-05-27 15:49:27 -05:00
|
|
|
UCSR1A |= _BV(U2X1);
|
2016-05-25 23:44:21 -05:00
|
|
|
#else
|
2016-05-27 15:49:27 -05:00
|
|
|
UCSR1A &= ~(_BV(U2X1));
|
2016-05-25 23:44:21 -05:00
|
|
|
#endif
|
|
|
|
|
2016-05-27 15:49:27 -05:00
|
|
|
UCSR1C = _BV(UCSZ11) | _BV(UCSZ10);
|
|
|
|
UCSR1B = _BV(RXEN1) | _BV(TXEN1);
|
2016-05-25 23:44:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uart_putchar(char c, FILE *fh) {
|
2016-05-27 15:49:27 -05:00
|
|
|
loop_until_bit_is_set(UCSR1A, UDRE1);
|
2016-05-25 23:44:21 -05:00
|
|
|
|
2016-05-27 15:49:27 -05:00
|
|
|
UDR1 = c;
|
2016-05-25 23:44:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
char uart_getchar(FILE *fh) {
|
2016-05-27 15:49:27 -05:00
|
|
|
loop_until_bit_is_set(UCSR1A, RXC1);
|
2016-05-25 23:44:21 -05:00
|
|
|
|
2016-05-27 15:49:27 -05:00
|
|
|
return UDR1;
|
2016-05-25 23:44:21 -05:00
|
|
|
}
|