Guest User

Untitled

a guest
Apr 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <inttypes.h>
  2. #include <stdio.h>
  3. #include <avr/io.h>
  4.  
  5. #include "debuguart.h"
  6.  
  7. inline void fulldelay(void)
  8. {
  9.     volatile int i;
  10.     for (i = 0; i < 44; i ++);
  11. }
  12.  
  13. inline void debuguart_high(void)
  14. {
  15.     PORTC |= 1<<PC0;
  16. }
  17.  
  18. inline void debuguart_low(void)
  19. {
  20.     PORTC &= ~(1<<PC0);
  21. }
  22.  
  23. void debuguart_init(void)
  24. {
  25.     DDRC = (1 << DDC0);
  26.     debuguart_high();
  27.  
  28.     /* This is for printf */
  29.     static FILE mystdout =
  30.         FDEV_SETUP_STREAM(debuguart_putchar, NULL, _FDEV_SETUP_WRITE);
  31.     stdout = &mystdout;
  32. }
  33.  
  34. void debuguart_sendbyte(uint8_t c)
  35. {
  36.     /* start bit */
  37.     debuguart_low();
  38.     fulldelay();
  39.  
  40.     if (c & 1) debuguart_high(); else debuguart_low();
  41.     fulldelay();
  42.  
  43.     if (c & 2) debuguart_high(); else debuguart_low();
  44.     fulldelay();
  45.  
  46.     if (c & 4) debuguart_high(); else debuguart_low();
  47.     fulldelay();
  48.  
  49.     if (c & 8) debuguart_high(); else debuguart_low();
  50.     fulldelay();
  51.  
  52.     if (c & 16) debuguart_high(); else debuguart_low();
  53.     fulldelay();
  54.  
  55.     if (c & 32) debuguart_high(); else debuguart_low();
  56.     fulldelay();
  57.  
  58.     if (c & 64) debuguart_high(); else debuguart_low();
  59.     fulldelay();
  60.  
  61.     if (c & 128) debuguart_high(); else debuguart_low();
  62.     fulldelay();
  63.  
  64.     /* parity thingie */
  65.     debuguart_high();
  66.     fulldelay();
  67. }
  68.  
  69. int debuguart_putchar(char c, FILE *stream)
  70. {
  71.     if (c == '\n') {
  72.         debuguart_sendbyte('\r');
  73.     }
  74.     debuguart_sendbyte(c);
  75.     return 0;
  76. }
  77.  
  78. /* vim: set sw=4 et: */
Add Comment
Please, Sign In to add comment