Quantcast

Mycal's Experimental Homepage Software

Menu
Home
Login

Jump To
  • My Projects
  • Basic Archive
  • Clearlake
  • Archive
  • Articles
  • Links
  • Sandbox
    Search
  • You are at /Archive/

    Parent DirectoryVery small and fast CRC16 for embedded processors


    I used this in an embedded PPP/IP/TCP/UDP stack I wrote in the mid 90's on the PC. But very useful for AVR's, PIC's and other 8bitters.

    
    typedef unsigned short U16;
    
    //(c)1996 www.mycal.com - attribution if used
    //---------------------------------------------------------------------------
    // Simple and fast CRC16 routine for embedded processors.
    //	Just slightly slower than the table lookup method but consumes
    //	almost no space.  Much faster and smaller than the loop and
    //	shift method that is widely used in the embedded space. 
    //	Can be optimized even more in .ASM
    //
    //	data = (crcvalue ^ inputchar) & 0xff;
    //	data = (data ^ (data << 4)) & 0xff;
    //	crc = (crc >> 8) ^ ((data << 8) ^ (data <<3) ^ (data >> 4))
    //---------------------------------------------------------------------------
    U16
    crcadd(U16 crcvalue, U8 c)
    {
    U16	b;
    
       b = (crcvalue ^ c) & 0xFF;
       b = (b ^ (b << 4)) & 0xFF;				
       b = (b << 8) ^ (b << 3) ^ (b >> 4);
       
       return((crcvalue >> 8) ^ b);
    }
    





    Sponsership

    Connect to anyting, anywhere anytime with yoics.







    Last Update at 05-18-2017 7:41 pm
    Copyright 1994-2006 mycal, All Rights Reserved