4M晶振,要9600波特率...
用波特率计算工具算得:UBR1=0X01;UBR0=0XA0;UCA0MCTLW=0XC000;
怎么不对呢...和PC联系不上...
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog
// XT1 Setup
PJSEL0 |= BIT4 + BIT5;
CSCTL0_H = 0xA5;
CSCTL1 |= DCOFSEL0 + DCOFSEL1; // Set max. DCO setting
CSCTL2 = SELA_0 + SELS_3 + SELM_3; // set ACLK = XT1; MCLK = DCO=smlk
CSCTL3 = DIVA_2 + DIVS_0 + DIVM_0; // set all dividers 1MHZ
CSCTL4 |= XTS; //high speed mode
CSCTL4&=~XT1DRIVE_3;
CSCTL4 &= ~XT1OFF;
do
{
CSCTL5 &= ~XT1OFFG;
// Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
// Configure UART pins
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
P3OUT=0;
P3DIR|=BIT4+BIT5+BIT6+BIT7;
// Configure UART 0
UCA0CTL1 |= UCSWRST;
UCA0CTL1 = UCSSEL_1; // Set ACLK = 4MHZ as UCBRCLK
UCA0BR0 = 0xa0; // 9600 baud
UCA0BR1 = 0x01;
UCA0MCTLW |= 0xc000;
UCA0CTL1 &= ~UCSWRST; // release from reset
UCA0IE |= UCRXIE; // Enable RX interrupt
_EINT();
没有问题啊...
我估计是波特率设置有问题...
那个MCTLW到底怎么设置...按书上说小数5应该设置为0X6B才是...怎么是0XC0呢..
此帖出自
小平头技术问答
一周热门 更多>