shuzu=fashu;
fashu[0]=add;
fashu[1]=0x03;
fashu[2]=add1/256; //起始地址高8位
fashu[3]=add1%256;
fashu[4]=0x00; //数据长度高8位
fashu[5]=sjlong; //数据长度低8位
ty=6;
crc=crc_chk(shuzu,ty);
fashu[6]=crc%256;
fashu[7]=crc/256;
for(ty=0;ty<8;ty++)
{
S2BUF=fashu[ty];
while(busy2==0);
busy2=0;
}
unsigned int crc_chk(unsigned char*shuzu1, unsigned char cd)
{
int j ;
unsigned int reg=0xffff;
while(cd--)
{
reg^=*shuzu1++;
for(j=0;j<8;j++)
{
if(reg&0x01)
{
reg=(reg>>0x01)^0xa001;
}
else
{
reg=reg>>0x01;
}
}
}
return reg;
校验结果,有时正确,有时高八位加一是怎么了,请教各位了?
|