1
0

led.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. @copyright None
  3. @file led.c
  4. @author Comment Vivre
  5. @date 2025-12-19
  6. @brief None
  7. */
  8. #include <MyProject.h>
  9. LED_State_t ledState = LED_STATE_OFF;
  10. LED_Count_t ledCount;
  11. /**
  12. @function LED_GPIO_Init
  13. @brief LED GPIO初始化
  14. @date 2025-12-19
  15. */
  16. void LED_GPIO_Init(void)
  17. {
  18. SetBit(LED_PXIN, LED_PINX);
  19. LED_OFF;
  20. }
  21. /**
  22. @function LED_State_Display
  23. @brief 指示运行与故障代码
  24. @param[in] Xn0: [输入/出] 故障代码
  25. @date 2025-05-30
  26. */
  27. void LED_State_Display(unsigned char Xn0)
  28. {
  29. switch (ledState)
  30. {
  31. // 关闭状态
  32. case LED_STATE_OFF:
  33. // 存在故障 切入故障状态 清零计数
  34. if (Xn0)
  35. {
  36. ledState = LED_STATE_BLINK_FAULT;
  37. ledCount.PauseDelayCnt = 0;
  38. ledCount.BlinkCnt = 0;
  39. }
  40. // 开启状态且无故障 切入开启状态并打开LED
  41. else if (isCtrlPowOn)
  42. {
  43. ledState = LED_STATE_ON;
  44. LED_ON;
  45. }
  46. break;
  47. // 开启状态
  48. case LED_STATE_ON:
  49. // 故障或停止时 关闭LED并切回关闭状态
  50. if (!isCtrlPowOn || Xn0)
  51. {
  52. ledState = LED_STATE_OFF;
  53. LED_OFF;
  54. }
  55. break;
  56. // 故障指示状态
  57. case LED_STATE_BLINK_FAULT:
  58. ledCount.PauseDelayCnt ++;
  59. // 延时等待
  60. if (ledCount.PauseDelayCnt >= 500)
  61. {
  62. ledCount.PauseDelayCnt = 0;
  63. LEDPinONOFF;
  64. // 灭灯时计数
  65. if (LED_PIN)
  66. {
  67. ledCount.BlinkCnt ++;
  68. // 完成一个周期的闪烁 切换到延时等待模式
  69. if (ledCount.BlinkCnt >= Xn0)
  70. { ledState = LED_STATE_POST_FAULT_DELAY; }
  71. }
  72. }
  73. // 故障清除后 立刻回到熄灭状态
  74. if (!Xn0)
  75. {
  76. LED_OFF;
  77. ledState = LED_STATE_OFF;
  78. }
  79. break;
  80. // 延迟等待
  81. case LED_STATE_POST_FAULT_DELAY:
  82. ledCount.PauseDelayCnt ++;
  83. // 延时满足或故障清除回到关闭状态
  84. if ((ledCount.PauseDelayCnt >= 1000) || (!Xn0))
  85. { ledState = LED_STATE_OFF; }
  86. break;
  87. }
  88. }