串口调试助手每次都显示 FF,求教
程序如下:
#include "msp430x26x.h"
unsigned char b;
//时钟初始化
void clock_init(void)
{
if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_16MHZ; // Set DCO to 16MHz
DCOCTL = CALDCO_16MHZ;
// BCSCTL2=(SELM_0+DIVM_1+DIVS_3+DCOR)^SELS;
BCSCTL2|=DIVS_3;//SMCLK 8分频 2M
// BCSCTL2|=DIVM_3; //MCLK 8分频 系统运行时钟
// Timer A0 interrupt service routine
}
//IO初始化
void io_init(void)
{
P1DIR|=BIT0;
P5DIR|=BIT5;
P5SEL|=BIT5;
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
P3DIR|=BIT4;
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//时钟初始化
clock_init();
io_init();
UCA0CTL1|=UCSWRST;
UCA0CTL0&=~UC7BIT;//字符长度为8
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 208; // 2MHz 9600
UCA0BR1 = 0; // 2MHz 9600
UCA0MCTL =UCBRS1; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE+UCA0TXIE; // Enable USCI_A0 RX interrupt
// IE2 |= UCA0TXIE;
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
for(;;)
{
// UCA0TXIFG=0;
UCA0TXBUF=0x33;
while((IFG2&UCA0TXIFG)==0); //查询发送是否结束
IFG2&=~UCA0TXIFG; //清除发送一标志位
}
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
// while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
//b = UCA0RXBUF; // TX -> RXed character
} |