程序如下,串口数据回传是正常,程序内调整PWM占空比正常的,判断单个字符也是正常的,但无法解析字符串数据,望帮助,十分感谢
temp.zip
(41.32 KB, 下载次数: 9)
2015-5-17 21:52 上传
点击文件名下载附件
串口数据解析部分如下
void Uart_Isr() interrupt 4 using 1
{
if (RI) //RI==¿ªÊ¼½ÓÊÕ
{
unsigned char ch;
RI = 0 ; //Èí¼þRI=0
ch = SBUF;
if ((ch == 'X')||(ch == 'x'))
{
RI_Count= 0 ;
RI_SD_flag = 0 ;
}
if ((ch == 'Y')||(ch == 'y'))
{
RI_Count= 0 ;
RI_SD_flag = 1 ;
}
if ((ch == 'Z')||(ch == 'z'))
{
RI_Count= 0 ;
RI_SD_flag = 2 ;
}
switch (RI_SD_flag)
{
case 0:
{
RI_Buffer[RI_Count++] = ch - '0' ;
if(RI_Count == 4){
Xaxis= RI_Buffer[1]*100 +RI_Buffer[2]*0 +RI_Buffer[3]*0;
Xaxis= RI_Buffer[0];
CCAP0H=CCAP0L=Xaxis;
}
}
break;
case 1:
{
RI_Buffer[RI_Count++] = ch - '0' ;
if(RI_Count == 4){
CCAP1H = RI_Buffer[1]*100 +RI_Buffer[2]*10 + RI_Buffer[3] ;
}
}
break;
case 2:
{
RI_Buffer[RI_Count++] = ch - '0' ;
if(RI_Count == 4){
CCAP3H = RI_Buffer[1]*100 +RI_Buffer[2]*10 + RI_Buffer[3] ;
}
}
break;
default:
;
break;
}
}
if (TI)
{
TI = 0; //Clear transmit interrupt flag
busy = 0; //Clear transmit busy flag
}
}
- Xaxis= RI_Buffer[1]*100 +RI_Buffer[2]*0 +RI_Buffer[3]*0;
复制代码这句有问题么??Case 0的语句
一周热门 更多>