R_Led.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*********************************************************************************************************
  2. * Module : R_Led.c
  3. * Abstract : R_Led module displays the relay status!
  4. * Version : 1.0.0
  5. * Author : Leopul(COPYRIGHT 2025 - 2027 Leopul. All rights reserved.)
  6. * Complete : 2025-02-16
  7. * Content : None
  8. * Note : None
  9. *********************************************************************************************************/
  10. #include "R_Led.h"
  11. #include "gd32f30x_libopt.h"
  12. #include "Sn74lvc573.h"
  13. #include "main.h"
  14. #define POWER_R2_Y GPIO_PIN_12
  15. #define POWER_R2_G GPIO_PIN_11
  16. #define POWER_R2_R GPIO_PIN_10
  17. #define POWER_R1_Y GPIO_PIN_9
  18. #define POWER_R1_G GPIO_PIN_8
  19. #define POWER_R1_R GPIO_PIN_7
  20. #define POWER_OUT_R GPIO_PIN_2
  21. #define POWER_OUT_G GPIO_PIN_3
  22. #define POWER_OUT_Y GPIO_PIN_4
  23. uint16_t led_status = 0;
  24. void r_led_init(void)
  25. {
  26. rcu_periph_clock_enable(RCU_GPIOC);
  27. gpio_init(GPIOC,GPIO_MODE_OUT_PP,GPIO_OSPEED_50MHZ,POWER_R2_Y |POWER_R2_G| POWER_R2_R | POWER_R1_Y | POWER_R1_G | POWER_R1_R | POWER_OUT_R | POWER_OUT_G | POWER_OUT_Y);
  28. gpio_bit_reset(GPIOC, POWER_R2_Y |POWER_R2_G| POWER_R2_R | POWER_R1_Y | POWER_R1_G | POWER_R1_R | POWER_OUT_R | POWER_OUT_G | POWER_OUT_Y);
  29. }
  30. void in_r_led_on_off(unsigned char channel)
  31. {
  32. // if(channel == 0)
  33. // {
  34. // gpio_bit_set(GPIOB, GPIO_PIN_2);
  35. // gpio_bit_reset(GPIOB, GPIO_PIN_10);
  36. // }else
  37. // {
  38. // gpio_bit_reset(GPIOB, GPIO_PIN_2);
  39. // gpio_bit_set(GPIOB, GPIO_PIN_10);
  40. // }
  41. }
  42. void out_r_led(unsigned char status)
  43. {
  44. // if(status == 0)
  45. // {
  46. // gpio_bit_set(GPIOB, GPIO_PIN_11);
  47. // }else
  48. // {
  49. // gpio_bit_reset(GPIOB, GPIO_PIN_11);
  50. // }
  51. }
  52. void show_wanning_led(void)
  53. {
  54. sts_data_t *data = get_sts();
  55. if(data)
  56. {
  57. uint16_t value = 0;
  58. if(data->m_data.input_status.input_status[0] && data->m_data.input_status.input_status[1])
  59. {
  60. if(data->m_data.input_wanning.waning[0] == 0 && data->m_data.input_wanning.waning[1] == 0)
  61. {
  62. if(data->m_data.md_choise.choise_ch == INPUT_CHANNEL_1)
  63. {
  64. value |= POWER_R1_G;
  65. }else
  66. {
  67. value |= POWER_R2_G;
  68. }
  69. }else
  70. {
  71. if(data->m_data.input_wanning.waning[0] != 0)
  72. {
  73. value |= POWER_R1_Y;
  74. //value |= POWER_R2_G;
  75. }else
  76. {
  77. value |= POWER_R1_G;
  78. }
  79. if(data->m_data.input_wanning.waning[1] != 0)
  80. {
  81. value |= POWER_R2_Y;
  82. //value |= POWER_R1_G;
  83. }else
  84. {
  85. value |= POWER_R2_G;
  86. }
  87. }
  88. }else
  89. {
  90. if(data->m_data.input_status.input_status[0] == 0)
  91. {
  92. value |=POWER_R1_R;
  93. if(data->m_data.input_status.input_status[1] == 1)
  94. {
  95. if(data->m_data.input_wanning.waning[1] != 0)
  96. {
  97. value |= POWER_R2_Y;
  98. }else
  99. value |=POWER_R2_G;
  100. }
  101. if(data->m_data.input_wanning.waning[0] != 0)
  102. {
  103. value |= POWER_R1_Y;
  104. }
  105. }
  106. if(data->m_data.input_status.input_status[1] == 0)
  107. {
  108. value |=POWER_R2_R;
  109. if(data->m_data.input_status.input_status[0] == 1)
  110. {
  111. if(data->m_data.input_wanning.waning[0] != 0)
  112. {
  113. value |= POWER_R1_Y;
  114. }else
  115. value |=POWER_R1_G;
  116. }
  117. if(data->m_data.input_wanning.waning[1] != 0)
  118. {
  119. value |= POWER_R2_Y;
  120. }
  121. }
  122. }
  123. if(data->m_data.out_status == 1)
  124. {
  125. if(data->m_data.output_waning.waning != 0)
  126. value |= POWER_OUT_Y;
  127. else
  128. value |= POWER_OUT_G;
  129. }else
  130. {
  131. if(data->m_data.output_waning.waning != 0)
  132. value |= POWER_OUT_Y;
  133. value |= POWER_OUT_R;
  134. }
  135. if(value != led_status)
  136. {
  137. led_status = value;
  138. gpio_bit_reset(GPIOC, POWER_R2_Y |POWER_R2_G| POWER_R2_R | POWER_R1_Y | POWER_R1_G | POWER_R1_R | POWER_OUT_R | POWER_OUT_G | POWER_OUT_Y);
  139. gpio_bit_set(GPIOC,led_status);
  140. unlock();
  141. lock();
  142. }
  143. }
  144. }