This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2串口通信

Other Parts Discussed in Thread: MSP430G2553, CCSTUDIO

 msp430g2553串行通信,在网上找的代码,粘贴到新建CCS工程里编译出24个errors,代码如下,问题出现在主函数里前面的寄存器初始化等,新手的我看了半天毫无效果,恳请大神支招,或是给个正确代码

#include<msp430G2553.h>
#include "in430.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; 
  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_cycles(10000);
  }
}
/**********************************UART接收中断*************************/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
  //while (!(IFG2&UCA0TXIFG));                // 等待发送完成
  //UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character
  temp=UCA0RXBUF;
}
 
/******************************UART发送字节函数*************************/
void UartPutchar(unsigned char c)
{
 while(!(IFG2 & UCA0TXIFG));  //待发送为空
 UCA0TXBUF=c;
 IFG2 &=~UCA0RXIFG;
}
/*********************************UART接收字节数据******************/
unsigned char UartGetchar()
{
  unsigned char c;
  while(!(IFG2 & UCA0RXIFG)); //等待接收完成
  c=UCA0RXBUF;
  IFG2 &=~UCA0TXIFG;
  return c;
}