blob: 63e5d5c05b8f628c117d3805e5ada7a0daf90aae (
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
32
33
34
35
36
37
38
39
|
#include <avr/io.h>
#include <util/delay.h>
static inline void uart_init();
int main()
{
/* serial */
uart_init();
/* data input */
PORTB &= ~0x0F;
DDRB |= 0x0F;
for (;;)
{
while ((UCSRA & (1 << RXC)) == 0);
PORTB ^= UDR & 0x0F;
while ((UCSRA & (1 << UDRE)) == 0);
UDR = PORTB & 0x0F;
}
return 0;
}
static inline void uart_init()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
UCSRC |= (1 << UCSZ0) | (1 << UCSZ1);
#define BAUD 38400
#include <util/setbaud.h>
UBRRH = UBRRH_VALUE;
UBRRL = UBRRL_VALUE;
#if USE_2X
UCSRA |= (1 << U2X);
#else
UCSRA &= ~(1 << U2X);
#endif
}
|