Both_Way_Comm_SY8833/TP3310_Demo.si4project/Backup/led(7241).c

233 lines
4.8 KiB
C
Raw Permalink 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.

/*
******************************************************************************
*
* @file led.c
* @brief led module
* @ic TP3102
*
* @version 1.0
* @date 2022/08/04 15:00:40
* @author Alex Xu
*
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
* All Rights Reserved
*
* History:
* Revision Date Author Desc
* 1.0.0 2022/08/04 Alex build this file
******************************************************************************/
/*_____ I N C L U D E S ____________________________________________________*/
#include "led.h"
#ifdef LED_DISPLAY
/******************************************************************************\
Macro definitions
\******************************************************************************/
/******************************************************************************\
Variables definitions
\******************************************************************************/
static idata TS_LED_INFO LED;
/******************************************************************************\
Functions definitions
\******************************************************************************/
/*
* 函数名称 : LED_Init
* 功能描述 : LED初始化
* 参 数 : NONE
* 返回值 : NONE
*/
/******************************************************************************/
void LED_Init(void)
/******************************************************************************/
{
SFRADDR = P0_OE;
SFRDATA = 0x1C;
SFRADDR = P0_DRV;
SFRDATA = 0x3F;
P0 &= ~0x1C;
}
/*
* 函数名称 : LED_On
* 功能描述 : 点亮LED
* 参 数 : LED的ID
* 返回值 : NONE
*/
/******************************************************************************/
static void LED_On(uint8_t LedId)
/******************************************************************************/
{
switch(LedId)
{
case LED_R:
LEDR_ON();
break;
case LED_G:
LEDG_ON();
break;
case LED_B:
LEDB_ON();
break;
default:
break;
}
}
/*
* 函数名称 : LED_Off
* 功能描述 : 熄灭LED
* 参 数 : LED的ID
* 返回值 : NONE
*/
/******************************************************************************/
static void LED_Off(uint8_t LedId)
/******************************************************************************/
{
switch(LedId)
{
case LED_R:
LEDR_OFF();
break;
#if 0
case LED_G:
LEDG_OFF();
break;
case LED_B:
LEDB_OFF();
break;
#endif
default:
break;
}
}
/*
* 函数名称 : LED_Clr
* 功能描述 : 熄灭全部LED
* 参 数 : NONE
* 返回值 : NONE
*/
#if 0
/******************************************************************************/
void LED_Clr(void)
/******************************************************************************/
{
uint8_t i = 0;
for(i=0; i<LED_ID_MAX; i++)
{
LED.State[i] = LED_OFF;
LED.Flash_Duty[i] = 0;
LED.Flash_Period[i] = 0;
LED.Flash_Times[i] = 0;
LED.Timer[i] = 0;
}
}
#endif
/*
* 函数名称 : LED_Set
* 功能描述 : LED工作方式设置
* 参 数 : LedIdID / State工作方式 / Duty:闪烁占空比(百分百1-100) / Period:闪烁周期(频率单位ms) / Times:闪烁次数
* 返回值 : NONE
*/
/******************************************************************************/
void LED_Set(uint8_t LedId,uint8_t State,uint8_t Period,uint8_t Times)
/******************************************************************************/
{
LED.State[LedId] = State;
LED.Flash_Duty[LedId] = Period / 2;
LED.Flash_Period[LedId] = Period;
LED.Flash_Times[LedId] = Times;
LED.Timer[LedId] = 0;
}
/*
* 函数名称 : LED_Service
* 功能描述 : LED驱动需放在100ms时间片中
* 参 数 : NONE
* 返回值 : NONE
*/
/******************************************************************************/
void LED_Drv(void)
/******************************************************************************/
{
uint8_t i = 0;
for(i = 0;i < LED_ID_MAX;i++)
{
switch(LED.State[i])
{
case LED_ON:
LED_On(i);
break;
case LED_OFF:
LED_Off(i);
break;
case LED_FLASH:
if( LED.Timer[i] < LED.Flash_Duty[i] )
{
LED_On(i);
}
else
{
LED_Off(i);
}
if( LED.Timer[i] >= LED.Flash_Period[i] )//LED.Timer[i]表示累加的时间
{
LED.Timer[i] = 0;
if( LED.Flash_Times[i] > 0 )
{
LED.Flash_Times[i]--;
}
if( LED.Flash_Times[i] == 0 )
{
LED.State[i] = LED_OFF;
}
}
break;
case LED_KEEP_FLASHING:
if( LED.Timer[i] <= LED.Flash_Duty[i] )
{
LED_On(i);
}
else
{
LED_Off(i);
}
if( LED.Timer[i] >= LED.Flash_Period[i] )
{
LED.Timer[i] = 0;
}
break;
default:
LED_Off(i);
break;
}
}
for(i = 0;i < LED_ID_MAX;i++)
{
LED.Timer[i] += LED_PLUS_TIME;
}
}
#endif