程序需要用到串口(和GSM模块通信用),程序得一直跑着,但是程序跑着跑着 串口就会出现乱码或者干脆串口死了,但是LCD显示什么的都正常
U0CTL = SWRST;// Set the reset bit to hold inactive
if(Baudrate==9600)
{
#if UCLK==SMCLK_8M
UBR00 = 0x41; // 32k/2400 - 13.65
UBR10 = 0x03; // 32k/2400
UMCTL0 = 0x00; // modulation
UTCTL0 |= SSEL1+SSEL0; // UCLK = SMLK
#else
//程序 运行一段时间后(有时几天 有时个把月),那个串口就死了
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00;
UMCTL0 = 0x4A;
UTCTL0 |= SSEL0; // UCLK = ACLK 选择ACLK,在LPM3.可激活
UTCTL0 &=~SSEL1;
#endif
}
else if(Baudrate==57600)
{
U0BR0 = 0x8A; // Prescale divisor = 0x008A
U0BR1 = 0x00;
U0MCTL = 0xFF; // Modulation 11111111
UTCTL0 |= SSEL1+SSEL0; // UCLK = SMLK
}
U0CTL = SWRST+CHAR; // P=none, 8 bits, 1 stop
U0RCTL = 0; // wake on all correct rx
ME1 |= URXE0 +UTXE0; // Enable the module
P2SEL |= 0x30; // P2.4,5 special function
P2DIR |= 0x10; // P2.4 TX output
P2DIR &= ~0x20; // P2.5 RX input
U0CTL &= ~SWRST; // Release the UART to operation
IE1 |= URXIE0; // RXINT enable |