;*********************************************************************************** ;MAKE_CRC16 - This routine generates a CRC-16 shift register from the data byte stored ;in the DATA_REG register. DATA_TEMP0 and DATA_TEMP1 are used to buffer the data ;and prevent it from being corrupted by the CRC-16 generation process. ;*********************************************************************************** MAKE_CRC16 movf DATA_REG,W movwf DATA_TEMP0 ;Store data in temporary register movlw '00001000'b ;Set counter for 8 data bits movwf NUMBER_BITS ;Load counter register More_Rotates movf DATA_TEMP0,W ;Move buffered data to 2nd buffer movwf DATA_TEMP1 ;This register is corrupted with every pass movf CRC16_HI,W ;Move upper shift register to working reg. xorwf DATA_TEMP1 ;XOR shift register with data register btfss DATA_TEMP1,7 ;MSB is XOR of stage16 and input data bit goto No_Xorwf ;If bit is clear then no complement of stage2,15 movlw '00000010'b ;Prepare to complement stage2 xorwf CRC16_LO ;Complement stage2 of shift register movlw '01000000'b ;Prepare to complement stage15 xorwf CRC16_HI ;Complement stage15 of shift register No_Xorwf rlf DATA_TEMP0 ;Rotate next data bit into position rlf DATA_TEMP1 ;Rotate XOR of input into CRC16_LO rlf CRC16_LO ;Shift CRC16 register rlf CRC16_HI ;Shift CRC16 register decfsz NUMBER_BITS ;Count out 8 data bits goto More_Rotates ;Not finished with this data byte return ;This byte is finished