#include "msp430g2553.h"
#include "msp430.h"
#define uchar unsigned char
#define uint unsigned int
#define UDRE 5
#define FE 4
#define PE 2
#define DOR 3
unsigned char Re_buf[11],counter=0;
unsigned char sign;
void USART_INIT()
{
WDTCTL=WDTPW+WDTHOLD;
BCSCTL1=CALBC1_1MHZ;
DCOCTL=CALDCO_1MHZ;
P1SEL=BIT1+BIT2; // P1.1 = RXD, P1.2=TXD
P1SEL2=BIT1+BIT2;
UCA0CTL1|=UCSSEL_2;
UCA0BR0=104;
UCA0BR1=0;
UCA0MCTL=UCBRS0;
UCA0CTL1&= ~UCSWRST;
IE2|=UCA0RXIE;
_EINT();
_bis_SR_register(LPM0_bits+GIE);
}
void USART_Transmit(char dat)
{
while( !(UCA0BR1 & (1 << UDRE)) ); //只有数据寄存器为空时才能发送数据
P1IN = dat;
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void usart_rx_isr(void) //USART串行接收中断
{
Re_buf[counter]=P1IN;
if(counter==0&&Re_buf[0]!=0x55) return; //第0号数据不是帧头
counter++;
if(counter==11) //接收到11个数据
{
counter=0; //重新赋值,准备下一帧数据的接收
sign=1;
}
} |