最近一直被这个问题困扰,串口发送不了数据,拿到示波器上看,串口输出是正弦波,希望大家帮忙看看是程序有问题吗?
#include <msp430f149.h>
unsigned char shuju;
#define DGUS_HEAD 0x5AA5
int LocalColorNum = 0;
void TS_SendChar(unsigned Chr)
{
shuju = Chr;
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt
}
void SendByte(int cont)
{
//WaitForTxBufEmpty
TS_SendChar((unsigned char)cont);
}
void SendWord(int cont)
{
SendByte(cont >> 8);
SendByte(cont & 0x00FF);
}
void EndSend(void)
{
;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL = 0x30; // P3.4,5 = USART1 TXD/RXD
U0CTL |= SWRST;
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
U0CTL |= CHAR;
U0TCTL |= SSEL1; //ACLK
U0BR1 = 0x03; // 32k/9600 - 3.41
U0BR0 = 0x00; //
U0MCTL=0x4A;
U0CTL &= ~SWRST; // Initialize USART state machine
IE1 |= UTXIE0; // Enable USART0 RX interrupt
_BIS_SR( LPM3_bits +GIE); // Enter LPM3 w/ interrupt
while(1)
{
SendWord(DGUS_HEAD);
SendWord(0x00FF);
SendWord(0x0582);
SendWord(LocalColorNum);
EndSend();
}
}
#pragma vector=USART0TX_VECTOR
__interrupt void usart0_tx (void)
{
// while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
U0TXBUF = shuju;
IFG1 &= ~UTXIFG0; // Clear inital flag on POR
}
|