SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <msp430.h>
  2. #include <legacymsp430.h>
  3. #include <inttypes.h>
  4.  
  5. #include "debuguart.h"
  6.  
  7. #define DEBUGUART_TXD BIT1
  8. #define DEBUGUART_BAUD 9600
  9.  
  10. void fulldelay()
  11. {
  12.     //__delay_cycles(16 * 100);
  13.     __delay_cycles(F_CPU / DEBUGUART_BAUD);
  14. }
  15.  
  16. void halfdelay()
  17. {
  18.     //__delay_cycles(16 * 100 / 2);
  19.     __delay_cycles(F_CPU / DEBUGUART_BAUD / 2);
  20. }
  21.  
  22. inline void debuguart_high(void)
  23. {
  24.     P1OUT |= DEBUGUART_TXD;
  25. }
  26.  
  27. inline void debuguart_low(void)
  28. {
  29.     P1OUT &= ~(DEBUGUART_TXD);
  30. }
  31.  
  32. void debuguart_init(void)
  33. {
  34.     P1DIR |= DEBUGUART_TXD;
  35.     debuguart_high();
  36. }
  37.  
  38. void debuguart_sendbyte(uint8_t c)
  39. {
  40.     /* start bit */
  41.     debuguart_low();
  42.     fulldelay();
  43.  
  44.     if (c & 1) debuguart_high(); else debuguart_low();
  45.     fulldelay();
  46.  
  47.     if (c & 2) debuguart_high(); else debuguart_low();
  48.     fulldelay();
  49.  
  50.     if (c & 4) debuguart_high(); else debuguart_low();
  51.     fulldelay();
  52.  
  53.     if (c & 8) debuguart_high(); else debuguart_low();
  54.     fulldelay();
  55.  
  56.     if (c & 16) debuguart_high(); else debuguart_low();
  57.     fulldelay();
  58.  
  59.     if (c & 32) debuguart_high(); else debuguart_low();
  60.     fulldelay();
  61.  
  62.     if (c & 64) debuguart_high(); else debuguart_low();
  63.     fulldelay();
  64.  
  65.     if (c & 128) debuguart_high(); else debuguart_low();
  66.     fulldelay();
  67.  
  68.     /* parity thingie */
  69.     debuguart_high();
  70.     fulldelay();
  71. }
  72.  
  73. /* vim: set sw=4 et: */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top