#include "reg52.h"
#define uint8 unsigned char
#define uint16 unsigned int
unsigned char str[]={0x28,0x6D,0x00,0x85,0x00,0x00,0x00,0xCF};
uint16 CRC_16_UP_Bit(uint8 * dat, uint8 len, uint16 oldcrc);
uint16 CRC_16_UP_NiByte(uint8 * dat, uint8 len, uint16 oldcrc);
uint16 CRC_16_UP_Byte(uint8 * dat, uint8 len, uint16 oldcrc);
/*CRC的初始值为0x00,多项式为0xff00,高位在先 */
/*方法一 */
//---------------------------------------
// 功能:逐位计算CRC16(UP_左移正序)
// 输入:
// uint8 * dat:要计算CRC的数据指针
// uint8 len :数据长度
// uint16 oldcrc:CRC初始值
// 输出:生成的新CRC值
//---------------------------------------
uint16 CRC_16_UP_Bit(uint8 * dat, uint8 len, uint16 oldcrc)
{
uint8 idata i,j;
uint16 idata x,crc = oldcrc;
for(i = 0;i < len;i ++)
{
crc = crc ^ (dat[i] << 8);
for (j = 8;j > 0;j --)
{
x = crc & 0x8000;
crc <<= 1;
if (x != 0)crc ^= 0xFF00;
}
}
return crc;
}
/*方法二 */
//---------------------------------------
// 半字节CRC16(UP_左移正序) 0xFF00 余式表