MSP430 UART 怎么一直在等待发送完毕啊?程序一直停在第一个 while ((UC0IFG & UCA0TXIFG)==0);
#include<msp430x41x2.h>//unsignedcharRxByte;//volatileunsignedcharRxData[256];unsigne...
#include <msp430x41x2.h>
//unsigned char RxByte;
//volatile unsigned char RxData[256];
unsigned char TxByte;
//volatile unsigned int i;
char data[6]="msp430";
void shuchu()
{
SCFQCTL=SCFQ_4M ;
P1SEL|=BIT2;
P1DIR|=BIT2;
TACCR0=55;
TACCTL1=OUTMOD_4;
TACTL|=MC_1+TASSEL_2;
}
void init()
{
P6SEL |= BIT6;// + BIT5; // Use P6.5/P6.6 for USCI_A0
P6DIR|= 0x40;
P1OUT &= ~0x20; // Clear P5.1
P1DIR |= 0x20; // P5.1 output
SCFQCTL = 121; // Set FLL to 3.998MHz
SCFI0 = FLLD0 + FN_2; // Adjust range select
UCA0CTL1 |= UCSWRST; // Set USCI_A0 SW Reset
UCA0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCA0BR0 = 0X1A; // 4Mhz/26=153.8kHz,9600波特率
UCA0BR1 = 0;
UCA0MCTL = UCBRF_1 + UCOS16; // Set 1st stage modulator to 1
// 16-times oversampling mode
UCA0IRTCTL = UCIRTXPL2 + UCIRTXPL0 + UCIRTXCLK + UCIREN;
// Pulse length = 6 half clock cyc??
// Enable BITCLK16, IrDA enc/dec
ME1=UTXE0+URXE0;
}
void main(void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
UCA0CTL1 &= ~UCSWRST; // Resume USCI_A0 operation
while (1)
{
shuchu();
UCA0TXBUF = 0xff; // TX data and pointer, 8-bit
while ((UC0IFG & UCA0TXIFG)==0); // USCI_A0 TX buffer ready?1表示发送完毕,0表示未发送完毕
for (i=0;i<=6; i++) // Small delay
{
UCA0TXBUF = data[i]; // TX character
while ((UC0IFG & UCA0TXIFG)==0);
}
P1OUT ^= 0x20;
}
} 展开
//unsigned char RxByte;
//volatile unsigned char RxData[256];
unsigned char TxByte;
//volatile unsigned int i;
char data[6]="msp430";
void shuchu()
{
SCFQCTL=SCFQ_4M ;
P1SEL|=BIT2;
P1DIR|=BIT2;
TACCR0=55;
TACCTL1=OUTMOD_4;
TACTL|=MC_1+TASSEL_2;
}
void init()
{
P6SEL |= BIT6;// + BIT5; // Use P6.5/P6.6 for USCI_A0
P6DIR|= 0x40;
P1OUT &= ~0x20; // Clear P5.1
P1DIR |= 0x20; // P5.1 output
SCFQCTL = 121; // Set FLL to 3.998MHz
SCFI0 = FLLD0 + FN_2; // Adjust range select
UCA0CTL1 |= UCSWRST; // Set USCI_A0 SW Reset
UCA0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCA0BR0 = 0X1A; // 4Mhz/26=153.8kHz,9600波特率
UCA0BR1 = 0;
UCA0MCTL = UCBRF_1 + UCOS16; // Set 1st stage modulator to 1
// 16-times oversampling mode
UCA0IRTCTL = UCIRTXPL2 + UCIRTXPL0 + UCIRTXCLK + UCIREN;
// Pulse length = 6 half clock cyc??
// Enable BITCLK16, IrDA enc/dec
ME1=UTXE0+URXE0;
}
void main(void)
{
unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
UCA0CTL1 &= ~UCSWRST; // Resume USCI_A0 operation
while (1)
{
shuchu();
UCA0TXBUF = 0xff; // TX data and pointer, 8-bit
while ((UC0IFG & UCA0TXIFG)==0); // USCI_A0 TX buffer ready?1表示发送完毕,0表示未发送完毕
for (i=0;i<=6; i++) // Small delay
{
UCA0TXBUF = data[i]; // TX character
while ((UC0IFG & UCA0TXIFG)==0);
}
P1OUT ^= 0x20;
}
} 展开
2个回答
展开全部
while ((UC0IFG & UCA0TXIFG)==0);是不是要改成while ((IFG2 & UCA0TXIFG)==0);
试试看。
试试看。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询