常驻嘉宾
- 积分
- 4042
- 威望
- 2998
- 贡献
- 12
- 兑换币
- 1807
- 注册时间
- 2013-9-2
- 在线时间
- 516 小时
|
/*
* 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]);
}
数据送给OutData[0]、OutData[1]、OutData[2]、OutData[3],调用OutPut_Data()进行显示。 |
|