我的程序是这样的:
#include
void delay_us(int n)
{
for(int i=0; i<n; i++)
for(int j=0; j<8; j++);
}
void UartInit()
{
UCA0CTL1 |= UCSWRST;
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
UCA0CTL1 |= UCSSEL1;
//8Mhz, 115200
UCA0CTL0 = 0;
// UCA0CTL0 &= ~UC7BIT; //no parity, 8-bit data, uart mode
UCA0BR0 = 69;
UCA0BR1 = 0;
UCA0MCTL |= UCBRS2;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
int main( void )
{
volatile unsigned int i;
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//clock set
BCSCTL1 &= ~XT2OFF; // XT2on
BCSCTL2 |= SELM1 + SELS + DCOR;
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
delay_us(50);
}while((IFG1 & OFIFG));
// BCSCTL3 |= XT2S1;
//uart init
UartInit();
//spi init
// SpiInit();
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
while(1)
{
while (!(IFG2&UCA0TXIFG));
UCA0TXBUF = 0xab;
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
实在是弄不明白为什么每次启动单片机就发送了个0xE0然后就没了,但是我的while里面是一直发送的啊,而中断程序里的发送是正常的,也就是当pc给单片机发送的时候单片机将收到的字节发送回来是可以的,怎么调都是这样的,求大神指点一二,谢谢了~ |