中级会员
- 积分
- 437
- 威望
- 221
- 贡献
- 120
- 兑换币
- 124
- 注册时间
- 2018-1-7
- 在线时间
- 48 小时
|
8#
楼主 |
发表于 2018-2-3 21:26:34
|
只看该作者
#include "uart.h"
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;//逐位异或 去取反
for (j=0;j<8;j++)
{
if (CRC_Temp & 0x01)//如果地位为1
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
// Buf[8] = CRC_Temp & 0x00ff; //将第9个数据赋上CRC的低字节
// Buf[9] = CRC_Temp >>8;//第10数据上是CRC的高字节
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 = (int)OutData;
temp1 = (unsigned int)temp;
}
for(i=0;i<4;i++)
{
databuf[i*2] = (unsigned char)(temp1%256);
databuf[i*2+1] = (unsigned char)(temp1/256);
}
CRC16 = CRC_CHECK(databuf,8);
databuf[8] = CRC16%256;
databuf[9] = CRC16/256;
for(i=0;i<10;i++)
{Uart_SendChar(UARTR1,databuf);
}
}
这是函数@GAI |
|