Dear Andre

thank you for the code you have posted,actually i am trying to use the PIC16F877A

another thing i have copy and pasted your code to proton+ compiler and i got some error messages one of them was
for this part of the code:

IF CRC16.Bit0=1 Then '<------ error here is saying Invalid Cast for this type of variable
CRC16=$A001^(CRC16>>1)
Else
CRC16=CRC16>>1
EndIF

i don't know what does that means,please help me.

Best Regards