crccheck.c

来自「PIC_Hi-Tech_C_Mike_Pearces_Dallas_1-wire」· C语言 代码 · 共 43 行

C
43
字号

unsigned char CRC;       //-- CRC Value, must be cleared before each run

//***********************************************************************
//                           CRC_Calc
//                            V0.0.0
//                         4 August 2000
//
// This calculates the CRC for one byte of data for Dallas DS182x devices
// To do a string of bytes, just feed each into this function without
// resetting the CRC value.
// Note: Before each CRC Generation set CRC = 0.
//***********************************************************************
//  Version 0.0.0 - 4 August 2000
//  First draft of code - not actually working yet!!!
//***********************************************************************
void CRC_Calc(Data)
{
 unsigned char temp,count,carry;
 for(count=0;count<8;count++)
 {
  temp=Data ^ CRC;
  carry=0;
  if((temp & 0x01)==1)
  {
   carry=1;
  }
  temp=CRC;
  if(temp !=0)
  {
   temp=temp ^ 0x18;
  }
  temp = temp >>1;
  temp &=0x7F;     // ensure bit 8 is clear
  if(carry==1)
  {
   temp |= 0x80;   // Move carry into top bit
  }
  CRC=temp;        // Store the CRC
  Data = Data >>1; // position the next data for adding to the CRC
 }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?