|
void InitUART(void)
{
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= URXE0; // Enable USART0 T/RXD
UCTL0 |= 0x10; // 8-bit character
UTCTL0 |=SSEL1; // UCLK = SMCLK
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00; //
UMCTL0 = 0x4A; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // 使能USART0的接收中断
}
#pragma vector = UART0RX_VECTOR
__interrupt void UART0_RXISR(void)
{
uchar ch;
IE1 &= ~URXIE0;
while (!(IFG1 & URXIFG0))
{
ch = RXBUF0;
if ((ch == '$') && (gps_flag == 0)) //如果收到字符'$',便开始接收
{
rev_start = 1;
rev_stop = 0;
}
if (rev_start == 1) //标志位为1,开始接收
{
rev_buf[num++] = ch; //字符存到数组中
if (ch == '\n') //如果接收到换行
{
rev_buf[num] = '\0';
rev_start = 0;
rev_stop = 1;
gps_flag = 1;
num = 0;
}
}
}
IFG1&=~URXIFG0;
IE1 |= URXIE0;
}
,怎么收不到信息,是不是串口初始化,还是别的地方有问题?
|
|