金牌会员
- 积分
- 1467
- 威望
- 701
- 贡献
- 410
- 兑换币
- 428
- 注册时间
- 2014-1-6
- 在线时间
- 178 小时
|
分享一个我自己修改过的吧,直接调用函数输出就行,fire库好使,其他未测试
本帖最后由 狂野的庄稼汉 于 2014-5-15 11:53 编辑
- /*
- * 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]);
- }
复制代码 分享一个我自己修改过的吧,直接调用函数输出就行,fire库好使,其他未测试
|
|