此程序可以实现led闪烁的频率和执行时间,若有不足之处,请指正
上传原工程文件,环境:MDK5.12,MK64FN1M0VLQ12
以下为部分代码
- //定义并初始化led结构体
- led_blink_t led3_blink = {0,0,0,0,0,0,LED3open,LED3close,ledBlink};
- led_blink_t led4_blink = {0,0,0,0,0,0,LED4open,LED4close,ledBlink};
- led_blink_t led5_blink = {0,0,0,0,0,0,LED5open,LED5close,ledBlink};
- led_blink_t led6_blink = {0,0,0,0,0,0,LED6open,LED6close,ledBlink};
- led_blink_t *ledBlinkTable[led_start_end] = {
- &led3_blink,
- &led4_blink,
- &led5_blink,
- &led6_blink,
- };
- /*************************************************************************
- ** Function Name :
- ** Description : led闪烁控制
- ** Input :
- ** Return :
- ** Notice :
- **************************************************************************/
- static uint8_t ledBlink( struct led_blink_s *led )
- {
- if(led->workstatus)
- {
- if( led->worktime )//LED工作时间判断
- {
- if(led->worktime > 1)led->worktime -= 1;
- else
- {
- uint8_t status = led->workstatus;
- led->workstatus = 0;
- led->worktime = 0;
- led->openCount = 0;
- led->closeCount = 0;
- led->led_close();
- return status;
- }
- }
-
- if(led->openCount <= led->opentime)
- {
- led->openCount++;
- led->closeCount = 0;
- led->led_open();
- }
- else
- {
- led->closeCount++;
- led->led_close();
- if(led->closeCount > led->closetime)led->openCount = 0;
- }
- }
- return 0;
- }
- /*************************************************************************
- ** Function Name :
- ** Description : 开启LED
- ** Input : start:led编号,
- worktime:led工作时间,0为永久工作,时间单位为led_working_loop执行周期时间
- opentime:led亮灯时间
- closetime:led关灯时间
- status:led状态,工作为1
- ** Return :
- ** Notice :
- **************************************************************************/
- void led_start( uint8_t start ,uint32_t worktime,uint32_t opentime,uint32_t closetime,uint8_t status)
- {
- ledBlinkTable[start] ->workstatus = status;
- ledBlinkTable[start] ->worktime = worktime/(1000/LED_BASE_TIME_PER_SEC);
- ledBlinkTable[start] ->opentime = opentime/(1000/LED_BASE_TIME_PER_SEC);
- ledBlinkTable[start] ->closetime = closetime/(1000/LED_BASE_TIME_PER_SEC);
- ledBlinkTable[start] ->openCount = 0;
- ledBlinkTable[start] ->closeCount = 0;
- }
- /*************************************************************************
- ** Function Name :
- ** Description : 关闭led
- ** Input :
- ** Return :
- ** Notice :
- **************************************************************************/
- void led_close( uint8_t start )
- {
- ledBlinkTable[start] ->workstatus = 0;
- ledBlinkTable[start] ->worktime = 0;
- ledBlinkTable[start] ->opentime = 0;
- ledBlinkTable[start] ->closetime = 0;
- ledBlinkTable[start] ->openCount = 0;
- ledBlinkTable[start] ->closeCount = 0;
- ledBlinkTable[start] ->led_close();
- }
- /*************************************************************************
- ** Function Name :
- ** Description : 周期性执行,执行频率LED_BASE_TIME_PER_SEC
- ** Input :
- ** Return :
- ** Notice :
- **************************************************************************/
- void led_working_loop(void)
- {
- uint8_t i,temp;
-
- for(i = 0;i< led_start_end;i++)
- {
- temp |= ledBlinkTable[i] ->led_blink( ledBlinkTable[i] );
- }
- }
复制代码
是的,对应lv5的
一周热门 更多>