This is the example source code for the Cyclic Redundancy Check (CRC) Module with Memory Scanner

(Microchip microcontroller)

 

volatile unsigned int crc = 0;
const uint8_t data[2] __at(0x800) = {0x6C, 0x93};

unsigned char data_size = 0;
unsigned char data_index = 0;

void main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    
    SCANCON0bits.EN = 1;
    SCANCON0bits.MODE = 0;
    SCANCON0bits.INTM = 0;
    SCANLADR = 0x800;
    SCANHADR = 0x801;
    
  
    CRCCON0bits.EN = 1;
    CRCACC = 0xFFFF;
    CRCXOR = 0x1021;
    CRCCON1bits.DLEN = 15;
    CRCCON1bits.PLEN = 15;
    CRCCON0bits.ACCM = 1;
    CRCCON0bits.SHIFTM = 0;
    CRCCON0bits.CRCGO = 1;
    SCANCON0bits.SCANGO = 1;
    while(SCANCON0bits.SCANGO);
    while(CRCCON0bits.BUSY);
    
    crc = CRCACC;
    
    while (1)
    {
        // Add your application code
    }
}

 

 

Will use 0x346C and 0x3493 value at 0x800 and 0x801 address in flash memory

https://www.lammertbies.nl/comm/info/crc-calculation.html

 

On-line CRC calculation and free library

On-line CRC calculation and free library Loading... Introduction on CRC calculations Whenever digital data is stored or interfaced, data corruption might occur. Since the beginning of computer science, people have been thinking of ways to deal with this ty

www.lammertbies.nl

To verify the CRC Calculation, I used On-line CRC Calculation and free library and put the value as "34633493" with Hex. And I got the calculated value as 0xF659 with CRC-CCITT (0xFFFF) and also I got the value as 0xF659 in MPLAB X debug mode as below.

 

 

CRC_PIC16F1618.X.zip
0.99MB

 

 

Posted by KennyShin
,