刚开始学430,遇到问题了。下面两个程序最终理论结果应该没区别吧!为什实际差别这么大?
程序一:
#include "msp430x14x.h"
#include "delay.h"
#define uchar unsigned char
#define uint unsigned int
uchar const trdata[]={'A','B','C','D','E','F','G','H','I','J','K','L',0x0d,0x0a};
uchar i;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P3SEL|=0X30;
ME1|=UTXE0+URXE0;
UCTL0|=CHAR;
UTCTL0|=SSEL0;
UBR10=0X00;
UBR00=0X03;
UMCTL0=0X4a;//设置波特率为9600
UCTL0&=~SWRST;
IE1|=UTXIE0;
while(1)
{
for(i=0;i<14;i++)
{
TXBUF0=trdata[i];
while(!(IFG1&UTXIFG0));
}
//_BIS_SR(LPM3_bits+GIE);
}
}
#pragma vector=UART0TX_VECTOR
__interrupt void usart0_rx(void)
{
_BIC_SR_IRQ(LPM3_bits);
} //结果是自动循环发送。
程序二:
#include "msp430x14x.h"
#include "delay.h"
#define uchar unsigned char
#define uint unsigned int
uchar const trdata[]={'Z','h','a','n','g','H','U','a','q','i','n','g',0x0d,0x0a,0x00};
uchar i;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P3SEL|=0X30;
ME1|=UTXE0+URXE0;
UCTL0|=CHAR;
UTCTL0|=SSEL0;
UBR10=0X00;
UBR00=0X03;
UMCTL0=0X4a;//设置波特率为9600
UCTL0&=~SWRST;
IE1|=UTXIE0;
while(1)
{
while(trdata[i]!=0x00)
{
TXBUF0=trdata[i];
while(!(IFG1&UTXIFG0));
//IFG1&=~UTXIFG0;
i++;
}
// _BIS_SR(LPM3_bits+GIE);
}
}
#pragma vector=UART0TX_VECTOR
__interrupt void usart0_rx(void)
{
_BIC_SR_IRQ(LPM3_bits);
} //结果是每按一次复位键,完整的发送一次。
求高手解释啊!!!!! |