#include <msp430x14x.h>/* For UART0 serial port configuration, and Operation function Description *//* First, UART0 initialization */ voidUart0_idev_init (void) {P3sel |= BIT4 + BIT5;//1. Select P3.4 and P3.5 to do UART0 communication portME1 |= UTXE0 + URXE0;//2. Enable USART0 to be sent and acceptedUCTL0 |= CHAR;//3. Select 8-bit charactersUTCTL0 |= SSEL0;//4. Select Clock Source, Aclk:ssel0 //Smclk:ssel1UBR00 =0x03;//5. Baud Rate 32767hz:9600UBR10 =0x00;//UMCTL0 =0x4A;//ModulationUCTL0 &= ~swrst;//6. Initialize the UART state machineIE1 |= URXIE0;//7. Enable USART0 to receive interrupts}/* Two, uart0 send a byte*/voidUart0_send_byte (byte dat) { while(! (IFG1 & UTXIFG0));//USART0 TX buffer ready?TXBUF0 = dat;}/* Three, read a byte*/from the uart0 RXBUF0Int8u Uart0_rec (void){returnRXBUF0;}/* Four, UART1 serial interrupt processing function */#pragma vector=uart0rx_vector__interruptvoidUSART0_RX (void){}/* For UART2 serial port configuration, and Operation function Description *// * one. UART1 initialization * /voidUart1_idev_init (void) {P3sel |= BIT6 + BIT7;//1. p3.6,p3.7 Selected as UART1 communication portME2 |= UTXE1 + URXE1;//2. Enable USART0 to be sent and acceptedUCTL1 |= CHAR;//3. Select 8-bit charactersUTCTL1 |= SSEL0;//4. Select Clock Source, Aclk:ssel0 //Smclk:ssel1UBR01 =0x03;//5. Baud Rate 32767hz:9600UBR11 =0x00;//UMCTL1 =0x4A;//ModulationUCTL1 &= ~swrst;//6. Initialize the UART state machineIE2 |= URXIE1;//7. Enable USART1 to receive interrupts}/* Two, Uart1 send a byte*/voidUart1_send_byte (byte dat) { while(! (IFG2 & UTXIFG1));//USART0 TX buffer ready?TXBUF1 = dat;}/* Three, read a byte*/from the Uart1 RXBUF1Int8u Uart1_rec (void){returnRXBUF1;}/* Four, UART1 serial interrupt processing function */#pragma vector=uart1rx_vector__interruptvoidUSART1_RX (void){}
MSP430 serial port initialization, and serial port operation