BuzzerScan.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* *************************** (C) COPYRIGHT 2015 Fortiortech shenzhen *****************************
  2. File Name : BuzzerScan.c
  3. Author : Billy Long Fortiortech Market Dept
  4. Version : V1.0
  5. Date : 01/07/2015
  6. Description : This file contains Buzzer Scan function used for Motor Control.
  7. ***************************************************************************************************
  8. All Rights Reserved
  9. **************************************************************************************************/
  10. /* Includes -------------------------------------------------------------------------------------*/
  11. #include <FU68xx_4.h>
  12. #include <MyProject.h>
  13. /* Private variables ----------------------------------------------------------------------------*/
  14. BZScan_TypeDef xdata BZScan;
  15. /* -------------------------------------------------------------------------------------------------
  16. Function Name : void BuzzerInit(void)
  17. Description : 按键参数初始化
  18. Input : 无
  19. Output : 无
  20. -------------------------------------------------------------------------------------------------*/
  21. void BuzzerInit(void)
  22. {
  23. BZScan.FlagBZ = 0;
  24. BZScan.BZRunTime = 0;
  25. BZScan.BZCnt = 0;
  26. BZScan.BZMultitimes = 0;
  27. BZScan.BZMultitimesCount = 0;
  28. }
  29. /* -------------------------------------------------------------------------------------------------
  30. Function Name : void SetBuzzer(uint8 Length)
  31. Description : 置位蜂鸣器鸣叫标志
  32. Input : Length:响铃长度 单位:100ms
  33. Output : 无
  34. -------------------------------------------------------------------------------------------------*/
  35. void SetBuzzer(uint8 BZRunTime, uint8 BZMultitimes)
  36. {
  37. BZScan.FlagBZ = 1;
  38. BZScan.BZRunTime = BZRunTime;
  39. BZScan.BZMultitimes = BZMultitimes;
  40. }
  41. /* ----------------------------------------------------------------------------------------------*/
  42. /* Function Name : BuzzerScan
  43. /* Description : 蜂鸣器,BZScan.BZRunTime控制时间长度
  44. /* Date : 2020-03-25
  45. /* Parameter : None
  46. /* ----------------------------------------------------------------------------------------------*/
  47. void BuzzerScan(void)
  48. {
  49. if (BZScan.BZMultitimes > 0)
  50. {
  51. BZScan.BZMultitimesCount++;
  52. if (BZScan.BZMultitimesCount % 200 == 0)
  53. {
  54. BZScan.BZMultitimesCount = 0;
  55. BZScan.FlagBZ = 1;
  56. }
  57. }
  58. else
  59. {
  60. BZScan.FlagBZ = 0;
  61. BZScan.BZMultitimesCount = 0;
  62. }
  63. if (BZScan.FlagBZ && BZScan.BZMultitimes)
  64. {
  65. SetBit(TIM3_CR1, T3EN);
  66. // SetBit(TIM4_CR1, T4EN);
  67. // SetBit(PH_SEL, T4SEL);
  68. BZScan.BZCnt ++;
  69. if (BZScan.BZCnt >= (100 * BZScan.BZRunTime))
  70. {
  71. BZScan.BZCnt = 0;
  72. BZScan.FlagBZ = 0;
  73. ClrBit(TIM3_CR1, T3EN);
  74. ResetBUZZERPin;
  75. // ClrBit(TIM4_CR1, T4EN);
  76. // ClrBit(PH_SEL, T4SEL);
  77. // ResetBUZZERPin;
  78. // BZScan.BZMultitimes = 0;
  79. BZScan.BZMultitimes--;
  80. }
  81. }
  82. }