fan.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // Created by DELL on 2025/2/10.
  3. //
  4. #include "fan.h"
  5. #include "main.h"
  6. #include "tim.h"
  7. uint8_t dipBuf[3];
  8. uint8_t dipNum;
  9. /**
  10. * 排风风机控制
  11. * @param speed
  12. */
  13. PWMComParam_t PWMComParam[3]=
  14. {
  15. {
  16. .htim=&htim8,
  17. .timChannel=TIM_CHANNEL_1,
  18. },
  19. {
  20. .htim=&htim8,
  21. .timChannel=TIM_CHANNEL_2,
  22. },
  23. {
  24. .htim=&htim8,
  25. .timChannel=TIM_CHANNEL_3,
  26. },
  27. };
  28. dipComParam_t dipComParam[5]=
  29. {
  30. {
  31. .GPIOx=GPIOB,
  32. .GPIO_Pin=GPIO_PIN_5,
  33. },
  34. {
  35. .GPIOx=GPIOB,
  36. .GPIO_Pin=GPIO_PIN_6,
  37. },
  38. {
  39. .GPIOx=GPIOB,
  40. .GPIO_Pin=GPIO_PIN_7,
  41. },
  42. {
  43. .GPIOx=GPIOB,
  44. .GPIO_Pin=GPIO_PIN_8,
  45. },
  46. {
  47. .GPIOx=GPIOB,
  48. .GPIO_Pin=GPIO_PIN_9,
  49. }
  50. };
  51. uint8_t read_dip5()
  52. {
  53. int n=0;
  54. for(int i=0;i<5;i++)
  55. {
  56. if(n>2)
  57. {
  58. break;
  59. }
  60. if(HAL_GPIO_ReadPin(dipComParam[i].GPIOx, dipComParam[i].GPIO_Pin)==GPIO_PIN_RESET)
  61. {
  62. dipBuf[n]=i;
  63. n++;
  64. }
  65. }
  66. if(n==0)
  67. {
  68. n=3;
  69. dipBuf[0]=0;
  70. dipBuf[1]=1;
  71. dipBuf[2]=2;
  72. }
  73. return n;
  74. }
  75. void fan_control(PWMComParam_t PWMParam,uint8_t speed) {
  76. __HAL_TIM_SetCompare(PWMParam.htim, PWMParam.timChannel, speed);
  77. }