1
0

CRC.c 1008 B

12345678910111213141516171819202122232425262728293031
  1. #include <MyProject.h>
  2. /****************************************************************************
  3. CRC16_CCITT_FALSE 硬件实现
  4. ****************************************************************************/
  5. unsigned short CRC_Check(unsigned char start_sector , unsigned char offset_sector)
  6. {
  7. unsigned short crcresult = 0x0000;
  8. unsigned short tempH = 0x00;
  9. unsigned short tempL = 0x00;
  10. SetBit(CRC_CR , CRCVAL); //0-->0x0000 1-->0xffff
  11. SetBit(CRC_CR , CRCDINI); //1-->init success
  12. CRC_BEG = start_sector; //起始扇区
  13. CRC_CNT = offset_sector; //扇区偏移量 0-->1个扇区
  14. //1个空扇区-->0x41E8 2个空扇区-->0x1634
  15. //1个0xFF -->0x5B2F 0x00~0xFF-->0x3FBD
  16. SetBit(CRC_CR , AUTOINT); //自动计算使能
  17. /***************************************************/
  18. SetBit(CRC_CR , CRCPNT);
  19. tempH = CRC_DR;
  20. ClrBit(CRC_CR , CRCPNT);
  21. tempL = CRC_DR;
  22. crcresult = (unsigned short)(tempH << 8) + tempL;
  23. return crcresult;
  24. }