ZDBMS/code_app/Led.c

156 lines
3.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************************
Copyright (C), Sinowealth Electronic. Ltd.
Author: Sino
Version: V0.0
Date: 2020/04/26
History:
V2.0 2020/04/26 Preliminary
********************************************************************************/
#include "Main.h"
BOOL bLedDisFlg; //LED显示标志
BOOL bLedDisBleFlg; //蓝牙开启时显示
U8 xdata ucLedTimeCnt;
U8 xdata ucLedChgFlickCnt;
U8 xdata ucLedBleFlickCnt;
/*************************************************************************************************
* 函数名: LedGetDisNum
* 参 数: Rsoc剩余容量百分比
* 返回值: 无
* 描 述: 根据剩余容量百分比计算当前显示的LED数
*************************************************************************************************/
U8 LedGetDisNum(U16 Rsoc)
{
if(Rsoc > 80)
{
return 5;
}
else if(Rsoc > 60)
{
return 4;
}
else if(Rsoc > 40)
{
return 3;
}
else if(Rsoc > 20)
{
return 2;
}
else if(Rsoc > 0)
{
return 1;
}
else
{
return 0;
}
}
/*************************************************************************************************
* 函数名: LedAutoOff
* 参 数: 无
* 返回值: 无
* 描 述: 按键显示LED持续5S后关闭LED显示
*************************************************************************************************/
void LedAutoOff(void)
{
if(bLedDisFlg)
{
if(++ucLedTimeCnt >= 100) //100*50mS
{
ucLedTimeCnt = 0;
bLedDisFlg = 0;
}
}
}
/*************************************************************************************************
* 函数名: LedDisplay
* 参 数: 无
* 返回值: 无
* 描 述: 显示LED
充电时充电LED指示灯以500mS周期闪烁
蓝牙开启时蓝牙指示灯以250mS周期闪烁
显示容量时LED开启5s后自动熄灭
*************************************************************************************************/
void LedDisplay(void)
{
U8 LedDisNum;
if(bCHGING) //显示充电状态
{
if(++ucLedChgFlickCnt >= 10) //10*50mS
{
ucLedChgFlickCnt = 0;
IO_LED_CHARGE ^= 1;
}
}
else
{
IO_LED_CHARGE = 0;
}
if(bLedDisBleFlg) //显示蓝牙开启状态
{
if(++ucLedBleFlickCnt >= 5) //5*50mS
{
ucLedBleFlickCnt = 0;
// IO_LED_BLE ^= 1;
}
}
else
{
// IO_LED_BLE = 0;
}
if(bLedDisFlg) //显示容量信息
{
LedDisNum = LedGetDisNum(Info.uiRSOC);
if(LedDisNum == 0)
{
// LEDAllOff();
}
if(LedDisNum == 1)
{
// LED1On();
}
else if(LedDisNum == 2)
{
// LED1On();
LED2On();
}
else if(LedDisNum == 3)
{
// LED1On();
LED2On();
LED3On();
}
else if(LedDisNum == 4)
{
// LED1On();
LED2On();
LED3On();
LED4On();
}
else if(LedDisNum == 5)
{
// LEDAllOn();
}
}
else
{
// LEDAllOff();
}
LedAutoOff(); //定时5s关闭容量LED显示
}