串口通信UART(msp430g2553)
串口通信UART(msp430g2553)430单片机
#include "io430.h"
#include "in430.h"
#include "shumaguan.h"
void UartPutchar(unsigned char c);
unsigned char UartGetchar();
unsigned char temp=0;
unsigned char number[2]={0};
void main( void )
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1DIR|=BIT6;
P1OUT&=~BIT6;
P1SEL = BIT1 + BIT2; // P1.1为RXD, P1.2为TXD
P1SEL2 = BIT1 + BIT2; // P1.1为RXD, P1.2为TXD
UCA0CTL1 |= UCSSEL_2; // 选择时钟BRCLK
UCA0BR0 = 106; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS2 + UCBRS0; // 波特率=BRCLK/(UBR+(M7+...0)/8)
UCA0CTL1 &= ~UCSWRST; // 初始化顺序:SWRST=1设置串口,然后设置SWRST=0,最后设置相应中断
IE2 |= UCA0RXIE; // 使能接收中断
while(1)
{
//UartPutchar(9);
display_int(temp,0);
delay();
}
}
/**********************************UART接收中断********************************/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
//while (!(IFG2&UCA0TXIFG)); // 等待发送完成


