HJ/T212-2005 CRC

unsigned short HJT212_CRC(char *p, uint16_t len)
{

    unsigned short lwrdCrc = 0xFFFF;
    unsigned short lwrdMoveOut;
    int i = 0;
    uint16_t lintDataLen;
    int j;
    char x;
    lintDataLen = len;
    while (i < lintDataLen)
    {

        x = (char)(lwrdCrc >> 8);

        lwrdCrc = (unsigned short)(((unsigned short)p[i]) ^ x);
        i++;

        j = 0;
        while (j < 8)
        {
            lwrdMoveOut = (unsigned short)(lwrdCrc & 0x0001);

            lwrdCrc = (unsigned short)(lwrdCrc >> 1);
            if (lwrdMoveOut == 1)
            {
                lwrdCrc = (unsigned short)(lwrdCrc ^ 0xA001);
            }
            j++;
        }
    }
    return lwrdCrc;
}

 

你可能感兴趣的:(STM32,C)