串口数据的解析。 /*****************************************************
*函数名称:void UartRecvAnalysisDeal(void)
*函数功能:解析串口接收数据处理
*入口参数:void
*出口参数:void
*****************************************************/
void UartRecvAnalysisDeal(void)
{
UartRecv();
if(RecvFlag==1) //判断是否接收完
{
RecvFlag = 0;
Uart_Send_String(RecvBuf);
if(RecvBuf[0] == '#') //判断启示标志位
{
//1.LED
if((RecvBuf[1]=='L')&&(RecvBuf[2]=='E')&&(RecvBuf[3]=='D'))
{
if (RecvBuf[4] == '0')
{
LED_OFF;
Uart_Send_String("#LED0\r\n");
}
if (RecvBuf[4] == '1')
{
LED_ON;
Uart_Send_String("#LED1\r\n");
}
}
//2.BEP
else if((RecvBuf[1]=='B')&&(RecvBuf[2]=='E')&&(RecvBuf[3]=='P'))
{
if (RecvBuf[4] == '0')
{
BEP_OFF;
Uart_Send_String("#BEP0\r\n");
}
if (RecvBuf[4] == '1')
{
BEP_ON;
Uart_Send_String("#BEP1\r\n");
}
}
//3.SMG
else if((RecvBuf[1]=='S')&&(RecvBuf[2]=='M')&&(RecvBuf[3]=='G'))
{
num1 = RecvBuf[4] - 0x30;
num2 = RecvBuf[5] - 0x30;
num3 = RecvBuf[6] - 0x30;
num4 = RecvBuf[7] - 0x30;
}
//5.EEPROM Write
else if((RecvBuf[1]=='E')&&(RecvBuf[2]=='E')&&(RecvBuf[3]=='P')&&(RecvBuf[4]=='W'))
{
startaddr = (RecvBuf[5]-0x30)*100 +(RecvBuf[6]-0x30)*10 + (RecvBuf[7]-0x30);
len = (RecvBuf[8]-0x30)*100 + (RecvBuf[9]-0x30)*10 + (RecvBuf[10]-0x30);
dater = (RecvBuf[11]-0x30)*100 + (RecvBuf[12]-0x30)*10 + (RecvBuf[13]-0x30);
for(i=startaddr;i<len;i++)
{
EEPROM_WriteOneByte(i,dater);
USCI0_TWI_Delay(2500);
USCI0_TWI_Delay(2500);
}
// Uart_Send_String("写入完成\r\n");
}
//6.EEPROM Read
else if((RecvBuf[1]=='E')&&(RecvBuf[2]=='E')&&(RecvBuf[3]=='P')&&(RecvBuf[4]=='R'))
{
startaddr = (RecvBuf[5]-0x30)*100 +(RecvBuf[6]-0x30)*10 + (RecvBuf[7]-0x30);
len = (RecvBuf[8]-0x30)*100 + (RecvBuf[9]-0x30)*10 + (RecvBuf[10]-0x30);
for(i=startaddr;i<len;i++)
{
temp = EEPROM_ReadOneByte(i);
Uart_Send_Byte('!');
Uart_Send_Byte(temp/100+0x30);
Uart_Send_Byte(temp%100/10+0x30);
Uart_Send_Byte(temp%10+0x30);
}
Uart_Send_Byte('\r');
Uart_Send_Byte('\n');
}
}
}
}
|