LED闪烁控制函数

led.h

/*
=================================================
FileName:   	led_drv.h
Description:  	led驱动函数文件 
Author:			
=================================================
*/
#ifndef LED_DRV_H
#define LED_DRV_H


#include "tm1640.h"


/** LED标志符定义 */
typedef enum {
	LED_pm2_5 = 0, //PM2.5符号         
 	LED_vocL, //voc等级L          
 	LED_vocM,             
 	LED_vocH,            
 	LED_vocHplus, //voc等级H+    
	LED_voc,
	LED_tempSig, //温度符号
	LED_humidSig, //湿度符号
	LED_brise,
	LED_auto,
	LED_turbo,
	LED_eco,
	LED_fan, //风扇符号
	LED_wind1,
	LED_wind2,
	LED_wind3,
	LED_wind4,
	LED_wind5,
	LED_wind6,
	LED_frontStra,//前置滤网
	LED_backStra, //后置滤网
 	LED_Count, // number of led
}LED_Id;

/** LED可能的显示状态定义 */
typedef enum {
	LED_StateOff = 0,          
	LED_StateOn,                
	LED_StateBlink,           
	LED_StateCount,            
}LED_State;


#define LED_pm2_5_putVal(x) 		do{if(x)ledBuf[0] |= BIT7;else ledBuf[0] &= ~BIT7;}while(0)//PM2.5符号, LED8         
#define LED_vocL_putVal(x)			do{if(x)ledBuf[6] |= BIT7;else ledBuf[6] &= ~BIT7;}while(0) //voc等级L, LED61          
#define LED_vocM_putVal(x)			do{if(x)ledBuf[7] |= BIT7;else ledBuf[7] &= ~BIT7;}while(0) //LED69           
#define LED_vocH_putVal(x)			do{if(x)ledBuf[8] |= BIT7;else ledBuf[8] &= ~BIT7;}while(0) //LED70           
#define LED_vocHplus_putVal(x)		do{if(x)ledBuf[8] |= BIT0;else ledBuf[8] &= ~BIT0;}while(0) //voc等级H+, LED77    
#define	LED_voc_putVal(x)			do{if(x)ledBuf[2] |= BIT7;else ledBuf[2] &= ~BIT7;}while(0) //LED28
#define	LED_tempSig_putVal(x)		do{if(x)ledBuf[4] |= BIT7;else ledBuf[4] &= ~BIT7;}while(0)//温度符号, LED45
#define	LED_humidSig_putVal(x)		do{if(x)ledBuf[5] |= BIT7;else ledBuf[5] &= ~BIT7;}while(0)//湿度符号, LED53
#define	LED_brise_putVal(x)			do{if(x)ledBuf[8] |= BIT6;else ledBuf[8] &= ~BIT6;}while(0) //LED71
#define	LED_auto_putVal(x)			do{if(x)ledBuf[8] |= BIT5;else ledBuf[8] &= ~BIT5;}while(0) //LED72
#define	LED_turbo_putVal(x)			do{if(x)ledBuf[8] |= BIT4;else ledBuf[8] &= ~BIT4;}while(0) //LED73
#define	LED_eco_putVal(x)			do{if(x)ledBuf[8] |= BIT3;else ledBuf[8] &= ~BIT3;}while(0) //LED74
#define	LED_fan_putVal(x)			do{if(x)ledBuf[7] |= BIT6;else ledBuf[7] &= ~BIT6;}while(0)//风扇符号, LED62
#define	LED_wind1_putVal(x)			do{if(x)ledBuf[7] |= BIT5;else ledBuf[7] &= ~BIT5;}while(0) //LED63 
#define	LED_wind2_putVal(x)			do{if(x)ledBuf[7] |= BIT4;else ledBuf[7] &= ~BIT4;}while(0) //LED64
#define	LED_wind3_putVal(x)			do{if(x)ledBuf[7] |= BIT3;else ledBuf[7] &= ~BIT3;}while(0) //LED65
#define	LED_wind4_putVal(x)			do{if(x)ledBuf[7] |= BIT2;else ledBuf[7] &= ~BIT2;}while(0) //LED66
#define	LED_wind5_putVal(x)			do{if(x)ledBuf[7] |= BIT1;else ledBuf[7] &= ~BIT1;}while(0) //LED67
#define	LED_wind6_putVal(x)			do{if(x)ledBuf[7] |= BIT0;else ledBuf[7] &= ~BIT0;}while(0) //LED68
#define	LED_frontStra_putVal(x)		do{if(x)ledBuf[8] |= BIT2;else ledBuf[8] &= ~BIT2;}while(0)//前置滤网, LED75
#define	LED_backStra_putVal(x)		do{if(x)ledBuf[8] |= BIT1;else ledBuf[8] &= ~BIT1;}while(0)//后置滤网, LED76

extern LED_State leds[21];

void LED_AllOn(void);
void LED_AllOff(void);
void led_refresh(void);
void LED_set(LED_Id id, LED_State state);
	
#endif	
	
	
	

led.c

/*
=================================================
FileName:   	led_drv.c
Description:  	led驱动函数文件 
Author:			
=================================================
*/

#include "led_drv.h"
#include "stdint.h"
#include "globals.h"
#include "systimer.h"


uint8_t blinkTimer;
BOOL_t blinkOn;



/** @brief LED status */
LED_State leds[21] = {LED_StateOff};

void LED_AllOff(void);
/*
======================================================
led闪烁控制
======================================================
*/
void BLINK_Refresh(void)
{
  	if (++blinkTimer >= TM_500MS_0S1) {
    	blinkTimer = 0;
		if(blinkOn == eTRUE){
			blinkOn = eFALSE;
		}	
		else{
			blinkOn = eTRUE;
		}	
  	}
}

/*
======================================================
led闪烁复位
======================================================
*/
void BLINK_Restart(BOOL_t on)
{
  	blinkOn = on;
  	blinkTimer = 0;
}

/*
======================================================
读取闪烁状态
======================================================
*/
BOOL_t BLINK_IsOn(void)
{
  	return blinkOn;
}


/*
===========================================================
led显示刷新
===========================================================
*/
void led_refresh(void)
{
	BOOL_t blinkOn = BLINK_IsOn();
		
	BLINK_Refresh();	
	LED_pm2_5_putVal((leds[LED_pm2_5] == LED_StateOn) ||
	 		((leds[LED_pm2_5] == LED_StateBlink) && blinkOn)); //PM2.5灯
	
  	LED_vocL_putVal((leds[LED_vocL] == LED_StateOn) || 
  			((leds[LED_vocL] == LED_StateBlink) && blinkOn)); //VOC灯
	
  	LED_vocM_putVal((leds[LED_vocM] == LED_StateOn) || 
  			((leds[LED_vocM] == LED_StateBlink) && blinkOn)); // vovM灯
	
  	LED_vocH_putVal((leds[LED_vocH] == LED_StateOn) || 	
  			((leds[LED_vocH] == LED_StateBlink) && blinkOn)); // vocH灯   
	
 	LED_vocHplus_putVal(leds[LED_vocHplus] == LED_StateOn || 	
 					((leds[LED_vocHplus] == LED_StateBlink) && blinkOn)); //vocH+灯                

	LED_voc_putVal(leds[LED_voc] == LED_StateOn || 	
 					((leds[LED_voc] == LED_StateBlink) && blinkOn));//voc灯
	
	LED_tempSig_putVal(leds[LED_tempSig] == LED_StateOn || 	
 					((leds[LED_tempSig] == LED_StateBlink) && blinkOn)); //温度符号灯
					
	LED_humidSig_putVal(leds[LED_humidSig] == LED_StateOn || 	
 					((leds[LED_humidSig] == LED_StateBlink) && blinkOn)); //湿度符号
	
	LED_brise_putVal(leds[LED_brise] == LED_StateOn || 	
 					((leds[LED_brise] == LED_StateBlink) && blinkOn)); //brise模式灯
	
	LED_auto_putVal(leds[LED_auto] == LED_StateOn || 	
 					((leds[LED_auto] == LED_StateBlink) && blinkOn)); //auto模式灯
	
	LED_turbo_putVal(leds[LED_turbo] == LED_StateOn || 	
 					((leds[LED_turbo] == LED_StateBlink) && blinkOn)); //turbo模式灯
	
	LED_eco_putVal(leds[LED_eco] == LED_StateOn || 	
 					((leds[LED_eco] == LED_StateBlink) && blinkOn)); //eco模式灯
					
	LED_fan_putVal(leds[LED_fan] == LED_StateOn || 	
 					((leds[LED_fan] == LED_StateBlink) && blinkOn)); //风扇符号灯
	
	LED_wind1_putVal(leds[LED_wind1] == LED_StateOn || 	
 					((leds[LED_wind1] == LED_StateBlink) && blinkOn)); //风扇档位灯1
	
	LED_wind2_putVal(leds[LED_wind2] == LED_StateOn || 	
 					((leds[LED_wind2] == LED_StateBlink) && blinkOn)); //风扇档位灯2
					
	LED_wind3_putVal(leds[LED_wind3] == LED_StateOn || 	
 					((leds[LED_wind3] == LED_StateBlink) && blinkOn)); //风扇档位灯3
					
	LED_wind4_putVal(leds[LED_wind4] == LED_StateOn || 	
 					((leds[LED_wind4] == LED_StateBlink) && blinkOn)); //风扇档位灯4
	
	LED_wind5_putVal(leds[LED_wind5] == LED_StateOn || 	
 					((leds[LED_wind5] == LED_StateBlink) && blinkOn)); //风扇档位灯5
					
	LED_wind6_putVal(leds[LED_wind6] == LED_StateOn || 	
 					((leds[LED_wind6] == LED_StateBlink) && blinkOn)); //风扇档位灯6
					
	LED_frontStra_putVal(leds[LED_frontStra] == LED_StateOn || 	
 					((leds[LED_frontStra] == LED_StateBlink) && blinkOn)); //前置滤网灯
					
	LED_backStra_putVal(leds[LED_backStra] == LED_StateOn || 	
 					((leds[LED_backStra] == LED_StateBlink) && blinkOn)); //后置滤网灯
}


/*
===========================================================
关闭所有led显示
===========================================================
*/
void LED_AllOff(void)
{
	LED_pm2_5_putVal(0);
	LED_vocL_putVal(0);
	LED_vocM_putVal(0);
	LED_vocH_putVal(0);
	LED_vocHplus_putVal(0);
	LED_voc_putVal(0);
	LED_tempSig_putVal(0);
	LED_humidSig_putVal(0);
	LED_brise_putVal(0);
	LED_auto_putVal(0);
	LED_turbo_putVal(0);
	LED_eco_putVal(0);
	LED_fan_putVal(0);
	LED_wind1_putVal(0);
	LED_wind2_putVal(0);
	LED_wind3_putVal(0);
	LED_wind4_putVal(0);
	LED_wind5_putVal(0);
	LED_wind6_putVal(0);
	LED_frontStra_putVal(0);
	LED_backStra_putVal(0);
}

/*
===========================================================
点亮所有指示灯
===========================================================
*/
void LED_AllOn(void)
{
	LED_pm2_5_putVal(TRUE);
	LED_vocL_putVal(TRUE);
	LED_vocM_putVal(TRUE);
	LED_vocH_putVal(TRUE);
	LED_vocHplus_putVal(TRUE);
	LED_voc_putVal(TRUE);
	LED_tempSig_putVal(TRUE);
	LED_humidSig_putVal(TRUE);
	LED_brise_putVal(TRUE);
	LED_auto_putVal(TRUE);
	LED_turbo_putVal(TRUE);
	LED_eco_putVal(TRUE);
	LED_fan_putVal(TRUE);
	LED_wind1_putVal(TRUE);
	LED_wind2_putVal(TRUE);
	LED_wind3_putVal(TRUE);
	LED_wind4_putVal(TRUE);
	LED_wind5_putVal(TRUE);
	LED_wind6_putVal(TRUE);
	LED_frontStra_putVal(TRUE);
	LED_backStra_putVal(TRUE);
}	


/*
===========================================================
led 显示状态设置
===========================================================
*/
void LED_set(LED_Id id, LED_State state)
{
  	if((id < LED_Count) && (state < LED_StateCount)){
    	leds[id] = state;
  	}else{
		LED_AllOff();
	}
//  	led_refresh();
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值