Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- typedef unsigned short uint16;
- typedef unsigned char uint8;
- //typedef char uint8;
- typedef unsigned int uint32;
- uint16 Crc_CalculateISOChecksum(uint8 *pt_start_address, uint32 length)
- {
- uint8 C0, C1;
- uint8 data;
- uint32 i;
- uint8 ck1, ck2;
- /* Initial value */
- C0 = 0;
- C1 = 0;
- /* memories - 32bits wide*/
- for (i=0; i<length; i++) /* nb_bytes has been verified */
- {
- data = pt_start_address[i];
- C0 = (C0 + data)%255;
- C1 = (C1 + C0)%255;
- }
- /* Calculate the intermediate ISO checksum value */
- ck1 = (unsigned char)(255-((C0+C1)%255));
- ck2 = (unsigned char)(C1%255);
- if (ck1 == 0)
- {
- ck1 =255;// MASK_BYTE_LSB;
- }
- if (ck2 == 0)
- {
- ck2 = 255;//MASK_BYTE_LSB;
- }
- return ((((uint16)ck1)<<8) | ((uint16)ck2));
- }
- void main(void)
- {
- unsigned short crc = 0;
- // unsigned char data[] = {0xAB,0xCD,0xEF,0x01};
- unsigned char data[] = {0x14,0x56,0xF8,0x9A,0x00,0x01};
- crc = Crc_CalculateISOChecksum(data,6);
- printf("%d %d %d \n",sizeof(uint8),sizeof(uint16),sizeof(uint32));
- printf("%x\n",crc);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement