Advertisement
Guest User

Hexorg

a guest
Apr 17th, 2011
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <avr/io.h>
  3. #include <inttypes.h>
  4. #include <avr/pgmspace.h>
  5. #include <stdio.h>
  6.  
  7. #include "uart.h" // uart.h and uart.c from libnerdkits, unchanged
  8.  
  9. char inttohex(uint8_t n)
  10. {
  11.     switch (n)
  12.     {
  13.         case 0: return '0';
  14.         case 1: return '1';
  15.         case 2: return '2';
  16.         case 3: return '3';
  17.         case 4: return '4';
  18.         case 5: return '5';
  19.         case 6: return '6';
  20.         case 7: return '7';
  21.         case 8: return '8';
  22.         case 9: return '9';
  23.         case 10: return 'A';
  24.         case 11: return 'B';
  25.         case 12: return 'C';
  26.         case 13: return 'D';
  27.         case 14: return 'E';
  28.         case 15: return 'F';
  29.     }
  30.     return 0;
  31. }
  32.  
  33. void tell_uart(uint8_t c)
  34. {
  35.     uart_write(inttohex((c>>4) & 0x0F));
  36.     uart_write(inttohex(c & 0x0F));
  37.     uart_write(' ');
  38.     uart_write('\'');
  39.     uart_write(c);
  40.     uart_write('\'');
  41.     uart_write('\r');
  42.     uart_write('\n');
  43. }
  44.  
  45. void setup()
  46. {
  47.     uart_init();
  48.     uart_init();
  49.     FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  50.     stdin = stdout = &uart_stream;
  51.    
  52. }
  53.  
  54. /*******************************************************************************
  55. ******* MAIN FUNCTION **********************************************************
  56. *******************************************************************************/
  57. int main()
  58. {
  59.     setup();
  60.     uint8_t i, k;
  61.     k = i = 0;
  62.  
  63.     /*printf("TEST"); // doesn't work */
  64.  
  65.  
  66.     tell_uart('R');
  67.     tell_uart('e');
  68.     tell_uart('a');
  69.     tell_uart('d');  // Works
  70.     tell_uart('y');
  71.     tell_uart(' ');
  72.    
  73.     return 0;
  74. }
Advertisement
RAW Paste Data Copied
Advertisement