C51 COMPILER V9.53.0.0 MULTI_LED 08/23/2018 15:10:01 PAGE 1 C51 COMPILER V9.53.0.0, COMPILATION OF MODULE MULTI_LED OBJECT MODULE PLACED IN .\Output\multi_led.obj COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE Code\User\Driver\multi_led.c LARGE OPTIMIZE(2,SPEED) BROWSE INCDIR(Code/ -Include;Code/User;Code/User/Common;Code/User/Driver) DEFINE(FOSC_160000) DEBUG OBJECTEXTEND PRINT(.\Output\LST\multi_led -.lst) TABS(2) OBJECT(.\Output\multi_led.obj) line level source 1 /******************************************************************************/ 2 /* -- 居加居-- */ 3 /* 4 // 文件名: 5 // 说明: 6 // 编写人员:kinve 7 // 编写日期:2018-8-21 8 // 程序维护: 9 // 维护记录: 10 // 11 // 12 */ 13 // 免责声明: 14 // (c) Anxinke Corporation. All rights reserved. 15 /******************************************************************************/ 16 #include "multi_led.h" 17 18 #define EVENT_CB(state) if(handle->led_set_gpio) handle->led_set_gpio((bool)state) 19 20 //button handle list head. 21 static struct Led* head_handle = NULL; 22 23 /** 24 * @brief Initializes the button struct handle. 25 * @param handle: the button handle strcut. 26 * @param pin_level: read the HAL GPIO of the connet button level. 27 * @param active_level: pressed GPIO level. 28 * @retval None 29 */ 30 void led_init_Head(void) 31 { 32 1 head_handle = NULL; 33 1 } 34 void led_init(struct Led* handle, LedCallback led_set_gpio) 35 { 36 1 memset(handle, 0, sizeof(struct Led)); 37 1 handle->led_set_gpio = led_set_gpio; 38 1 } 39 40 void led_set_state(struct Led* handle, u8 ID, u8 OnOff, u8 Type, u16 FlashTime, u16 CloseTime, bool Res ) 41 { 42 1 if ( Type < LED_STATE_MAX ) 43 1 { 44 2 handle->Play.ID = ID; 45 2 handle->Play.Type = Type; 46 2 47 2 if ( Type != LED_STATE4_NOT ) 48 2 { 49 3 handle->Play.OnOff = OnOff; 50 3 } 51 2 52 2 handle->Play.FlashTime = FlashTime; 53 2 handle->Play.CloseTime = CloseTime; C51 COMPILER V9.53.0.0 MULTI_LED 08/23/2018 15:10:01 PAGE 2 54 2 handle->Play.Count = 0; 55 2 handle->Play.Res = Res; 56 2 } 57 1 } 58 59 60 /** 61 * @brief Button driver core function, driver state machine. 62 * @param handle: the button handle strcut. 63 * @retval None 64 */ 65 void led_handler(struct Led* handle) 66 { 67 1 switch ( handle->Play.Type ) 68 1 { 69 2 case LED_STATE0_OFF: //关 70 2 EVENT_CB(false); 71 2 handle->Play.Type = LED_STATE_MAX; 72 2 break; 73 2 74 2 case LED_STATE1_ON: //开 75 2 EVENT_CB(true); 76 2 handle->Play.Type = LED_STATE_MAX; 77 2 break; 78 2 79 2 case LED_STATE2_FLASH: //闪烁 80 2 handle->Play.Count += LED_SCAN; 81 2 82 2 if ( handle->Play.Count >= handle->Play.FlashTime ) 83 2 { 84 3 handle->Play.Count = 0; 85 3 EVENT_CB(handle->Play.OnOff); 86 3 handle->Play.OnOff = !handle->Play.OnOff; 87 3 } 88 2 89 2 break; 90 2 91 2 case LED_STATE3_CONUT: //定时开关 92 2 if ( handle->Play.CloseTime > 0 ) 93 2 { 94 3 handle->Play.CloseTime -= LED_SCAN; 95 3 EVENT_CB(handle->Play.Res); //开始 96 3 } 97 2 else 98 2 { 99 3 handle->Play.CloseTime = 0; 100 3 EVENT_CB(!handle->Play.Res); //结束,与结果相反 101 3 handle->Play.Type = LED_STATE_MAX; 102 3 } 103 2 104 2 break; 105 2 106 2 case LED_STATE4_NOT: //取反 107 2 EVENT_CB(!handle->Play.OnOff); 108 2 handle->Play.Type = LED_STATE_MAX; 109 2 break; 110 2 111 2 case LED_STATE5_FLASH_DELAY: //闪烁,延时关闭 112 2 if ( handle->Play.CloseTime > 0 ) 113 2 { 114 3 handle->Play.CloseTime -= LED_SCAN; 115 3 //闪烁 C51 COMPILER V9.53.0.0 MULTI_LED 08/23/2018 15:10:01 PAGE 3 116 3 handle->Play.Count += LED_SCAN; //开始 117 3 118 3 if ( handle->Play.Count >= handle->Play.FlashTime ) 119 3 { 120 4 handle->Play.Count = 0; 121 4 EVENT_CB(handle->Play.OnOff); 122 4 handle->Play.OnOff = !handle->Play.OnOff; 123 4 } 124 3 } 125 2 else 126 2 { 127 3 handle->Play.CloseTime = 0; 128 3 EVENT_CB(handle->Play.Res); //结束,与结果 129 3 handle->Play.Type = LED_STATE_MAX; 130 3 } 131 2 132 2 break; 133 2 } 134 1 } 135 136 /** 137 * @brief Start the button work, add the handle into work list. 138 * @param handle: target handle strcut. 139 * @retval 0: succeed. -1: already exist. 140 */ 141 int led_start(struct Led* handle) 142 { 143 1 struct Led* target = head_handle; 144 1 while(target) { 145 2 if(target == handle) return -1; //already exist. 146 2 target = target->next; 147 2 } 148 1 handle->next = head_handle; 149 1 head_handle = handle; 150 1 return 0; 151 1 } 152 153 /** 154 * @brief Stop the button work, remove the handle off work list. 155 * @param handle: target handle strcut. 156 * @retval None 157 */ 158 void led_stop(struct Led* handle) 159 { 160 1 struct Led** curr; 161 1 for(curr = &head_handle; *curr; ) { 162 2 struct Led* entry = *curr; 163 2 if (entry == handle) { 164 3 *curr = entry->next; 165 3 // free(entry); 166 3 } else { 167 3 curr = &entry->next; 168 3 } 169 2 } 170 1 } 171 172 /** 173 * @brief background ticks, timer repeat invoking interval 5ms. 174 * @param None. 175 * @retval None 176 */ 177 void led_ticks() C51 COMPILER V9.53.0.0 MULTI_LED 08/23/2018 15:10:01 PAGE 4 178 { 179 1 struct Led* target; 180 1 for(target=head_handle; target; target=target->next) { 181 2 led_handler(target); 182 2 } 183 1 } 184 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 2014 ---- CONSTANT SIZE = ---- ---- XDATA SIZE = 3 38 PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)