Subversion Repositories HomeAutomation

Rev

Rev 553 | Go to most recent revision | Blame | Last modification | View Log | SVN | RSS feed

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