Guest User

Untitled

a guest
Jan 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <msp430.h>
  2.  
  3. #include <stdint.h>
  4.  
  5. int main(void)
  6. {
  7. uint16_t n, p;
  8.  
  9. WDTCTL = WDTPW | WDTHOLD;
  10.  
  11. #if 0
  12. BCSCTL1 = CALBC1_1MHZ;
  13. DCOCTL = CALDCO_1MHZ;
  14. BCSCTL2 = SELM_0 | DIVM_0 | DIVS_0; /* MCLK = SMCLK = DCO */
  15.  
  16. UCA0CTL1 |= UCSWRST;
  17. UCA0CTL1 |= UCSSEL_3;
  18.  
  19. UCA0BR1 = 0; /* 1,000,000 / 115200 */
  20. UCA0BR0 = 9;
  21. UCA0MCTL |= UCBRS_1;
  22. #else
  23.  
  24. BCSCTL1 = CALBC1_16MHZ;
  25. DCOCTL = CALDCO_16MHZ;
  26. BCSCTL2 = SELM_0 | DIVM_0 | DIVS_0; /* MCLK = SMCLK = DCO */
  27.  
  28. UCA0CTL1 |= UCSWRST;
  29. UCA0CTL1 |= UCSSEL_3; /* BRCLK = SMCLK */
  30.  
  31. UCA0BR1 = 0; /* 16,000,000 / 115,200 */
  32. UCA0BR0 = 138;
  33. UCA0MCTL |= UCBRS_7;
  34. #endif
  35.  
  36. UCA0CTL1 &= ~UCSWRST;
  37. P1DIR = BIT3 | BIT4 | BIT6 | BIT7;
  38. P1REN = BIT0; /* Pull-up for IR, RXD; pull-down for Flow Control */
  39. P1OUT = BIT0; /* Pull up, serial idle high */
  40. P1SEL = BIT0 | BIT4; /* Timer_A external input, SMCLK output */
  41.  
  42. P1SEL |= BIT1 | BIT2; /* UART */
  43. P1SEL2 |= BIT1 | BIT2;
  44.  
  45. TACTL = TASSEL_0 | MC_2 | TACLR; /* External clock, continuous */
  46.  
  47. p = 0;
  48.  
  49. while(1)
  50. {
  51. n = TAR;
  52. TACTL |= TACLR;
  53.  
  54. if(n != p)
  55. {
  56. P1OUT |= BIT6;
  57. /* Transmit in network byte order, BE */
  58. /* receiver will ntohs() */
  59. #if 1
  60. UCA0TXBUF = (uint8_t)(n >> 8); /* Transmit high byte; let USCI work */
  61. while(UCA0STAT & UCBUSY) /* Wait for high byte transmission */
  62. {
  63. ;
  64. }
  65. #endif
  66. UCA0TXBUF = (uint8_t)(n); /* Transmit low byte */
  67. }
  68. else
  69. {
  70. P1OUT &= ~BIT6;
  71. }
  72.  
  73. __delay_cycles(32);
  74.  
  75. while(UCA0STAT & UCBUSY) /* Wait for USCI to catch up, if it's still not done */
  76. {
  77. ;
  78. }
  79.  
  80. p = n;
  81. }
  82. }
Add Comment
Please, Sign In to add comment