led.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #include "led.h"
  2. #include "key.h"
  3. #include "HT16C22.h"
  4. #include "FreeRTOS.h"
  5. #include "task.h"
  6. #include "pwm.h"
  7. #include "All_define.h"
  8. int Is_blink=0;
  9. Led_struct led_struct;
  10. void Set_LCD_lum(u16 lum)
  11. {
  12. switch(lum)
  13. {
  14. /* case 1:TIM_SetCompare1(TIM5,400);break;
  15. case 2:TIM_SetCompare1(TIM5,500);break;
  16. case 3:TIM_SetCompare1(TIM5,600);break;
  17. case 4:TIM_SetCompare1(TIM5,700);break;
  18. case 5:TIM_SetCompare1(TIM5,800);break;
  19. case 6:TIM_SetCompare1(TIM5,900);break;
  20. case 7:TIM_SetCompare1(TIM5,1000);break;*/
  21. case 1:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 400);break;
  22. case 2:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 500);break;
  23. case 3:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 600);break;
  24. case 4:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 700);break;
  25. case 5:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 800);break;
  26. case 6:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 900);break;
  27. case 7:timer_channel_output_pulse_value_config(TIMER4, TIMER_CH_0, 1000);break;
  28. default:break;
  29. }
  30. }
  31. void delay_led_sec(uint32_t sec)
  32. {
  33. for(int i=0;i<sec;i++)
  34. {
  35. for(int j=0;j<10;j++)
  36. Delay_SS();
  37. }
  38. }
  39. void Zigbee_led_blink(void)
  40. {
  41. uint16_t Low_value = dis_page_param.face_plate_param.Led_Brightness & 0x0f00;
  42. int i=0;
  43. for(i=0;i<90;i++)
  44. {
  45. //vTaskDelay(1000);
  46. if(Is_blink==1)
  47. {
  48. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, 0);//
  49. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, 0);
  50. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, 0);
  51. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, 0);//
  52. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, 0);
  53. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, 0);//
  54. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, 0);//
  55. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, 0);
  56. //delay_led_sec(1);
  57. vTaskDelay(1000);
  58. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, 650);//
  59. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, 650);
  60. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, 650);
  61. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, 650);//
  62. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, 650);
  63. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, 650);//
  64. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, 650);//
  65. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, 650);
  66. /*timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, 650);//
  67. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, 650);
  68. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, 650);
  69. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, 650);//
  70. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, 650);
  71. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, 650);//
  72. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, 650);//
  73. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, 650);*/
  74. //delay_led_sec(1);
  75. vTaskDelay(1000);
  76. //timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, 0);
  77. }
  78. else
  79. {
  80. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, 0);//
  81. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, 0);
  82. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, 0);
  83. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, 0);//
  84. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, 0);
  85. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, 0);//
  86. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, 0);//
  87. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, 0);
  88. // if(led_open==1)
  89. // dis_page_param.face_plate_param.Led_Brightness |= 0x0100;
  90. break;
  91. }
  92. }
  93. }
  94. void Press_Key_Set(u8 key)
  95. {
  96. u16 light = 0;
  97. if(led_struct.led_pwm_value <1) led_struct.led_pwm_value = 1;
  98. switch(led_struct.led_pwm_value)
  99. {
  100. case 1:light = 350;break;
  101. case 2:light = 450;break;
  102. case 3:light = 550;break;
  103. case 4:light = 650;break;
  104. case 5:light = 750;break;
  105. case 6:light = 850;break;
  106. default:break;
  107. }
  108. if(Is_blink==0)
  109. {
  110. switch(key)
  111. {
  112. case 6:
  113. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, light);//
  114. break;
  115. case 4:
  116. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, light);
  117. break;
  118. case 3:
  119. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, light);
  120. break;
  121. case 0:
  122. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, light);//
  123. break;
  124. case 2:
  125. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, light);
  126. break;
  127. case 7:
  128. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, light);//
  129. break;
  130. case 1:
  131. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, light);//
  132. break;
  133. case 5:
  134. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, light);
  135. break;
  136. default:break;
  137. }
  138. }
  139. }
  140. void Press_Key_up_Set(u8 key)
  141. {
  142. u16 light = 0;
  143. if(led_struct.led_low_off_flag == 1)
  144. {
  145. light = 0;
  146. }
  147. else if(led_struct.led_low_off_flag == 0)
  148. {
  149. light = 100;
  150. }
  151. if(Is_blink==0)
  152. {
  153. switch(key)
  154. {
  155. case 6:
  156. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, light);//
  157. break;
  158. case 4:
  159. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, light);
  160. break;
  161. case 3:
  162. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, light);
  163. break;
  164. case 0:
  165. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, light);//
  166. break;
  167. case 2:
  168. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, light);
  169. break;
  170. case 7:
  171. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, light);//
  172. break;
  173. case 1:
  174. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, light);//
  175. break;
  176. case 5:
  177. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, light);
  178. break;
  179. default:break;
  180. }
  181. }
  182. }
  183. void Press_Key_Lum(void)
  184. {
  185. u8 i;
  186. uint8_t temp = 0;
  187. temp = KEY_GET;
  188. for(i=0; i<8; i++)
  189. {
  190. if((~temp&0x01<<i) != 0)
  191. Press_Key_Set(i+1);
  192. }
  193. }
  194. void Set_led_lum(u16 lum)
  195. {
  196. /*TIM_SetCompare4(TIM8,lum);//key1
  197. TIM_SetCompare1(TIM1,lum);//key2
  198. TIM_SetCompare2(TIM3,lum);//key3
  199. TIM_SetCompare3(TIM3,lum);//key4
  200. TIM_SetCompare4(TIM3,lum);//key5
  201. TIM_SetCompare1(TIM8,lum);//key6
  202. TIM_SetCompare2(TIM8,lum);//key7
  203. TIM_SetCompare3(TIM8,lum);//key8*/
  204. if(Is_blink==0)
  205. {
  206. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_3, lum);
  207. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_2, lum);
  208. timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, lum);
  209. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_1, lum);
  210. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_1, lum);
  211. timer_channel_output_pulse_value_config(TIMER7, TIMER_CH_0, lum);
  212. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_2, lum);
  213. timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_3, lum);
  214. }
  215. }