这段代码与外设时序相关,不能缩短执行时间。有什么好的方法能够让连接稳定吗?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
这段代码与外设时序相关,不能缩短执行时间。有什么好的方法能够让连接稳定吗?
void readAllData(void)
{
TIMER3_CMD( ENABLE);//打开pwm输出
delay_ms(5);
TIMER3_CMD( DISABLE);//关闭pwm输出
delay_us(300);//start gap
WriteBitOne();
WriteBitZero();
WriteBitZero();
TIMER3_CMD( ENABLE);//打开pwm输出
delay_ms(5); //给一定的编程时间
sendFlag = 0;
DecodeMul(1);
}
u8 DecodeMul(u8 mode)
{
u16 i = 0;
u8 count = 0;
u16 temp = 0;
nowbit =0;
u8 bitState[500] = {0};
for(i=0;i<28;i++)
nowData[i] = 0;
for(i=0;i<500;i++)
bitState[i] = 0;
/*开启捕获总开关*/
TimeOutFlg = 1;
#if 1
i=0;
while(i != 400)
{
if(isCapture())
{
valBuffer_L[i] = LOW_temp;
valBuffer_H[i] = TIM2CH1_CAPTURE_VAL;
i++;
setCaptureStart(StartClear);//开始下次捕获
}
if(timerOutCheck())
break;
}
temp = 0;
for(i=10;i<400;i++)
{
if(temp == 1)
{
if(valBuffer_L[i] >315)
break;
if(valBuffer_L[i] > 200)
{
bitState[bit++] = 0;
bitState[bit++] = 0;
}else if(valBuffer_L[i] > 70)
{
bitState[bit++] = 0;
}
if((valBuffer_H[i] > 700))
{
bitState[bit++] = 1;
bitState[bit++] = 1;
}else if((valBuffer_H[i] > 600))
{
bitState[bit++] = 1;
bitState[bit++] = 0;
bitState[bit++] = 1;
}
else if((valBuffer_H[i] > 200) ||(valBuffer_H[i] <100) )
{
bitState[bit++] = 1;
bitState[bit++] = 1;
}else if(valBuffer_H[i] > 100)
{
bitState[bit++] = 1;
}//暂时不考虑 小于 60情况更具实际情况调整
}
if(bit ==500)break;
if(temp == 0)
{
if((valBuffer_L[i] >315)&&(valBuffer_L[i+1] <300))
{
temp =1;
if( valBuffer_H[i] <100)
{
bitState[bit++] = 1;
bitState[bit++] = 0;
}
}
}
}
//解码
for(i=0;i<bit;i++)
{
if((bitState[i] == 0) &&(bitState[++i] == 1))
{
nowData[nowbit/8] <<=1;
nowbit++;//执行到这里表示上一个低电平为双信号表示信号0
}else if((bitState[i] == 1) &&(bitState[++i] == 0))
{
nowData[nowbit/8] <<=1;
nowData[nowbit/8] |=0x01;
nowbit++;//执行到这里表示上一个低电平为双信号表示信号0
}else
{
i-=1;
}
// if(nowbit==32)break;
}
bit = 0;
#endif
TIMER3_CMD( DISABLE);//关闭pwm输出
TimeOutFlg = 0;
return 3;
}
#endif