串口控制STC12C5616AD三路PWM,但接收数据不成功,望帮助
程序如下,串口数据回传是正常,程序内调整PWM占空比正常的,判断单个字符也是正常的,但无法解析字符串数据,望帮助,十分感谢串口数据解析部分如下
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 = ch - '0' ;
if(RI_Count == 4){
Xaxis= RI_Buffer*100 +RI_Buffer*0 +RI_Buffer*0;
Xaxis= RI_Buffer;
CCAP0H=CCAP0L=Xaxis;
}
}
break;
case 1:
{
RI_Buffer = ch - '0' ;
if(RI_Count == 4){
CCAP1H = RI_Buffer*100 +RI_Buffer*10 + RI_Buffer ;
}
}
break;
case 2:
{
RI_Buffer = ch - '0' ;
if(RI_Count == 4){
CCAP3H = RI_Buffer*100 +RI_Buffer*10 + RI_Buffer ;
}
}
break;
default:
;
break;
}
}
if (TI)
{
TI = 0; //Clear transmit interrupt flag
busy = 0; //Clear transmit busy flag
}
} LZ是不是作灯饰行业的?dmx512 RGB控制? Xaxis= RI_Buffer*100 +RI_Buffer*0 +RI_Buffer*0;
这句有问题么??Case 0的语句 中断服务里程序太长 你不能放太多的执行程序在中断中 尤其是你中断速度比较快的时候
页:
[1]