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

160 lines
3.4 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;
idata uint8_t Display_Sta = LED_OFF; // 显示状态
/******************************************************************************\
Functions definitions
\******************************************************************************/
#if 0
/*
* 函数名称 : LED_Init
* 功能描述 : LED初始化
* 参 数 : NONE
* 返回值 : NONE
*/
/******************************************************************************/
void LED_Init(void)
/******************************************************************************/
{
SFRADDR = P0_OE;
SFRDATA |= 0x08;
SFRADDR = P0_DRV;
SFRDATA = 0x0C;
pin_LED_1 = 0;
}
#endif
/*
* 函数名称 : LED_Set
* 功能描述 : LED工作方式设置
* 参 数 : State工作方式 / Period:闪烁周期(频率单位ms) / Times:闪烁次数当次数等于0xff时一直闪。
* 返回值 : NONE
*/
/******************************************************************************/
void LED_Set(uint8_t State,uint8_t Period,uint8_t Times)
/******************************************************************************/
{
LED.State = State;
LED.Flash_Duty = Period / 2;
LED.Flash_Period = Period;
LED.Flash_Times = Times;
LED.Timer = 0;
}
/*
* 函数名称 : LED_Service
* 功能描述 : LED驱动需放在100ms时间片中
* 参 数 : NONE
* 返回值 : NONE
*/
/******************************************************************************/
void LED_Drv(void)
/******************************************************************************/
{
switch(LED.State)
{
case LED_ON:
LEDR_ON();
break;
case LED_OFF:
LEDR_OFF();
break;
case LED_FLASH:
if( LED.Timer < LED.Flash_Duty )
{
LEDR_ON();
}
else
{
LEDR_OFF();
}
if( LED.Timer >= LED.Flash_Period )//LED.Timer[i]表示累加的时间
{
LED.Timer = 0;
if( LED.Flash_Times == 0xff )
{
break;
}
else
{
if( LED.Flash_Times > 0 )
{
LED.Flash_Times--;
}
if( LED.Flash_Times == 0 )
{
LED.State = LED_OFF;
}
}
}
break;
#if 0
case LED_KEEP_FLASHING:
if( LED.Timer <= LED.Flash_Duty )
{
LEDR_ON();
}
else
{
LEDR_OFF();
}
if( LED.Timer >= LED.Flash_Period )
{
LED.Timer = 0;
}
break;
#endif
default:
LEDR_OFF();
break;
}
Display_Sta = LED.State; // 获取当前LED工作状态。
LED.Timer += LED_PLUS_TIME;
}
#endif