void USART1_IRQHandler(void) //串口1中断服务程序
{
static u8 i;
u8 j=0,k=0;
u16 check=0;
u32 distance=0,strength=0;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_RX_BUF=USART_ReceiveData(USART1);
if(USART_RX_BUF[0]!=HEADER)
{
i=0;
}
else if((i==1)&&(USART_RX_BUF[1]!=HEADER))
{
i=0;
}
else if(i==8)
{
for(j=0;j<8;j++)
{
check += USART_RX_BUF[j];
}
for(k=0;k<9;k++)
{
printf(&quot;%x&quot;,USART_RX_BUF[k]);
}
if(USART_RX_BUF[8]==(check%256))
{
printf(&quot;check = %d&quot;,check);
printf(&quot; &quot;);
distance = USART_RX_BUF[2] + USART_RX_BUF[3]*256;
strength = USART_RX_BUF[4] + USART_RX_BUF[5]*256;//计算信号强度值
printf(&quot;dist = %d&quot;,distance);
printf(&quot; &quot;);
printf(&quot;strength = %d&quot;,strength);
printf(&quot;
&quot;); //插入换行
i=0;
}
}
else
{i++;}
输出的数据 5959fdff45070fa check = 762 dist = 65533 strength = 69 数据一成不变 跪求大佬解释 |