blob: 1a9956d53e11134d924d9b4d5f9edfd44d9a5814 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <avr/io.h>
#include <util/setbaud.h>
#include "uart.h"
void uart_init(void)
{
UBRR0H = UBRRH_VALUE;
UBRR0L = UBRRL_VALUE;
#if USE_2X
UCSR0A |= (1 << U2X0);
#else
UCSR0A &= ~(1 << U2X0);
#endif
UCSR0B = (1 << TXEN0) | (1 << RXEN0);
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
}
uint8_t uart_recv(void)
{
while (!(UCSR0A & (1 << RXC0)))
;
return UDR0;
}
void uart_send(uint8_t c)
{
while (!(UCSR0A & (1 << UDRE0)))
;
UDR0 = c;
}
|