fork download
  1. #include <avr/io.h>
  2. #include <stdio.h>
  3.  
  4. #include <util/setbaud.h>
  5.  
  6. void uart_init (void)
  7. {
  8. UBRR0H = UBRRH_VALUE;
  9. UBRR0L = UBRRL_VALUE;
  10. #if USE_2X
  11. UCSR0A |= _BV(U2X0);
  12. #else
  13. UCSR0A &= ~(_BV(U2X0));
  14. #endif
  15. UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); /* 8-bit data */
  16. UCSR0B = _BV(RXEN0) | _BV(TXEN0); /* Enable RX and TX */
  17. }
  18.  
  19. int uart_putchar (char c, FILE *stream)
  20. {
  21. loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
  22. UDR0 = c;
  23. return 0;
  24. }
  25.  
  26. FILE uart_output = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
  27.  
  28. int main ()
  29. {
  30. uart_init();
  31. stdout = &uart_output;
  32.  
  33. printf("Hello\n");
  34. }
  35.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:20: fatal error: avr/io.h: No such file or directory
compilation terminated.
stdout
Standard output is empty