// RX_Ready(); // UART ready to RX one Byte(为等待起始位到来作准备)
// _BIS_SR(LPM3_bits+GIE); // Enter LPM3 Until character RXed
TX_Byte(0x00); // TX Back RXed Byte Received(回传收到的字节)
TX_Byte(0xFF);
}
}
// Function Transmits Character from RXTXData Buffer
void TX_Byte (unsigned int TXData)
{
RXTXData=TXData;
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP(发送10位数据)
CCR0 = TAR; // Current state of TA counter(定时器计数器当前值放比较寄存器中)
CCR0 += Bitime; // Some time till first bit(后推一位的时间)
//帧格式:1XXXXXXXX0
RXTXData |= BIT9; // Add mark stop bit to RXTXData(填充停止位)
RXTXData = RXTXData << 1; // Add space start bit(填充起始位)
CCTL0 = OUTMOD0+CCIE; // TXD = mark = idle(置位输出模式,允许中断)
while ( CCIE & CCTL0); // Wait for TX completion(等待发送完成)
}
// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
BitCnt = 0x8; // Load Bit counter(接收8位)
CCTL0 = SCS+CCIS0+OUTMOD0+CM1+CAP+CCIE; // Sync, Neg Edge, Capture
//(CCIxB引脚同步下降沿捕获,置位输出模式,允许中断)
}