使用C预处理器计算8位CRC?

问题描述 投票:5回答:3

我正在为一个只有几个字节RAM的小型8位微控制器编写代码。它有一个简单的工作,即传输7个16位字,然后传输这些字的CRC。在编译时选择单词的值。 CRC具体是“字0到字6的除法的余数,因为无符号数除以多项式x ^ 8 +x²+ x + 1(初始值0xFF)。”

是否可以使用C预处理器在编译时计算这些字节的CRC?

#define CALC_CRC(a,b,c,d,e,f,g)    /* what goes here? */

#define W0    0x6301
#define W1    0x12AF
#define W2    0x7753
#define W3    0x0007
#define W4    0x0007
#define W5    0x5621
#define W6    0x5422
#define CRC   CALC_CRC(W0, W1, W2, W3, W4, W5, W6)
c c-preprocessor microcontroller crc
3个回答
© www.soinside.com 2019 - 2024. All rights reserved.