Advertisement
Guest User

Untitled

a guest
Nov 30th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include "stdio.h"
  2. typedef unsigned short uint16;
  3. typedef unsigned char uint8;
  4. //typedef char uint8;
  5. typedef unsigned int uint32;
  6. uint16 Crc_CalculateISOChecksum(uint8 *pt_start_address, uint32  length)
  7. {
  8.     uint8 C0, C1;
  9.     uint8 data;
  10.     uint32 i;
  11.     uint8 ck1, ck2;
  12.  
  13.     /* Initial value */
  14.     C0 = 0;
  15.     C1 = 0;
  16.  
  17.     /* memories - 32bits wide*/
  18.     for (i=0; i<length; i++)    /* nb_bytes has been verified */
  19.     {
  20.       data = pt_start_address[i];
  21.       C0 = (C0 + data)%255;
  22.       C1 = (C1 + C0)%255;
  23.     }
  24.     /* Calculate the intermediate ISO checksum value */
  25.     ck1 = (unsigned char)(255-((C0+C1)%255));
  26.     ck2 =  (unsigned char)(C1%255);
  27.     if (ck1 == 0)
  28.     {
  29.       ck1 =255;// MASK_BYTE_LSB;
  30.     }
  31.     if (ck2 == 0)
  32.     {
  33.         ck2 = 255;//MASK_BYTE_LSB;
  34.     }
  35.     return ((((uint16)ck1)<<8) | ((uint16)ck2));
  36. }
  37.  
  38. void main(void)
  39. {
  40.         unsigned short crc = 0;
  41. //      unsigned char data[] = {0xAB,0xCD,0xEF,0x01};
  42.         unsigned char data[] = {0x14,0x56,0xF8,0x9A,0x00,0x01};
  43.         crc = Crc_CalculateISOChecksum(data,6);
  44.         printf("%d %d %d \n",sizeof(uint8),sizeof(uint16),sizeof(uint32));
  45.         printf("%x\n",crc);
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement