常驻嘉宾
- 积分
- 3667
- 威望
- 1715
- 贡献
- 1174
- 兑换币
- 1147
- 注册时间
- 2014-12-6
- 在线时间
- 389 小时
- 毕业学校
- 你猜
|
3#
楼主 |
发表于 2015-4-15 20:24:13
|
只看该作者
float OutData[4] = { 0 };
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);
}
void OutPut_Data(void)
{
int temp[4] = {0};
unsigned int temp1[4] = {0};
unsigned char databuf[10] = {0};
unsigned char i;
unsigned short CRC16 = 0;
for(i=0;i<4;i++)
{
temp[i] = (int)OutData[i];
temp1[i] = (unsigned int)temp[i];
}
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++)
SCI_TX(databuf[i]);
}
void send_data()
{
angle_velocity();
OutData[0] = Angle_z ;
OutData[1] = Gyro_y;
OutData[2] = 0;//g_fGyroscopeAngleSpeed;
OutData[3] = 0;//VOLTAGE_GRAVITY_Z;
OutPut_Data();
}
这是程序 |
|