求高手看一下这个程序,到底哪里有问题,在CCS5.1中单步调试执行串口发送程序,但是电脑上接收不到,波特率设置的也应该是正确的,但不知道哪里出了问题
#include"msp430g2553.h"
unsigned char data=22;
void Putchar0(unsigned char Chr)
{
UCA0TXBUF = Chr;
while(!(IFG2 & UCA0TXIFG));
IFG2&=~UCA0TXIFG;
}
void delay(unsigned char x)
{
unsigned char a,b;
for(a=x;a>0;a--)
for(b=100;b>0;b--);
}
void main(void)
{
WDTCTL =WDTHOLD+WDTPW;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;//上面两句将内部DCO校准至8MHz
P1SEL |= BIT1 + BIT2; // P1.2 = USCI_A0 TXD
P1SEL2 = BIT1 + BIT2;
UCA0CTL1 |= UCSSEL_2; // SMCLK
//UCA0BR0 = 0x34; // 8MHz 9600
UCA0BR0 = 104;
UCA0BR1 = 0;
//UCBRS0 = 1; // Modln UCBRSx=1, over sampling
UCA0MCTL = UCBRS0;
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |=UCA0RXIE;
_EINT();
while(1)
{
Putchar0(data);
delay(30);
Putchar0('a');
delay(30);
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
data = UCA0RXBUF;
IFG2&=~UCA0RXIFG;
}
|