CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

CRC16 problem with forum code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

CRC16 problem with forum code
PostPosted: Sat Jun 26, 2010 5:07 pm     Reply with quote

Hi,

I need to use CRC16-1021 and I get the code from the forum library, I use a PIC18F8722 and this is my code:
Code:

int16 CRC16_1021( int16 lCRC, char *sBuffer, int iLen )
{
#if 0
    int8        iPtr;
    int8        iCRC[2];

    iCRC[ 0 ] = make8( lCRC, 1 );
    iCRC[ 1 ] = make8( lCRC, 0 );
   
    *(0x0FE9) = sBuffer;                // FSR0 = sBuffer;
   
    do
    {
   
        #ASM
            movf  0x0FEE,w              // 0x0FEE = POSTINC0
            xorwf iCRC[0],w             // (a^x):(b^y)
            movwf iPtr                  //
            andlw 0xf0                  // W = (a^x):0
            swapf iPtr,f                // Index = (b^y):(a^x)
            xorwf iPtr,f                // Index = (a^b^x^y):(a^x) = i2:i1
           
           
                                        // High byte
            movf  iPtr,W
            andlw 0xf0
            xorwf iCRC[1],W
            movwf iCRC[0]
           
            rlcf  iPtr,W                // use rlf for PIC16
            rlcf  iPtr,W                // use rlf for PIC16
            xorwf iCRC[0],f
            andlw 0xe0
            xorwf iCRC[0],f
           
            swapf iPtr,F
            xorwf iPtr,W
            movwf iCRC[1]
        #ENDASM
       
    } while ( --iLen );
       
    return make16( iCRC[ 0 ], iCRC[ 1 ] );

#else

    int         iPtr;
    int16       lTmp;


    for ( iPtr = 0 ; iPtr < iLen ; iPtr++ )
    {
        lTmp  = ( make8( lCRC, 1 ) ^ sBuffer[ iPtr ] );
       
        lTmp ^= lTmp >> 4;

        lCRC = ( lCRC << 8 ) ^ ( lTmp << 12 ) ^ ( lTmp << 5) ^ lTmp;
    }
   
    return lCRC;
   
#endif   
}

I found a problem with this array:
Quote:

0x03 0x02 0x00 0x9A 0x5B 0x10 0x00 0x00 0x00

But when I use the C code the result is 0x105C, and when use the ASM code the result is 0x32AE.

What is wrong?? For other array the result is the same in both code.

Anyone can help me ?

Can verify this using this link:
http://www.lammertbies.nl/comm/info/crc-calculation.html

Thanks
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group