我刚接手的一段程序,让更改一下曼彻斯特解码。这段程序的前导符是0X00 0X01,现在让我更改成0X00 0XEE。看了好久没有看懂是什么意思所以想请教一下大家这段程序改如何修改成我需要的。这使用的是STM32F1的TIM4定时器中断。波特率我算的是9600.麻烦有知道的给点提示谢谢啦
void Manchester_decode_for_fsk(uint16_t sign)
{
uint8_t code_type;
uint16_t delt_time;
static uint16_t timer=0;
static uint8_t syn_count=0;
static uint8_t rev_count=0;
static uint16_t rev_data=0;
static uint8_t last_bit=0;
static uint8_t skip_bit=0;
static uint8_t strt_bit=0;
//------------------------
delt_time=sign-timer;
timer=sign;
//------------------------bit=104,208,312,417
if((delt_time>156)&&(delt_time<250))
{
if(strt_bit!=0)
code_type=2;
else
{
syn_count++;
code_type=0;
}
}
else if((delt_time>250)&&(delt_time<360))
{
if(syn_count>8)
{
strt_bit=1;
code_type=3;
}
}
else if((delt_time>360)&&(delt_time<480))
{
if(strt_bit!=0)
code_type=4;
else
code_type=0;
}
else
{
syn_count=0;
strt_bit=0;
code_type=0;
rev_count=0;
rev_data=0;
last_bit=0;
return;
}
//--------------------------------------
switch(code_type)
{
case 2:
rev_data<<=1;
rev_count+=1;
if(last_bit!=0)
rev_data+=1;
break;
case 3:
if(last_bit!=0)
{
rev_data<<=1;
last_bit=0;
rev_count+=1;
}
else
{
rev_data<<=2;
rev_data+=1;
last_bit=1;
rev_count+=2;
}
break;
case 4:
rev_data<<=2;
rev_data+=1;
last_bit=1;
rev_count+=2;
break;
default:
strt_bit=0;
rev_count=0;
rev_data=0;
return;
// break;
}
//-------------------------------------
if(rev_count==2)
{
rev_count=8;
}
if(rev_count%8==0)
{
Rev_buff[rev_count/8-1]=rev_data;
rev_data=0;
skip_bit=1;
}
else if(rev_count%8==7)
skip_bit=0;
else if((rev_count%8==1)&&(skip_bit==0))
{
Rev_buff[rev_count/8-1]=rev_data>>1;
rev_data&=1;
}
if(rev_count>=72)
{
//Rev_buff[0]<<=1;
Rev_flag=1;
rev_count=0;
rev_data=0;
last_bit=0;
}
} |