Bit Shift difference between PIC16 and PIC18 ???


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012
    Posts
    2

    Default Bit Shift difference between PIC16 and PIC18 ???

    Hi,

    This is my first post here, normally the depth of knowledge on this forum is so great - that a search always results in help.

    But this problem has me stumped and searching has not pulled anything which will explain what is going on, probably user error.

    My code is as follows
    Code:
    TempWord1 var WORD
    TempWord2 var WORD
    CRC16 var WORD
    
        CRC16 = $FFFF     
        for j = 0 to 48           ' parse through each byte in serial data
            TempWord1 = (CRC16 >> 8) ^ SerialData[i]
            CRC16 = CRC16 << 8
            TempWord2 = TempWord1 ^ (TempWord1 >> 4)
            CRC16 = CRC16 ^ TempWord2
            TempWord2 = TempWord2 << 5
            CRC16 = CRC16 ^ TempWord2
            TempWord2 = TempWord2 << 7
            CRC16 = CRC16 ^ TempWord2 
        next j
    So my problem if I run this code on a PIC16F1936 then a PIC18F46K20, the resulting CRC16 value is different for the same data array (SerialData).

    So I investigated further by watching the variables in a simulator and noticed this. (before anyone asks the simulator running the code on 16f1936 works ok.)

    PIC16F1936
    CRC16 = $FFFF
    CRC16 >> 8 = $01FF

    PIC18F46K20
    CRC16 = $FFFF
    CRC16 >> 8 = $FFFF

    I also noticed the bit shift operation is not effecting the high byte of the word variables in the loop when running on the 18f46k20.

    So am I going mad or is there something I do not understand that is different between the pic16 and pic18's.

    Help please...

    bambi123

  2. #2
    Join Date
    Feb 2012
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Bit Shift difference between PIC16 and PIC18 ???

    Ok scrub this, realised I was not counting up the serial data!!! user error as usual!!

    bambi123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts