|
我刚接触单片机不久,还在看别人写的程序,现在关于单片机与PC通信的程序没大看懂,希望前辈能指点下,不胜感激。我看的是MSP430F449,下面是串口中断程序。目前单片机和PC不能正常通信,不知道是不是程序出了问题。
unsigned char ReceiveFlag=0;
#pragma vector=USART0RX_VECTOR
__interrupt void USART0RX(void)
{
_BIC_SR_IRQ(LPM3_bits); // Cleat LPM3 bits from 0(SR)
ReceiveBUFF[ReceiveCounter++] = RXBUF0;
if(ReceiveHeadFlag == 0)
{
if(ReceiveBUFF[0] != 0x55)
{
ReceiveCounter = 0;
return;
}
if (ReceiveCounter == 1)
return;
if (ReceiveBUFF[1] != 0xaa)
{
ReceiveCounter = 0;
return;
}
if (ReceiveCounter < 4)
return;
if(ReceiveCounter == 4)
{
ULen = (ReceiveBUFF[2]<<8) + ReceiveBUFF[3];
ReceiveFlag =1;
ReceiveChecksum =ReceiveBUFF[2];
return;
}
}
else
{
ReceiveChecksum += ReceiveBUFF[ReceiveCounter-1];
if (ReceiveCounter >= (ULen + 2))
{
ReceiveChecksum -=ReceiveBUFF[ReceiveCounter-1];
ReceiveFlag = 1;
ReceiveCounter = 0;
ReceiveHeadFlag = 0;
}
if(ReceiveFlag ==1)
{
ReceiveFlag =0;
receivecorrect =1;
Command = ReceiveBUFF[5];
}
}
}
上面程序 ULen = (ReceiveBUFF[2]<<8) + ReceiveBUFF[3],其中“ReceiveBUFF[2]<<8”,之前定义的是char ReceiveBUFF[20]; char ULen,这里ReceiveBUFF[2]向左移8位,那不是都移出去了吗,不是就变成00000000了,这句话到底什么意思啊,有什么作用?谢谢啦
|
|