-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
48 lines (35 loc) · 862 Bytes
/
main.c
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
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdint.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "typedef.h"
int main() {
uart_init();
printf("Ready!\n");
for (;;) {
asm("nop");
}
fclose(&uart_str);
return 0;
}
void uart_init(void) {
unsigned char old_sreg = SREG;
cli();
UBRRH = (unsigned char) (USART_SCALED_UBRR >> 8);
UBRRL = (unsigned char) USART_SCALED_UBRR;
SREG = old_sreg;
UCSRB |= (1 << RXEN) | (1 << TXEN);
UCSRC |= (1 << URSEL) | (1 << USBS) | (1 << UCSZ1) | (1 << UCSZ0);
stdin = &uart_str;
stdout = &uart_str;
}
int _uart_rx_char(FILE *stream) {
loop_until_bit_is_set(UCSRA, RXC);
return UDR;
}
int _uart_tx_char(char data, FILE *stream) {
if (data == '\n')
_uart_tx_char('\r', stream);
loop_until_bit_is_set(UCSRA, UDRE);
UDR = data;
}