解释代码void task_touch(void) { gKeyTemp = 0; gKeyTemp = (TK_Info[TK_OUT_DATA0] & 0x07); if(gKeyBak == gKeyTemp) { if(gKeyOld == gKeyTemp) { if(gKeyTemp != 0) { if(gKeyPress >= 1500 && gKeyPress<2500) { if(F_LedSwitch) { F_LedSwitch = 0; } else { F_LedSwitch = 1; } } if(gKeyPress < 2500) { gKeyPress++; } if(gKeyPress >= 2500) { gKeyPress = 2501; } } } else { gKeyOld = gKeyTemp; gKeyPress = 0; if(gKeyTemp != 0) { } else { if(F_LedSwitch) { F_CwLong = 1; if (gKeyPress = 2501) { F_CwLong = 0; if(F_LedSwitch) { F_LedSwitch = 0; } } } } } } else { gKeyBak = gKeyTemp; } } void task_led(void) { static unsigned char sChangeTime = 0; if(F_LedSwitch) { if(++sChangeTime >= 12) { sChangeTime = 0; if(F_CwLong) { if(F_Cwflag) { gDutyW = gDutyW+10; } else { gDutyW = gDutyW-10; } if(gDutyW==0||gDutyW==100) { F_Cwflag = ~F_Cwflag; } gDutyC = 100 - gDutyW; } } gDutySetC = gDutyC * gLight / 100; gDutySetW = gDutyW * gLight / 100; LED_C_DUTY(gDutySetC << 3); LED_W_DUTY(gDutySetW << 3); } else { LED_C_DUTY(0); LED_W_DUTY(0); } }
时间: 2024-03-29 18:41:42 浏览: 11
这是一段嵌入式系统的代码,其中包含了两个任务函数:task_touch 和 task_led。这些函数用于触摸和 LED 灯的控制。
在 task_touch 函数中,首先从 TK_Info 数组中读取触摸传感器的状态,并将其存储在 gKeyTemp 变量中。然后,该函数会检查 gKeyBak 和 gKeyTemp 是否相同,如果相同,则会进一步检查 gKeyOld 和 gKeyTemp 是否相同。如果 gKeyOld 和 gKeyTemp 相同,并且 gKeyTemp 不等于 0,则会检查 gKeyPress 是否大于等于 1500 并且小于 2500。如果是这种情况,则会切换 LED 灯的状态。如果 gKeyPress 小于 2500,则会将其递增。如果 gKeyPress 大于等于 2500,则将其设置为 2501。
如果 gKeyOld 和 gKeyTemp 不相同,则会更新 gKeyOld 和 gKeyPress 的值。如果 gKeyTemp 不等于 0,则不会执行任何其他操作。如果 gKeyTemp 等于 0,则会检查 F_LedSwitch 是否为真,如果是,则将 F_CwLong 设置为 1,并检查 gKeyPress 是否等于 2501。如果是,则将 F_CwLong 设置为 0,将 F_LedSwitch 设置为 0。
在 task_led 函数中,首先检查 F_LedSwitch 是否为真。如果是,则会逐渐调整 LED 灯的亮度。如果 F_CwLong 为真,则会根据 F_Cwflag 的值递增或递减 gDutyW 的值。如果 gDutyW 等于 0 或 100,则会将 F_Cwflag 取反。然后会计算 gDutyC 和 gDutyW 的比例,并将其存储在 gDutySetC 和 gDutySetW 变量中。最后,将 gDutySetC 和 gDutySetW 值左移 3 位,并将其传递给 LED_C_DUTY 和 LED_W_DUTY 函数。如果 F_LedSwitch 不为真,则会将 LED_C_DUTY 和 LED_W_DUTY 函数的参数设置为 0。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)