|
如下面所示 程序,没有设置 时钟源,为何能以 9600正确接收到数据?
此时 cpu的晶振使用 DCO,而uart的晶振使用 LFXT1(9600) 吗?
void main(void)
{
unsigned int i,n;
WDTCTL = WDTPW + WDTHOLD; // 停止看门狗
uart0Init();
P5DIR |= 0x01; // 设P5.0为输出口
// BCSCTL1= 0x80; //分频电阻选择为0(此时闪烁频率较慢)
// BCSCTL1= 0x87; //分频电阻选择为7(此时闪烁频率较快)
// BCSCTL2= 0xc0; //选择外部32768低频晶振作为MCLK(此时闪烁频率极慢)
// BCSCTL2= 0x10; //选择外部8M高频晶振作为MCLK(此时闪烁频率较快)
n =0;
for (;;)
{
i = 80000; // 循环
do i--; while (i);
P5OUT = 0x00; // 通过异或取反P5.0
i = 50000; // 循环
do i--; while (i);
P5OUT = 0x01; // 通过异或取反P5.0
uart0tx(n);
n++;
if(n>9)
{
n = 0;
}
}
}
//////////////
void uart0Init(void)
{
UCTL0=SWRST; //Ready for configurating serial's parameters
//UCTL0 |=CHAR;//+LISTEN; //Data frame format(8-N-1) with listen
UTCTL0=SSEL0+URXSE; //Selection of SMCLK becomes baud ratio clock,edge of starting singal available
//URCTL0=URXEIE; //Wrong message interrupt of reception enable
UBR10=0x00; //Baud ratio adjustiing
UBR00=0x03; //115200 @ 7.3728MHz External Oscillator
UMCTL0=0x4A;
UCTL0 &=~SWRST; //Functions of serial port enable
UCTL0 |=CHAR;//+LISTEN; //Data frame format(8-N-1) with listen
U0ME=URXE0+UTXE0; //Functions of reception and transmitter enable
//UCTL0 &=~SWRST; //Functions of serial port enable
U0IE=URXIE0;//+UTXIE0; //Enable interrupt of reception
P3SEL |=0x30; //P3.5(URXD0),P3.4(UTXD0)
P3OUT &=0xDF; //Setting P3.5 input
P3OUT |=0x10; //Setting p3.4 output
P3DIR |=0x10; //Setting P3.4 direction to output
//tx0flg=1;
//rx0flg=0;
//_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
//_EINT(); // 整个系统使能中断(开总中断)
//LPM1; // 进入LPM1模式
}
void uart0tx(unsigned int i)
{
//unsigned int i;
/*
//while(!(UTCTL0 & TXEPT));
if(!(UTCTL0 & TXEPT))
{}
else
{if(uart0sendb)
{ uart0sendb=0;
TXBUF0=rxbuf0[countt++];
if(countt==10) countt=0;
}
}
*/
//for(i=0;i<10;i++)
TXBUF0=txbuf;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|