#include "stdio.h"
unsigned short MY_CRC16_MODBUS(unsigned char *buff,unsigned int size)
{
unsigned short tmp = 0xffff;
unsigned short ret1 = 0;
unsigned short n=0,i=0;
for(n = 0; n < size; n++){
tmp = buff[n] ^ tmp;
for(i = 0;i < 8;i++){
if(tmp & 0x01){
tmp = tmp >> 1;
tmp = tmp ^ 0xa001;
}
else{
tmp = tmp >> 1;
}
}
}
ret1 = tmp >> 8;
ret1 = ret1 | (tmp << 8);
return ret1;
}
void main()
{
unsigned char tmp[]={0x01,0x03,0x00,0x03,0x00,0x18};
printf("%X\n",MY_CRC16_MODBUS(tmp,6));
}