项目

一般

简介

Crc(1).txt

UPS的crc检验 - 陆 志毅, 2024-10-09 14:38

 
1
INT16U cal_crc_half(INT8U far *pin, INT8U len)
2
{
3

    
4
	INT16U crc;
5

    
6
	INT8U da;
7
	INT8U far *ptr;
8
	INT8U bCRCHign;
9
    INT8U bCRCLow;
10

    
11
	INT16U crc_ta[16]=
12
	{ /* CRC??ʽ?? */
13
		0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
14

    
15
		0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef
16
	};
17
	ptr=pin;
18
	crc=0;
19
	while(len--!=0) 
20
	{
21
		da=((INT8U)(crc>>8))>>4; /* ?ݴ?CRC?ĸ???λ */
22

    
23
		crc<<=4; /* CRC????4λ???൱??ȡCRC?ĵ?12λ??*/
24

    
25
		crc^=crc_ta[da^(*ptr>>4)]; /* CRC?ĸ?4λ?ͱ??ֽڵ?ǰ???ֽ???Ӻ???????CRC??Ȼ???????һ??CRC?????? */
26

    
27
		da=((INT8U)(crc>>8))>>4; /* ?ݴ?CRC?ĸ?4λ */
28

    
29
		crc<<=4; /* CRC????4λ?? ?൱??CRC?ĵ?12λ?? */
30

    
31
		crc^=crc_ta[da^(*ptr&0x0f)]; /* CRC?ĸ?4λ?ͱ??ֽڵĺ???ֽ???Ӻ???????CRC??Ȼ???ټ?????һ??CRC?????? */
32

    
33
		ptr++;
34
	}
35
	bCRCLow = crc;
36

    
37
    bCRCHign= (INT8U)(crc>>8);
38

    
39
	if(bCRCLow==0x28||bCRCLow==0x0d||bCRCLow==0x0a)
40

    
41
    {
42
    	bCRCLow++;
43
    }
44
    if(bCRCHign==0x28||bCRCHign==0x0d||bCRCHign==0x0a)
45

    
46
    {
47
		bCRCHign++;
48
    }
49
    crc = ((INT16U)bCRCHign)<<8;
50
    crc += bCRCLow;
51
	return(crc);
52
}