声明变量:
uint8_t NDEFSelect[15] = {0x02,0x00,0xA4,0x04,0x00,0x07,0xD2,0x76,0x00,0x00,0x85,0x01,0x01,0x00,0x35,0xC0};
uint8_t selectCCFile[9] = {0x03,0x00,0xA4,0x00,0x0C,0x02,0xE1,0x03,0xD2,0xAF};
函数 CRC16:
uint16_t M24SR_UpdateCrc (uint8_t ch, uint16_t *lpwCrc)
{
ch = (ch^(uint8_t)((*lpwCrc) & 0x00FF));
ch = (ch^(ch<<4));
*lpwCrc = (*lpwCrc >> 8)^((uint16_t)ch << 8)^((uint16_t)ch<<3)^((uint16_t)ch>>4);
return(*lpwCrc);
}
/**
* @brief This function returns the CRC 16
* @param Data : pointer on the data used to compute the CRC16
* @param Length : number of byte of the data
* @retval CRC16
*/
uint16_t M24SR_ComputeCrc(uint8_t *Data, uint8_t Length, uint8_t *crc0, uint8_t *crc1)
{
uint8_t chBlock = 0;
uint16_t wCrc = 0;
wCrc = 0x6363; // ITU-V.41
do {
chBlock = *Data++;
M24SR_UpdateCrc(chBlock, &wCrc);
} while (--Length);
*crc0 = (uint8_t) (wCrc & 0xFF);
*crc1 = (uint8_t) ((wCrc >> 8) & 0xFF);
return wCrc ;
}
函数调用主循环:
M24SR_ComputeCrc(NDEFSelect, sizeof(NDEFSelect)-1, &(NDEFSelect[14]), &(NDEFSelect[15]));
M24SR_ComputeCrc(selectCCFile, sizeof(selectCCFile)-1, &(selectCCFile[8]), &(selectCCFile[9]));
我认为变量值仍然记得上次函数调用。如何重置此变量?