Relay.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*********************************************************************************************************
  2. * Module : Relay.c
  3. * Abstract : Relay module is used to control external relay,of which combine with latch!
  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 "Relay.h"
  11. #include "gd32e230x_conf.h"
  12. #include "Sn74lvc573.h"
  13. #include "R_Led.h"
  14. #include "main.h"
  15. #define RELAY_1 GPIO_PIN_3
  16. #define RELAY_2 GPIO_PIN_4
  17. static void ConfigRelayGPIO(void);
  18. static void ConfigRelayGPIO(void)
  19. {
  20. rcu_periph_clock_enable(RCU_GPIOB);
  21. gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, RELAY_1);
  22. gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RELAY_1);
  23. gpio_bit_reset(GPIOB, RELAY_1);
  24. gpio_mode_set(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, RELAY_2);
  25. gpio_output_options_set(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RELAY_2);
  26. gpio_bit_reset(GPIOB, RELAY_2);
  27. }
  28. void InitRelay(void)
  29. {
  30. Init74Lvc();
  31. ConfigRelayGPIO();
  32. sts_data_t *data = get_sts();
  33. data->choise_input = choise_input;
  34. data->open_output = out_open;
  35. data->close_output = out_close;
  36. }
  37. void choise_input(uint8_t channel)
  38. {
  39. sts_data_t *data = get_sts();
  40. switch(channel)
  41. {
  42. case 0:
  43. {
  44. unlock();
  45. gpio_bit_reset(GPIOB, RELAY_1);
  46. lock();
  47. data->m_data.md_choise.choise_ch = INPUT_CHANNEL_1;
  48. in_r_led_on_off(channel);
  49. }
  50. break;
  51. case 1:
  52. {
  53. unlock();
  54. gpio_bit_set(GPIOB, RELAY_1);
  55. lock();
  56. data->m_data.md_choise.choise_ch = INPUT_CHANNEL_2;
  57. in_r_led_on_off(channel);
  58. }
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. void out_open()
  65. {
  66. sts_data_t *data = get_sts();
  67. unlock();
  68. gpio_bit_set(GPIOB, RELAY_2);
  69. lock();
  70. out_r_led(0);
  71. data->m_data.out_status = OUT_OPEN;
  72. }
  73. void out_close()
  74. {
  75. sts_data_t *data = get_sts();
  76. unlock();
  77. gpio_bit_reset(GPIOB, RELAY_2);
  78. lock();
  79. out_r_led(1);
  80. data->m_data.out_status = OUT_CLOSE;
  81. }