CRC.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* --------------------------- (C) COPYRIGHT 2021 Fortiortech ShenZhen -----------------------------
  2. File Name : CRC.c
  3. Author : Fortiortech Appliction Team
  4. Version : V1.0
  5. Date : 2021-04-11
  6. Description : This file contains .C file function used for Motor Control.
  7. ----------------------------------------------------------------------------------------------------
  8. All Rights Reserved
  9. ------------------------------------------------------------------------------------------------- */
  10. #include <Myproject.h>
  11. /****************************************************************************
  12. CRC16_CCITT_FALSE 硬件实现
  13. ****************************************************************************/
  14. unsigned short CRC_Check(unsigned char start_sector , unsigned char offset_sector)
  15. {
  16. unsigned short crcresult = 0x0000;
  17. unsigned short tempH = 0x00;
  18. unsigned short tempL = 0x00;
  19. SetBit(CRC_CR , CRCVAL); //0-->0x0000 1-->0xffff
  20. SetBit(CRC_CR , CRCDINI); //1-->init success
  21. CRC_BEG = start_sector; //起始扇区
  22. CRC_CNT = offset_sector; //扇区偏移量 0-->1个扇区
  23. //1个空扇区-->0x41E8 2个空扇区-->0x1634
  24. //1个0xFF -->0x5B2F 0x00~0xFF-->0x3FBD
  25. SetBit(CRC_CR , AUTOINT); //自动计算使能
  26. /***************************************************/
  27. SetBit(CRC_CR , CRCPNT);
  28. tempH = CRC_DR;
  29. ClrBit(CRC_CR , CRCPNT);
  30. tempL = CRC_DR;
  31. crcresult = (unsigned short)(tempH << 8) + tempL;
  32. return crcresult;
  33. }