中级会员
- 积分
- 286
- 威望
- 142
- 贡献
- 72
- 兑换币
- 83
- 注册时间
- 2017-2-28
- 在线时间
- 36 小时
- 毕业学校
- 重庆邮电大学
|
2#
楼主 |
发表于 2017-4-10 18:02:11
|
只看该作者
/*
* Description: 虚拟示波器校验码生成函数
*
* Data: 2014.5.8
* Author: Liu
*/
unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT)
{
unsigned short CRC_Temp;
unsigned char i,j;
CRC_Temp = 0xffff;
for (i=0;i<CRC_CNT; i++){
CRC_Temp ^= Buf[i];
for (j=0;j<8;j++) {
if (CRC_Temp & 0x01)
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
return(CRC_Temp);
}
/*
* Description: 虚拟示波器输出函数
*
* Data: 2014.5.8
* Author: Liu
*/
void VisualScope_Output(float data1 ,float data2 ,float data3 ,float data4)
{
int temp[4] = {0};
unsigned int temp1[4] = {0};
unsigned char databuf[10] = {0};
unsigned char i;
unsigned short CRC16 = 0;
temp[0] = (int)data1;
temp[1] = (int)data2;
temp[2] = (int)data3;
temp[3] = (int)data4;
temp1[0] = (unsigned int)temp[0] ;
temp1[1] = (unsigned int)temp[1];
temp1[2] = (unsigned int)temp[2];
temp1[3] = (unsigned int)temp[3];
for(i=0;i<4;i++)
{
databuf[i*2] = (unsigned char)(temp1[i]%256);
databuf[i*2+1] = (unsigned char)(temp1[i]/256);
}
CRC16 = CRC_CHECK(databuf,8);
databuf[8] = CRC16%256;
databuf[9] = CRC16/256;
for(i=0;i<10;i++)
uart_putchar(UART3,databuf[i]);
}
大神们,请问一下用蓝牙接收了小车发来的数据后,想用程序来接收数据然后用VScope显示出来,我该用那个函数啊? |
|