注册会员
- 积分
- 84
- 威望
- 52
- 贡献
- 20
- 兑换币
- 22
- 注册时间
- 2015-4-18
- 在线时间
- 6 小时
- 毕业学校
- 湖南大学
|
/*示波器输出*/
//示波器冗余校验码产生函数
uint16 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)
CRC_Temp = (CRC_Temp >>1 ) ^ 0xa001;
else
CRC_Temp = CRC_Temp >> 1;
}
}
return(CRC_Temp);
}
//示波器显示函数
void OutPut_Data()
{
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 = (int16)OutData;
temp1 = (uint16)temp;
}
for(i=0;i<4;i++)
{
databuf[i*2] = (int8)(temp1%256);
databuf[i*2+1] = (int8)(temp1/256);
}
CRC16 = CRC_CHECK(databuf,8);
databuf[8] = CRC16%256;
databuf[9] = CRC16/256;
for(i=0;i<10;i++)
uart_putchar(UART0,databuf);
}
补充内容 (2015-5-7 22:18):
for(i=0;i<4;i++)
{
temp = (int16)OutData;
temp1 = (uint16)temp;
}
前面那里显示的有问题,补充一下。OutData[]自己定义一下,例如OutData[1]=x表示示波器2通道输出变量x |
|