INST.No.INE-863B KR2S
【
Communication Interface
】
Instruction Manual
-27-
Reference: CRC-16 calculation program (C language)
/***** CRC-16 calculation program *****/
#include <stdio.h>
#include <conio.h>
void main(void){
/*** Internal variable declaration ***/
unsigned int iLoopCnt; /* Loop counter*/
unsigned short usData; /* Input data*/
unsigned short usCrcData; /* CRC-16 data*/
unsigned short usErrChkData; /* Error check data*/
int iDummy; /* Dummy variable*/
/* (1) Initialization of output result of a CRC-16 data */
usCrcData = 0xffff;
printf("Enter the hexadecimal data (Cancel by [q].) >
\
n");
while( scanf("%x", &usData) != 0){
/* (2) (6) Taking exclusive OR of the CRC output result and the entered data */
usCrcData = usData ^ usCrcData;
/*** CRC calculation processing ***/
/* (5) Repetition up to 8-bit shifts */
for(iLoopCnt = 0 ; iLoopCnt < 8 ; i+){
/* (4) Checking if there is a carry. */
if(usCrcData & 0x0001){
/* (4) At a carry activated */
/* (3) 1-bit shifting of the CRC output result to the right */
usCrcData = usCrcData >> 1;
/* (4) Taking exclusive OR with A001H */
usCrcData = usCrcData ^ 0xa001;
}else{
/* (4) At a carry no activated */
/* (3) 1-bit shifting of the CRC output result to the right */
usCrcData = usCrcData >> 1;
}
} /* for */
}; /* while */
printf("The CRC-16 data is %xH.", usCrcData);
/* Error check data creation*/
usErrChkData = (usCrcData >> 8) | (usCrcData << 8);
printf("The data for the error check is %xH.", usErrChkData);
iDummy = getch();
}
Summary of Contents for KR2S
Page 2: ...INST No INE 863B KR2S Communication Interface Instruction Manual ...
Page 124: ...INST No INE 863B KR2S Communication Interface Instruction Manual ...
Page 125: ...INST No INE 863B KR2S Communication Interface Instruction Manual ...
Page 126: ...INST No INE 863B KR2S Communication Interface Instruction Manual ...
Page 127: ...INST No INE 863B KR2S Communication Interface Instruction Manual ...