0

我正在尝试在我的代码中实现 CRC16 函数。当我尝试编译时,它给了我一个错误:Keil 上的 C195 “非法间接”。任何有关此事的指导将不胜感激!

         unsigned char *puchMsg ;   /* message to calculate CRC upon */
         unsigned short usDataLen ; /* quantity of bytes in message */              
         unsigned short CRC16 ( puchMsg, usDataLen) 
            {
             unsigned char uchCRCHi = 0xFF ; /* high byte of CRC initialized */
         unsigned char uchCRCLo = 0xFF ;    /* low byte of CRC initialized */   
                                    
            unsigned uIndex ; /* will index into CRC lookup table */
        while (usDataLen--)                 /* pass through message buffer */
         {
                uIndex=uchCRCLo^*puchMsg++;         /* Calculate the CRC */
                uchCRCLo = uchCRCHi^auchCRCHi[uIndex];
                uchCRCHi = auchCRCLo[uIndex];
       }
            return (uchCRCHi<<8|uchCRCLo);
        }

/* One array contains all of the 256 possible CRC values for the
high byte of the 16–bit CRC field, and the other array contains all of the values for the low byte.*/

//* Table of CRC values for low–order byte */ 
const char auchCRCLo[] = {0x00, 0xC0,.....} 

///* Table of CRC values for high–order byte */
 const unsigned char auchCRCHi[] = {0x00, 0xC1...}
4

1 回答 1

1

您需要将函数参数的声明 (puchMsgusDataLen)放在函数声明 ( CRC16) 之后。更好的是使用 30 年前开始的现代 C,并将参数类型放在函数声明中:

unsigned short CRC16 (unsigned char *puchMsg, unsigned short usDataLen) {
...
于 2020-08-01T00:59:13.783 回答