当前位置:网站首页>某相机通信协议校验CRC程序
某相机通信协议校验CRC程序
2022-06-10 09:08:00 【vzhb】
编程语言:c语言
根据设定的算法规则,输入字符串,计算得出校验数据;
代码如下:
#include <stdio.h>
int main(void)
{
//unsigned char ptr[31] = {0xAA ,0x1F ,0x08 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x2B ,0xD8 ,0xF9 ,0xFF ,0xFF ,0xA0 ,0xB3 ,0x01 ,0x00 ,0x56 ,0xD2 ,0x04 ,0x00 ,0x00 ,0x3F ,0x3C ,0x34 ,0x01,0x00};
unsigned char ptr[31] = {0xAA ,0x1F ,0x08 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x2B ,0xEF ,0x04 ,0x00 ,0x00 ,0xA0 ,0xB3 ,0x01 ,0x00 ,0x56 ,0xD2 ,0x04 ,0x00 ,0x00 ,0x3F ,0x3C ,0x34 ,0x01,0x00};
unsigned char i ,len;
unsigned char t = 0;
unsigned char crc = 0x00;
len = sizeof(ptr);
//最后一位保留给校验位
int len_t=len-1;
while(len_t--)
{
crc ^= ptr[t++];
for (i=8; i>0; --i)
{
if (crc & 0x80)
{
crc = (crc << 1) ^ 0xD5;
}
else
crc = (crc << 1);
}
}
printf("crc = 0x%x \n",crc);
ptr[len-1] = crc;
for(i=0;i<len;i++)
{
printf("[%02X]",ptr[i]);
}
}运行结果如下图:

边栏推荐
- 知识图谱、图数据平台、图技术如何助力零售业飞速发展
- Rexroth pressure reducing valve 3dr16p5-5x/100y/00m
- 高考---人生的转折点
- vtk学习之RenderCylinder-Lights灯光渲染
- 樂鑫推出 ESP32-C3 的 AWS IoT 參考示例
- Task03:复杂一点的查询(二)
- The digital collection platform also said that it was "running away": its security was in doubt, and strict supervision was on the way
- 乐鑫对 Zephyr 的最新支持
- C语言define变参__VA_ARGS__及##__VA_ARGS__的使用
- texstudio 如何编译运行基于markdown宏包的tex文件
猜你喜欢

Ifstream seekg() read() text operation

How to Understand Your Data With Visualization

Principal Component Analysis

如何在使用 Flutter时切换应用时隐藏应用预览

Texstudio how to compile and run tex files based on markdown macro package

Coordinate system of VTK learning

vtk学习之Pipeline管线

Win11 installing pandoc

Reference counting and smart pointer for VTK learning

关于函数声明的思考
随机推荐
Task06: Autumn move script C
Latex基本语法备注
Formula Derivation
C语言一维数组名究竟是什么
Skill tree evaluation
Configure vscode+cmake under win11
解压jar包修改配置文件(解压、修改、压缩、运行)
Contact IC card - STM32 (smart card)
How to Spot-Check Regression Algorithms
How to Spot-Check Classification Algorithms
MainActivity
uni-app_ Configure network request in wechat applet development project (third-party package @escook/request miniprogram)
以行为单位 页面的所有的内容都是以行分切的
对线HR_MySQL存储引擎,原来是这样啊
对C语言指针强转的理解
vscode-markdown all in one-keyboard shortcut
js獲取當前時間
uniapp将聊天页面定位始终定位到最底部展示
js获取当前时间
Rendercylinder lights for VTK learning