Guest User

Untitled

a guest
Oct 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. void crc(unsigned char msgData[],byte *lowbyte,byte *highbyte)
  2. {
  3. unsigned short Polynom = 0x8408;
  4. unsigned short Register = 0x0000;
  5. unsigned short temp = 0x0000;
  6.  
  7. // loop through the entire array of bytes
  8. for( int i = 0; i < sizeof(msgData); i++ )
  9. {
  10. temp = msgData[i];
  11.  
  12. // shift all 8 data bits once
  13. for( int y = 0; y < 8; y++ )
  14. {
  15. if ( ( ( Register ^ temp ) & 0x01 ) == 0x01 )
  16. {
  17. Register >>= 1;
  18. Register ^= Polynom;
  19. }
  20. else
  21. {
  22. Register >>= 1;
  23. }
  24. temp >>= 1; // shift data 1 bit right, dividing it by 2
  25.  
  26. } // end of inner for loop (bit shift loop)
  27. } // end of outer for loop (data loop)
  28.  
  29. // now we have got our overall 2-byte CRC "Checksum" number
  30. *lowbyte = (byte) ( Register / 256 );
  31. *highbyte = (byte) ( Register % 256 );
  32.  
  33. }
Add Comment
Please, Sign In to add comment