24
© 2000 Microchip Technology Inc. Preliminary DS00730A-page 1 AN730 INTRODUCTION This application note describes the Cyclic Redundancy Check (CRC) theory and implementation. The CRC check is used to detect errors in a message. Two imple- mentations are shown: T able driven CRC calcul ation Loop dri ven CRC calculation This application describes the implementation of the CRC-16 polynomial. However, there are several for- mats for the implementation of CRC such as CRC-CCITT , CRC-32 or other polynomials. CRC is a common method for detecting errors in trans- mitted messages or stored data. The CRC is a very powerful, but easily implemented technique to obtain data reliability. THEORY OF OPERATION The theory of a CRC calculation is straight forward. The data is treated by the CRC algorithm as a binary num- ber. This number is divided by another binary number called the polynomial. The rest of the division is the CRC checksum, which is appended to the transmitted message. The receiver divides the message (including the calculated CRC), by the same polynomial the trans- mitter used. If the result of this division is zero, then the transmission was successful. However, if the result is not equal to zero, an error occurred during the trans- mission. The CRC-16 polynomial is shown in Equation 1. The polynomial can be translated into a binary value, because the divisor is viewed as a polynomial with binary coefficients. For example, the CRC-16 poly- nomial translates to 1000000000000101b. All coeffi- cients, like x 2 or x 15 , are represented by a logical 1 in the binary value. The division uses the Modulo-2 arithmetic. Modulo-2 calculation is simply realized by XOR’ing two numbers. EXAMPLE 1: MODULO-2 CALCULATION EQUATION 1: THE CRC-16 POLYNOMIAL Example Calculation In this example calculation, the message is two bytes long. In general, the message can have any length in bytes. Before we can start calculating the CRC value 1, the message has to be augmented by n-bits, where n is the length of the polynomial. The CRC-16 polynomial has a length of 16-bits, therefore, 16-bits have to be augmented to the original message. In this example calculation, the polynomial has a length of 3 -bits, there- fore, the message has to be extended by three z eros at the end. An example calculation for a CRC is shown in Example 1. The reverse ca lculation is shown in Exampl e 2. Author s: Thoma s Schmi dt  Microchip Technology Inc. 1 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 0 XOR = XOR-Function X1 X2 Y 0 0 0 0 1 1 1 0 1 1 1 0 P(x) = x 16 +x 15 +x 2 +1 CRC Generating and Checking

CRC Calculation

Embed Size (px)

Citation preview

Page 1: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 1/24

© 2000 Microchip Technology Inc. Preliminary DS00730A-page 1

AN730

INTRODUCTIONThis application note describes the Cyclic RedundancyCheck (CRC) theory and implementation. The CRCcheck is used to detect errors in a message. Two imple-mentations are shown:

• Table driven CRC calculation• Loop driven CRC calculation

This application describes the implementation of theCRC-16 polynomial. However, there are several for-mats for the implementation of CRC such asCRC-CCITT, CRC-32 or other polynomials.

CRC is a common method for detecting errors in trans-mitted messages or stored data. The CRC is a verypowerful, but easily implemented technique to obtaindata reliability.

THEORY OF OPERATIONThe theory of a CRC calculation is straight forward. Thedata is treated by the CRC algorithm as a binary num-

ber. This number is divided by another binary numbercalled the polynomial. The rest of the division is theCRC checksum, which is appended to the transmittedmessage. The receiver divides the message (includingthe calculated CRC), by the same polynomial the trans-mitter used. If the result of this division is zero, then thetransmission was successful. However, if the result isnot equal to zero, an error occurred during the trans-mission.

The CRC-16 polynomial is shown in Equation 1. Thepolynomial can be translated into a binary value,because the divisor is viewed as a polynomial withbinary coefficients. For example, the CRC-16 poly-nomial translates to 1000000000000101b. All coeffi-cients, like x 2 or x 15 , are represented by a logical 1 inthe binary value.

The division uses the Modulo-2 arithmetic. Modulo-2calculation is simply realized by XOR’ing two numbers.

EXAMPLE 1: MODULO-2 CALCULATION

EQUATION 1: THE CRC-16 POLYNOMIAL

Example CalculationIn this example calculation, the message is two byteslong. In general, the message can have any length inbytes. Before we can start calculating the CRC value 1,the message has to be augmented by n-bits, where nis the length of the polynomial. The CRC-16 polynomialhas a length of 16-bits, therefore, 16-bits have to beaugmented to the original message. In this examplecalculation, the polynomial has a length of 3-bits, there-fore, the message has to be extended by three zeros atthe end. An example calculation for a CRC is shown inExample 1. The reverse calculation is shown inExample 2.

Authors: Thomas Schmidt Microchip Technology Inc.

1 0 0 1 1 0 0 1 0 1

0 1 0 0 1 1 0 1 1 1

1 1 0 1 0 1 0 0 1 0

XOR

=

XOR-Function X1 X2 Y0 0 00 1 11 0 1

1 1 0

P(x) = x 16 +x 15+x 2+1

CRC Generating and Checking

Page 2: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 2/24

AN730

DS00730A-page 2 Preliminary © 2000 Microchip Technology Inc.

EXAMPLE 2: CALCULATION FOR GENERATING A CRC

EXAMPLE 3: CHECKING A MESSAGE FOR A CRC ERROR

Message = 110101Polynomial = 101

1 1 0 1 0 1 0 0 : 1 0 1 = 1 1 1 0 11 0 1

1 1 11 0 1

1 0 0

Remainder = CRC checksum

Message with CRC = 1 1 0 1 0 1 1 1

1 0 11 1 01 0 1

1 1 01 0 1

1 1

Quotient (has no function in CRC calculation)

Message with CRC = 11010111Polynomial = 101

1 1 0 1 0 1 1 1 : 1 0 1 = 1 1 1 0 11 0 1

1 1 11 0 1

1 0 0

Checksum is zero, therefore, no transmission error

1 0 11 1 11 0 1

1 0 11 0 1

0 0

Quotient

Page 3: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 3/24

© 2000 Microchip Technology Inc. Preliminary DS00730A-page 3

AN730

FIGURE 1: HARDWARE CRC-16 GENERATOR

FIGURE 2: LOOP DRIVEN CRC IMPLEMENTATION

CRC Hardware ImplementationThe CRC calculation is realized with a shift register andXOR gates. Figure 1 shows a CRC generator for theCRC-16 polynomial. Each bit of the data is shifted into

the CRC shift register (Flip-Flops) after being XOR’edwith the CRC’s most significant bit.

Software ImplementationsThere are two different techniques for implementing aCRC in software. One is a loop driven implementationand the other is a table driven implementation.

The loop driven implementation works like the calcula-

tion shown in Figure 2. The data is fed through a shiftregister. If a one pops out at the MSb, the content isXORed with the polynomial. In the other, the registersare shifted by one position to the left.

Another method to calculate a CRC is to use precalcu-lated values and XOR them to the shift register.

+++

Datax0x2x15x16Flip-Flops

CRC_HIGH CRC_LOW CRC_BUFF

C

07 7 0 07

Note: The mathematical details are not givenwithin this application note. The interestedreader may refer to the material shown inthe Reference section.

Page 4: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 4/24

AN730

DS00730A-page 4 Preliminary © 2000 Microchip Technology Inc.

LOOP DRIVEN CRCIMPLEMENTATIONThis section describes the loop driven CRC implemen-tation. This implementation is derived from the hard-ware implementation shown in Figure 1. The programfor the loop driven CRC generation and CRC checkingis shown in Appendix A.

CRC GenerationThe implementation of a loop driven CRC generation isshown in Figure 2. In the first step the registers,CRC_HIGH and CRC_LOW, are initialized with the firsttwo bytes of data. CRC_BUFF is loaded with the thirdbyte of data. After that, the MSb of CRC_BUFF isshifted into the LSb of CRC_LOW and the MSb ofCRC_LOW is shifted into the LSb of CRC_HIGH. TheMSb of CRC_HIGH, which is now stored in the Carryflag, is tested to see if it is set. If the bit is set, the reg-isters, CRC_HIGH and CRC_LOW, will be XORed withthe CRC-16 polynomial. If the bit is not set, the next bitfrom CRC_BUFF will be shifted into the LSb ofCRC_LOW.This process is repeated until all data from CRC_BUFFis shifted into CRC_LOW. After this, CRC_BUFF isloaded with the next data byte. Then all data bytes areprocessed, and 16 zeros are appended to the mes-sage. The registers, CRC_HIGH and CRC_LOW, con-tain the calculated CRC value. The message can haveany length. In this application note, the CRC value for8 data bytes is calculated.

CRC CheckingThe CRC check uses the same technique as the CRCgeneration, with the only difference being that zerosare not appended to the message.

TABLE DRIVEN CRCIMPLEMENTATIONA table driven CRC routine uses a different techniquethan a loop driven CRC routine. The idea behind atable driven CRC implementation is that instead of cal-culating the CRC bit by bit, precomputed bytes areXORed to the data. The source code for the tabledriven implementation is given in Appendix B.

The advantage of the table driven implementation isthat it is faster than the loop driven solution. The draw-back is that it consumes more program memory

because of the size of the look-up table.

CRC GenerationThe CRC at the table driven implementation is gener-ated by reading a precomputed value out of a table andXOR, the result with the low and high byte of the CRCshift registers.

In the first step, the registers, CRC_BUFF, CRC_HIGHand CRC_LOW, are initialized with the first three bytes

of data. After that, the value in CRC_BUFF is used asan offset to get the value for the precomputed CRCvalue out of the look-up table. Since the CRC-16 is 16bits long, the look-up table is split up into two separatelook-up tables. One for the high byte of the CRC regis-ter and one for the low byte of the CRC register (seeFigure 3). The result from the look-up table of the highbyte is XORed to the content of the CRC_HIGH regis-ter. The result for the low byte is XORed to the contentof CRC_LOW. The results are stored back inCRC_LOW.

The next step is that the content from CRC_HIGH isshifted into CRC_BUFF and the content fromCRC_LOW is shifted into the register, CRC_HIGH.Then the register, CRC_LOW, is loaded with the newdata byte.

This process repeats for all data bytes. At the end of theCRC generation, the message has to be appended by16 zeros. The 16 zeros are treated like the data bytes.

After the calculation is done, the content of the regis-ters, CRC_HIGH and CRC_LOW, are appended to themessage.

CRC CheckingThe CRC check uses the same technique as the CRCgeneration, with the difference being that zeros are notappended to the message.

COMPARISONTable 1 shows a comparison between the loop drivenimplementation and the table driven implementation.For the calculation, 8 data bytes were used.

TABLE 1: CRC-16 COMPARISON TABLE

ImplementationCRC

Generation(in cycles)

CRCCheck

(incycles)

ProgramMemoryUsage

(words)

DataBytes

Loop Driven 865 870 85 6

Table Driven 348 359 612 5

Page 5: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 5/24

© 2000 Microchip Technology Inc. Preliminary DS00730A-page 5

AN730

ADVANTAGES OF CRC VS. SIMPLESUM TECHNIQUESThe CRC generation has many advantages over sim-ple sum techniques or parity check. CRC error correc-tion allows detection of:

1. single bit errors

2. double bit errors3. bundled bit errors (bits next to each other)

A parity bit check detects only single bit errors. TheCRC error correction is mostly used where large datapackages are transmitted, for example, in local areanetworks such as Ethernet.

ReferencesRoss N. Williams - A Painless Guide to CRC Error Detection Algorithms

Donald E. Knuth - The Art of Computer Programming,Volume 2, Addisson Wesley

Page 6: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 6/24

AN730

DS00730A-page 6 Preliminary © 2000 Microchip Technology Inc.

FIGURE 3: TABLE DRIVEN CRC CALCULATION IMPLEMENTATION

CRC_BUFF CRC_HIGH CRC_LOW07 0 07 7

TABLE_HIGH0

0xFF

07 TABLE_LOW0

0xFF

07

++

Page 7: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 7/24

Page 8: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 8/24

Page 9: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 9/24

Page 10: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 10/24

Page 11: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 11/24

Page 12: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 12/24

Page 13: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 13/24

Page 14: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 14/24

Page 15: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 15/24

Page 16: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 16/24

Page 17: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 17/24

© 2000 Microchip Technology Inc. Preliminary DS00730A-page 17

AN730

0 2 1 5

0 8 0 0

0 8 8 0

0 8 8 0

0 0 2 1

8

d t

0 ,

0 x

8 0

,

0 x

8 0

,

0

0 8 0 0

0 2 1 9

0 8 0 0

0 8 8 0

0 8 8 0

0 0 2 1

9

d t

0 ,

0 x

8 0

,

0 x

8 0

,

0

0 8 0 0

0 2 1

D

0 8 8 0

0 8 0 0

0 8 0 0

0 0 2 2

0

d t

0 x

8 0

,

0 ,

0 ,

0 x

8 0

0 8 8 0

0 2 2 1

0 8 8 0

0 8 0 0

0 8 0 0

0 0 2 2

1

d t

0 x

8 0

,

0 ,

0 ,

0 x

8 0

0 8 8 0

0 2 2 5

0 8 0 0

0 8 8 0

0 8 8 0

0 0 2 2

2

d t

0 ,

0 x

8 0

,

0 x

8 0

,

0

0 8 0 0

0 2 2 9

0 8 0 0

0 8 8 0

0 8 8 0

0 0 2 2

3

d t

0 ,

0 x

8 0

,

0 x

8 0

,

0

0 8 0 0

0 2 2

D

0 8 8 0

0 8 0 0

0 8 0 0

0 0 2 2

4

d t

0 x

8 0

,

0 ,

0 ,

0 x

8 0

0 8 8 0

0 2 3 1

0 8 0 0

0 8 8 0

0 8 8 0

0 0 2 2

5

d t

0 ,

0 x

8 0

,

0 x

8 0

,

0

0 8 0 0

0 2 3 5

0 8 8 0

0 8 0 0

0 8 0 0

0 0 2 2

6

d t

0 x

8 0

,

0 ,

0 ,

0 x

8 0

0 8 8 0

0 2 3 9

0 8 8 0

0 8 0 0

0 8 0 0

0 0 2 2

7

d t

0 x

8 0

,

0 ,

0 ,

0 x

8 0

0 8 8 0

0 2 3

D

0 8 0 0

0 8 8 0

0 8 8 0

0 0 2 2

8

d t

0 ,

0 x

8 0

,

0 x

8 0

,

0

0 8 0 0

0 2 4 1

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 2

9

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 4 5

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 3

0

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 4 9

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 3

1

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 4

D

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 3

2

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 5 1

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 3

3

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 5 5

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 3

4

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 5 9

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 3

5

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 5

D

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 3

6

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 6 1

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 3

7

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 6 5

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 3

8

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 6 9

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 3

9

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 6

D

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 4

0

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 7 1

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 4

1

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

Page 18: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 18/24

AN730

DS00730A-page 18 Preliminary © 2000 Microchip Technology Inc.

0 8 8 1

0 2 7 5

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 4

2

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 7 9

0 8 0 1

0 8 8 1

0 8 8 1

0 0 2 4

3

d t

0 x

1 ,

0 x

8 1

,

0 x

8 1

,

0 x

1

0 8 0 1

0 2 7

D

0 8 8 1

0 8 0 1

0 8 0 1

0 0 2 4

4

d t

0 x

8 1

,

0 x

1 ,

0 x

1 ,

0 x

8 1

0 8 8 1

0 2 8 1

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 4

5

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2 8 5

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 4

6

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2 8 9

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 4

7

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2 8

D

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 4

8

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2 9 1

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 4

9

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2 9 5

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 5

0

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2 9 9

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 5

1

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2 9

D

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 5

2

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2

A 1

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 5

3

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2

A 5

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 5

4

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2

A 9

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 5

5

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2

A D

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 5

6

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2

B 1

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 5

7

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2

B 5

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 5

8

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2

B 9

0 8 0 3

0 8 8 3

0 8 8 3

0 0 2 5

9

d t

0 x

3 ,

0 x

8 3

,

0 x

8 3

,

0 x

3

0 8 0 3

0 2

B D

0 8 8 3

0 8 0 3

0 8 0 3

0 0 2 6

0

d t

0 x

8 3

,

0 x

3 ,

0 x

3 ,

0 x

8 3

0 8 8 3

0 2

C 1

0 8 0 2

0 8 8 2

0 8 8 2

0 0 2 6

1

d t

0 x

2 ,

0 x

8 2

,

0 x

8 2

,

0 x

2

0 8 0 2

0 2

C 5

0 8 8 2

0 8 0 2

0 8 0 2

0 0 2 6

2

d t

0 x

8 2

,

0 x

2 ,

0 x

2 ,

0 x

8 2

0 8 8 2

0 2

C 9

0 8 8 2

0 8 0 2

0 8 0 2

0 0 2 6

3

d t

0 x

8 2

,

0 x

2 ,

0 x

2 ,

0 x

8 2

0 8 8 2

0 2

C D

0 8 0 2

0 8 8 2

0 8 8 2

0 0 2 6

4

d t

0 x

2 ,

0 x

8 2

,

0 x

8 2

,

0 x

2

0 8 0 2

Page 19: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 19/24

Page 20: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 20/24

AN730

DS00730A-page 20 Preliminary © 2000 Microchip Technology Inc.

0 8 4 1

0 4 2 1

0 8

C 3

0 8

C 6

0 8

C C

0 0 2 9

3

d t

0 x c

3 ,

0 x c

6 ,

0 x c c ,

0 x c

9

0 8

C 9

0 4 2 5

0 8

D 8

0 8

D D

0 8

D 7

0 0 2 9

4

d t

0 x

d 8

,

0 x

d d

,

0 x

d 7

,

0 x

d 2

0 8

D 2

0 4 2 9

0 8

F 0

0 8

F 5

0 8

F F

0 0 2 9

5

d t

0 x

f 0

,

0 x

f 5

,

0 x

f f

,

0 x

f a

0 8

F A

0 4 2

D

0 8

E B

0 8

E E

0 8

E 4

0 0 2 9

6

d t

0 x e

b ,

0 x e e ,

0 x e

4 ,

0 x e

1

0 8

E 1

0 4 3 1

0 8

A 0

0 8

A 5

0 8

A F

0 0 2 9

7

d t

0 x a

0 ,

0 x a

5 ,

0 x a

f ,

0 x a a

0 8

A A

0 4 3 5

0 8

B B

0 8

B E

0 8

B 4

0 0 2 9

8

d t

0 x

b b

,

0 x

b e ,

0 x

b 4

,

0 x

b 1

0 8

B 1

0 4 3 9

0 8 9 3

0 8 9 6

0 8 9

C

0 0 2 9

9

d t

0 x

9 3

,

0 x

9 6

,

0 x

9 c ,

0 x

9 9

0 8 9 9

0 4 3

D

0 8 8 8

0 8 8

D

0 8 8 7

0 0 3 0

0

d t

0 x

8 8

,

0 x

8 d

,

0 x

8 7

,

0 x

8 2

0 8 8 2

0 4 4 1

0 8 8 3

0 8 8 6

0 8 8

C

0 0 3 0

1

d t

0 x

8 3

,

0 x

8 6

,

0 x

8 c ,

0 x

8 9

0 8 8 9

0 4 4 5

0 8 9 8

0 8 9

D

0 8 9 7

0 0 3 0

2

d t

0 x

9 8

,

0 x

9 d

,

0 x

9 7

,

0 x

9 2

0 8 9 2

0 4 4 9

0 8

B 0

0 8

B 5

0 8

B F

0 0 3 0

3

d t

0 x

b 0

,

0 x

b 5

,

0 x

b f

,

0 x

b a

0 8

B A

0 4 4

D

0 8

A B

0 8

A E

0 8

A 4

0 0 3 0

4

d t

0 x a

b ,

0 x a e ,

0 x a

4 ,

0 x a

1

0 8

A 1

0 4 5 1

0 8

E 0

0 8

E 5

0 8

E F

0 0 3 0

5

d t

0 x e

0 ,

0 x e

5 ,

0 x e

f ,

0 x e a

0 8

E A

0 4 5 5

0 8

F B

0 8

F E

0 8

F 4

0 0 3 0

6

d t

0 x

f b

,

0 x

f e ,

0 x

f 4

,

0 x

f 1

0 8

F 1

0 4 5 9

0 8

D 3

0 8

D 6

0 8

D C

0 0 3 0

7

d t

0 x

d 3

,

0 x

d 6

,

0 x

d c ,

0 x

d 9

0 8

D 9

0 4 5

D

0 8

C 8

0 8

C D

0 8

C 7

0 0 3 0

8

d t

0 x c

8 ,

0 x c

d ,

0 x c

7 ,

0 x c

2

0 8

C 2

0 4 6 1

0 8 4 0

0 8 4 5

0 8 4

F

0 0 3 0

9

d t

0 x

4 0

,

0 x

4 5

,

0 x

4 f

,

0 x

4 a

0 8 4

A

0 4 6 5

0 8 5

B

0 8 5

E

0 8 5 4

0 0 3 1

0

d t

0 x

5 b

,

0 x

5 e ,

0 x

5 4

,

0 x

5 1

0 8 5 1

0 4 6 9

0 8 7 3

0 8 7 6

0 8 7

C

0 0 3 1

1

d t

0 x

7 3

,

0 x

7 6

,

0 x

7 c ,

0 x

7 9

0 8 7 9

0 4 6

D

0 8 6 8

0 8 6

D

0 8 6 7

0 0 3 1

2

d t

0 x

6 8

,

0 x

6 d

,

0 x

6 7

,

0 x

6 2

0 8 6 2

0 4 7 1

0 8 2 3

0 8 2 6

0 8 2

C

0 0 3 1

3

d t

0 x

2 3

,

0 x

2 6

,

0 x

2 c ,

0 x

2 9

0 8 2 9

0 4 7 5

0 8 3 8

0 8 3

D

0 8 3 7

0 0 3 1

4

d t

0 x

3 8

,

0 x

3 d

,

0 x

3 7

,

0 x

3 2

0 8 3 2

0 4 7 9

0 8 1 0

0 8 1 5

0 8 1

F

0 0 3 1

5

d t

0 x

1 0

,

0 x

1 5

,

0 x

1 f

,

0 x

1 a

0 8 1

A

Page 21: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 21/24

© 2000 Microchip Technology Inc. Preliminary DS00730A-page 21

AN730

0 4 7

D

0 8 0

B

0 8 0

E

0 8 0 4

0 0 3 1

6

d t

0 x

b ,

0 x e ,

0 x

4 ,

0 x

1

0 8 0 1

0 4 8 1

0 8 0 3

0 8 0 6

0 8 0

C

0 0 3 1

7

d t

0 x

3 ,

0 x

6 ,

0 x c ,

0 x

9

0 8 0 9

0 4 8 5

0 8 1 8

0 8 1

D

0 8 1 7

0 0 3 1

8

d t

0 x

1 8

,

0 x

1 d

,

0 x

1 7

,

0 x

1 2

0 8 1 2

0 4 8 9

0 8 3 0

0 8 3 5

0 8 3

F

0 0 3 1

9

d t

0 x

3 0

,

0 x

3 5

,

0 x

3 f

,

0 x

3 a

0 8 3

A

0 4 8

D

0 8 2

B

0 8 2

E

0 8 2 4

0 0 3 2

0

d t

0 x

2 b

,

0 x

2 e ,

0 x

2 4

,

0 x

2 1

0 8 2 1

0 4 9 1

0 8 6 0

0 8 6 5

0 8 6

F

0 0 3 2

1

d t

0 x

6 0

,

0 x

6 5

,

0 x

6 f

,

0 x

6 a

0 8 6

A

0 4 9 5

0 8 7

B

0 8 7

E

0 8 7 4

0 0 3 2

2

d t

0 x

7 b

,

0 x

7 e ,

0 x

7 4

,

0 x

7 1

0 8 7 1

0 4 9 9

0 8 5 3

0 8 5 6

0 8 5

C

0 0 3 2

3

d t

0 x

5 3

,

0 x

5 6

,

0 x

5 c ,

0 x

5 9

0 8 5 9

0 4 9

D

0 8 4 8

0 8 4

D

0 8 4 7

0 0 3 2

4

d t

0 x

4 8

,

0 x

4 d

,

0 x

4 7

,

0 x

4 2

0 8 4 2

0 4

A 1

0 8

C 0

0 8

C 5

0 8

C F

0 0 3 2

5

d t

0 x c

0 ,

0 x c

5 ,

0 x c

f ,

0 x c a

0 8

C A

0 4

A 5

0 8

D B

0 8

D E

0 8

D 4

0 0 3 2

6

d t

0 x

d b

,

0 x

d e ,

0 x

d 4

,

0 x

d 1

0 8

D 1

0 4

A 9

0 8

F 3

0 8

F 6

0 8

F C

0 0 3 2

7

d t

0 x

f 3

,

0 x

f 6

,

0 x

f c ,

0 x

f 9

0 8

F 9

0 4

A D

0 8

E 8

0 8

E D

0 8

E 7

0 0 3 2

8

d t

0 x e

8 ,

0 x e

d ,

0 x e

7 ,

0 x e

2

0 8

E 2

0 4

B 1

0 8

A 3

0 8

A 6

0 8

A C

0 0 3 2

9

d t

0 x a

3 ,

0 x a

6 ,

0 x a c ,

0 x a

9

0 8

A 9

0 4

B 5

0 8

B 8

0 8

B D

0 8

B 7

0 0 3 3

0

d t

0 x

b 8

,

0 x

b d

,

0 x

b 7

,

0 x

b 2

0 8

B 2

0 4

B 9

0 8 9 0

0 8 9 5

0 8 9

F

0 0 3 3

1

d t

0 x

9 0

,

0 x

9 5

,

0 x

9 f

,

0 x

9 a

0 8 9

A

0 4

B D

0 8 8

B

0 8 8

E

0 8 8 4

0 0 3 3

2

d t

0 x

8 b

,

0 x

8 e ,

0 x

8 4

,

0 x

8 1

0 8 8 1

0 4

C 1

0 8 8 0

0 8 8 5

0 8 8

F

0 0 3 3

3

d t

0 x

8 0

,

0 x

8 5

,

0 x

8 f

,

0 x

8 a

0 8 8

A

0 4

C 5

0 8 9

B

0 8 9

E

0 8 9 4

0 0 3 3

4

d t

0 x

9 b

,

0 x

9 e ,

0 x

9 4

,

0 x

9 1

0 8 9 1

0 4

C 9

0 8

B 3

0 8

B 6

0 8

B C

0 0 3 3

5

d t

0 x

b 3

,

0 x

b 6

,

0 x

b c ,

0 x

b 9

0 8

B 9

0 4

C D

0 8

A 8

0 8

A D

0 8

A 7

0 0 3 3

6

d t

0 x a

8 ,

0 x a

d ,

0 x a

7 ,

0 x a

2

0 8

A 2

0 4

D 1

0 8

E 3

0 8

E 6

0 8

E C

0 0 3 3

7

d t

0 x e

3 ,

0 x e

6 ,

0 x e c ,

0 x e

9

0 8

E 9

0 4

D 5

0 8

F 8

0 8

F D

0 8

F 7

0 0 3 3

8

d t

0 x

f 8

,

0 x

f d

,

0 x

f 7

,

0 x

f 2

0 8

F 2

0 4

D 9

0 8

D 0

0 8

D 5

0 8

D F

0 0 3 3

9

d t

0 x

d 0

,

0 x

d 5

,

0 x

d f

,

0 x

d a

Page 22: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 22/24

AN730

DS00730A-page 22 Preliminary © 2000 Microchip Technology Inc.

0 8

D A

0 4

D D

0 8

C B

0 8

C E

0 8

C 4

0 0 3 4

0

d t

0 x c

b ,

0 x c e ,

0 x c

4 ,

0 x c

1

0 8

C 1

0 4

E 1

0 8 4 3

0 8 4 6

0 8 4

C

0 0 3 4

1

d t

0 x

4 3

,

0 x

4 6

,

0 x

4 c ,

0 x

4 9

0 8 4 9

0 4

E 5

0 8 5 8

0 8 5

D

0 8 5 7

0 0 3 4

2

d t

0 x

5 8

,

0 x

5 d

,

0 x

5 7

,

0 x

5 2

0 8 5 2

0 4

E 9

0 8 7 0

0 8 7 5

0 8 7

F

0 0 3 4

3

d t

0 x

7 0

,

0 x

7 5

,

0 x

7 f

,

0 x

7 a

0 8 7

A

0 4

E D

0 8 6

B

0 8 6

E

0 8 6 4

0 0 3 4

4

d t

0 x

6 b

,

0 x

6 e ,

0 x

6 4

,

0 x

6 1

0 8 6 1

0 4

F 1

0 8 2 0

0 8 2 5

0 8 2

F

0 0 3 4

5

d t

0 x

2 0

,

0 x

2 5

,

0 x

2 f

,

0 x

2 a

0 8 2

A

0 4

F 5

0 8 3

B

0 8 3

E

0 8 3 4

0 0 3 4

6

d t

0 x

3 b

,

0 x

3 e ,

0 x

3 4

,

0 x

3 1

0 8 3 1

0 4

F 9

0 8 1 3

0 8 1 6

0 8 1

C

0 0 3 4

7

d t

0 x

1 3

,

0 x

1 6

,

0 x

1 c ,

0 x

1 9

0 8 1 9

0 4

F D

0 8 0 8

0 8 0

D

0 8 0 7

0 0 3 4

8

d t

0 x

8 ,

0 x

d ,

0 x

7

0 0 3 4

9

0 0 3 5

0

E N D

P r o g r a m

M e m o r y

W o r

d s

U s e

d :

6 2 1

P r o g r a m

M e m o r y

W o r

d s

F r e e :

1 4 2 7

E r r o r s

:

0

W a r n

i n g s

:

0

r e p o r t e

d ,

0

s u p p r e s s e

d

M e s s a g e s

:

5

r e p o r t e

d ,

0

s u p p r e s s e

d

Page 23: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 23/24

Page 24: CRC Calculation

8/6/2019 CRC Calculation

http://slidepdf.com/reader/full/crc-calculation 24/24

Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates.It is your responsibility to ensure that your application meets with your specifications. No representation or warranty is given and no liability is assumed byMicrochip Technology Incorporated with respect to the accuracy or use of such information, or infringement of patents or other intellectual property rightsarising from such use or otherwise. Use of Microchip’s products as critical components in life support systems is not authorized except with express writtenapproval by Microchip. No licenses are conveyed, implicitly or otherwise, except as maybe explicitly expressed herein, under any intellectual property

All rights reserved. © 2000 Microchip Technology Incorporated. Printed in the USA. 5/00 Printed on recycled paper.

AMERICASCorporate OfficeMicrochip Technology Inc.2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-786-7200 Fax: 480-786-7277Technical Support: 480-786-7627Web Address: http://www.microchip.com

AtlantaMicrochip Technology Inc.500 Sugar Mill Road, Suite 200BAtlanta, GA 30350Tel: 770-640-0034 Fax: 770-640-0307BostonMicrochip Technology Inc.5 Mount Royal Avenue

Marlborough, MA 01752Tel: 508-480-9990 Fax: 508-480-8575ChicagoMicrochip Technology Inc.333 Pierce Road, Suite 180Itasca, IL 60143Tel: 630-285-0071 Fax: 630-285-0075DallasMicrochip Technology Inc.4570 Westgrove Drive, Suite 160Addison, TX 75248Tel: 972-818-7423 Fax: 972-818-2924DaytonMicrochip Technology Inc.Two Prestige Place, Suite 150Miamisburg, OH 45342Tel: 937-291-1654 Fax: 937-291-9175DetroitMicrochip Technology Inc.Tri-Atria Office Building32255 Northwestern Highway, Suite 190Farmington Hills, MI 48334Tel: 248-538-2250 Fax: 248-538-2260Los AngelesMicrochip Technology Inc.18201 Von Karman, Suite 1090Irvine, CA 92612Tel: 949-263-1888 Fax: 949-263-1338New YorkMicrochip Technology Inc.150 Motor Parkway, Suite 202Hauppauge, NY 11788Tel: 631-273-5305 Fax: 631-273-5335San JoseMicrochip Technology Inc.2107 North First Street, Suite 590

San Jose, CA 95131Tel: 408-436-7950 Fax: 408-436-7955

AMERICAS (continued)TorontoMicrochip Technology Inc.5925 Airport Road, Suite 200Mississauga, Ontario L4V 1W1, CanadaTel: 905-405-6279 Fax: 905-405-6253

ASIA/PACIFICChina - BeijingMicrochip Technology, BeijingUnit 915, 6 Chaoyangmen Bei DajieDong Erhuan Road, Dongcheng DistrictNew China Hong Kong Manhattan BuildingBeijing, 100027, P.R.C.Tel: 86-10-85282100 Fax: 86-10-85282104China - ShanghaiMicrochip TechnologyUnit B701, Far East International Plaza,No. 317, Xianxia RoadShanghai, 200051, P.R.C.Tel: 86-21-6275-5700 Fax: 86-21-6275-5060Hong KongMicrochip Asia PacificUnit 2101, Tower 2Metroplaza223 Hing Fong RoadKwai Fong, N.T., Hong KongTel: 852-2-401-1200 Fax: 852-2-401-3431IndiaMicrochip Technology Inc.India Liaison OfficeNo. 6, Legacy, Convent RoadBangalore, 560 025, IndiaTel: 91-80-229-0061 Fax: 91-80-229-0062Japan

Microchip Technology Intl. Inc.Benex S-1 6F3-18-20, ShinyokohamaKohoku-Ku, Yokohama-shiKanagawa, 222-0033, JapanTel: 81-45-471- 6166 Fax: 81-45-471-6122KoreaMicrochip Technology Korea168-1, Youngbo Bldg. 3 FloorSamsung-Dong, Kangnam-KuSeoul, KoreaTel: 82-2-554-7200 Fax: 82-2-558-5934

ASIA/PACIFIC (continued)SingaporeMicrochip Technology Singapore Pte Ltd.200 Middle Road#07-02 Prime CentreSingapore, 188980Tel: 65-334-8870 Fax: 65-334-8850TaiwanMicrochip Technology Taiwan10F-1C 207Tung Hua North RoadTaipei, TaiwanTel: 886-2-2717-7175 Fax: 886-2-2545-0139

EUROPEDenmarkMicrochip Technology Denmark ApSRegus Business CentreLautrup hoj 1-3Ballerup DK-2750 DenmarkTel: 45 4420 9895 Fax: 45 4420 9910FranceArizona Microchip Technology SARLParc d’Activite du Moulin de Massy43 Rue du Saule TrapuBatiment A - ler Etage91300 Massy, FranceTel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79GermanyArizona Microchip Technology GmbHGustav-Heinemann-Ring 125D-81739 München, GermanyTel: 49-89-627-144 0 Fax: 49-89-627-144-44ItalyArizona Microchip Technology SRL

Centro Direzionale ColleoniPalazzo Taurus 1 V. Le Colleoni 120041 Agrate BrianzaMilan, ItalyTel: 39-039-65791-1 Fax: 39-039-6899883United KingdomArizona Microchip Technology Ltd.505 Eskdale RoadWinnersh TriangleWokinghamBerkshire, England RG41 5TUTel: 44 118 921 5858 Fax: 44-118 921-5835

03/23/00

WORLDWIDE SALES AND SERVICE

Microchip received QS-9000 quality system certification for its worldwide headquarters,design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 1999. The Company’s quality system processes and procedures are QS-9000 compliant for its PICmicro ® 8-bit MCUs, K EE LOQ ® code hopping devices, Serial EEPROMs and microperipheral products. In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001 certified.