msp430g2533之uart

好久之前做的,贴上来分享下

#include "msp430g2533.h"
volatile int j;
void UART0_send_byte(unsigned char data)    //发送一位
{
for( j=10000;j>0;j--);
UCA0TXBUF=data;
}


void UART0_send_str(char *s)   //发送字符串
{
    while(*s != '\0')
    {
        UART0_send_byte(*s++);
    }
}


void UART0()
{
DCOCTL = 0;                               // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL |= BIT1 + BIT2 ;                    // P1.1 = RXD, P1.2=TXD
P1SEL2 |= BIT1 + BIT2 ;                   // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2;                     // SMCLK
UCA0BR0 = 104;                            // 1MHz 9600
UCA0BR1 = 0;                              // 1MHz 9600
UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
}
int main()
{
WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
 {
   while(1);                               // do not load, trap CPU!!
 }
UART0();

while(1)
 {
for(j=10000;j>0;j--);
UART0_send_str("hello world!\n");

 }
}

你可能感兴趣的:(嵌入式,msp430)