Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430.h>
- #include <stdint.h>
- int main(void)
- {
- uint16_t n, p;
- WDTCTL = WDTPW | WDTHOLD;
- #if 0
- BCSCTL1 = CALBC1_1MHZ;
- DCOCTL = CALDCO_1MHZ;
- BCSCTL2 = SELM_0 | DIVM_0 | DIVS_0; /* MCLK = SMCLK = DCO */
- UCA0CTL1 |= UCSWRST;
- UCA0CTL1 |= UCSSEL_3;
- UCA0BR1 = 0; /* 1,000,000 / 115200 */
- UCA0BR0 = 9;
- UCA0MCTL |= UCBRS_1;
- #else
- BCSCTL1 = CALBC1_16MHZ;
- DCOCTL = CALDCO_16MHZ;
- BCSCTL2 = SELM_0 | DIVM_0 | DIVS_0; /* MCLK = SMCLK = DCO */
- UCA0CTL1 |= UCSWRST;
- UCA0CTL1 |= UCSSEL_3; /* BRCLK = SMCLK */
- UCA0BR1 = 0; /* 16,000,000 / 115,200 */
- UCA0BR0 = 138;
- UCA0MCTL |= UCBRS_7;
- #endif
- UCA0CTL1 &= ~UCSWRST;
- P1DIR = BIT3 | BIT4 | BIT6 | BIT7;
- P1REN = BIT0; /* Pull-up for IR, RXD; pull-down for Flow Control */
- P1OUT = BIT0; /* Pull up, serial idle high */
- P1SEL = BIT0 | BIT4; /* Timer_A external input, SMCLK output */
- P1SEL |= BIT1 | BIT2; /* UART */
- P1SEL2 |= BIT1 | BIT2;
- TACTL = TASSEL_0 | MC_2 | TACLR; /* External clock, continuous */
- p = 0;
- while(1)
- {
- n = TAR;
- TACTL |= TACLR;
- if(n != p)
- {
- P1OUT |= BIT6;
- /* Transmit in network byte order, BE */
- /* receiver will ntohs() */
- #if 1
- UCA0TXBUF = (uint8_t)(n >> 8); /* Transmit high byte; let USCI work */
- while(UCA0STAT & UCBUSY) /* Wait for high byte transmission */
- {
- ;
- }
- #endif
- UCA0TXBUF = (uint8_t)(n); /* Transmit low byte */
- }
- else
- {
- P1OUT &= ~BIT6;
- }
- __delay_cycles(32);
- while(UCA0STAT & UCBUSY) /* Wait for USCI to catch up, if it's still not done */
- {
- ;
- }
- p = n;
- }
- }
Add Comment
Please, Sign In to add comment