Rev 21 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 21 | Rev 73 | ||
|---|---|---|---|
| 1 | #define F_CPU 1000000UL |
1 | #define F_CPU 1000000UL |
| 2 | #define F_BAUD 31250UL |
2 | #define F_BAUD 31250UL |
| 3 | 3 | ||
| 4 | #include <inttypes.h> |
4 | #include <inttypes.h> |
| 5 | #include <string.h> |
5 | #include <string.h> |
| 6 | #include <avr/io.h> |
6 | #include <avr/io.h> |
| 7 | #include <util/delay.h> |
7 | #include <util/delay.h> |
| 8 | #include <stdio.h> |
8 | #include <stdio.h> |
| 9 | 9 | ||
| 10 | static int uart_putchar(char c, FILE *stream); |
10 | static int uart_putchar(char c, FILE *stream); |
| 11 | static int uart_getchar(FILE *stream); |
11 | static int uart_getchar(FILE *stream); |
| 12 | 12 | ||
| 13 | static FILE mystdio = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, |
13 | static FILE mystdio = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, |
| 14 | _FDEV_SETUP_RW); |
14 | _FDEV_SETUP_RW); |
| 15 | 15 | ||
| 16 | static int |
16 | static int |
| 17 | uart_putchar(char c, FILE *stream) |
17 | uart_putchar(char c, FILE *stream) |
| 18 | { |
18 | { |
| 19 | loop_until_bit_is_set(UCSRA, UDRE); |
19 | loop_until_bit_is_set(UCSRA, UDRE); |
| 20 | UDR = c; |
20 | UDR = c; |
| 21 | return 0; |
21 | return 0; |
| 22 | } |
22 | } |
| 23 | 23 | ||
| 24 | static int |
24 | static int |
| 25 | uart_getchar(FILE *stream) |
25 | uart_getchar(FILE *stream) |
| 26 | { |
26 | { |
| 27 | loop_until_bit_is_set(UCSRA, RXC); |
27 | loop_until_bit_is_set(UCSRA, RXC); |
| 28 | return UDR; |
28 | return UDR; |
| 29 | } |
29 | } |
| 30 | 30 | ||
| 31 | void init(void) |
31 | void init(void) |
| 32 | { |
32 | { |
| 33 | // Setup USART for debug channel |
33 | // Setup USART for debug channel |
| 34 | UCSRB = _BV(RXEN)|_BV(TXEN); |
34 | UCSRB = _BV(RXEN)|_BV(TXEN); |
| 35 | UBRRL = (F_CPU / 16 / F_BAUD) - 1; |
35 | UBRRL = (F_CPU / 16 / F_BAUD) - 1; |
| 36 | stdout = &mystdio; |
36 | stdout = &mystdio; |
| 37 | stdin = &mystdio; |
37 | stdin = &mystdio; |
| 38 | } |
38 | } |
| 39 | 39 | ||
| 40 | int main(void) |
40 | int main(void) |
| 41 | { |
41 | { |
| 42 | init(); |
42 | init(); |
| 43 | printf("Hello, World!\n"); |
43 | printf("Hello, World!\n"); |
| 44 | 44 | ||
| 45 | return 0; |
45 | return 0; |
| 46 | } |
46 | } |
| 47 | 47 | ||