Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <inttypes.h>
- #include <avr/pgmspace.h>
- #include <stdio.h>
- #include "uart.h" // uart.h and uart.c from libnerdkits, unchanged
- char inttohex(uint8_t n)
- {
- switch (n)
- {
- case 0: return '0';
- case 1: return '1';
- case 2: return '2';
- case 3: return '3';
- case 4: return '4';
- case 5: return '5';
- case 6: return '6';
- case 7: return '7';
- case 8: return '8';
- case 9: return '9';
- case 10: return 'A';
- case 11: return 'B';
- case 12: return 'C';
- case 13: return 'D';
- case 14: return 'E';
- case 15: return 'F';
- }
- return 0;
- }
- void tell_uart(uint8_t c)
- {
- uart_write(inttohex((c>>4) & 0x0F));
- uart_write(inttohex(c & 0x0F));
- uart_write(' ');
- uart_write('\'');
- uart_write(c);
- uart_write('\'');
- uart_write('\r');
- uart_write('\n');
- }
- void setup()
- {
- uart_init();
- uart_init();
- FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
- stdin = stdout = &uart_stream;
- }
- /*******************************************************************************
- ******* MAIN FUNCTION **********************************************************
- *******************************************************************************/
- int main()
- {
- setup();
- uint8_t i, k;
- k = i = 0;
- /*printf("TEST"); // doesn't work */
- tell_uart('R');
- tell_uart('e');
- tell_uart('a');
- tell_uart('d'); // Works
- tell_uart('y');
- tell_uart(' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement