123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- /**********************************************************************************
- * File Name: LedTask.c
- * Function Describe:The task for LED display
- * Relate Module:
- * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式
- * Writer: ShiLiangWen
- * Date: 2015.2.10
- **********************************************************************************/
- #include "includes.h"
- unsigned char g_ucLedSel;
- unsigned char g_ucLedFlash; //LED闪烁次数,每次亮0.5秒灭0.5秒
- unsigned char g_ucLedSleepTime; //LED熄灭时间,单位:秒
- void LedInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- //Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull
- //在PowerCtrlInit中已经禁止JTAG-DP功能,这里不需要了。
- // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//复用功能IO 时钟使能 这里必须先使能复用IO的时钟,再关闭JTAG功能
- // GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // JTAG-DP Disabled and SW-DP Enabled
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN;
- GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN;
- GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
- MODEM_LED1_LOW;
- MODEM_LED2_LOW;
- g_ucLedSel=LED_SEL_BLUE;
- g_ucLedFlash=0; //LED闪烁次数,每次亮0.5秒灭0.5秒
- g_ucLedSleepTime=0; //LED熄灭时间,单位:秒
- }
- /*******************************************************************
- *LedTask
- ********************************************************************/
- void LedTickMsg(void)
- {
- unsigned char ucLedCt=0;
- static unsigned char sucLedMaxCt=0;
- static unsigned char sucLedFlash2=0;
- static unsigned char sucLastLedFlash=0xff;
- static unsigned char sucLastLedSleepTime=0xff;
- //喂狗
- IWDG_ReloadCounter();
- if(g_ucLedFlash==0){ //长灭
- if(g_ucLedSel){
- MODEM_LED1_LOW;
- }else{
- MODEM_LED2_LOW;
- }
- return;
- }else if(g_ucLedSleepTime==0){//长亮
- if(g_ucLedSel){
- MODEM_LED1_HIGH;
- }else{
- MODEM_LED2_HIGH;
- }
- return;
- }
-
- if(sucLastLedFlash!=g_ucLedFlash || sucLastLedSleepTime!=g_ucLedSleepTime){
- ucLedCt=0;
- sucLastLedFlash=g_ucLedFlash;
- sucLastLedSleepTime=g_ucLedSleepTime;
- sucLedFlash2=g_ucLedFlash*2;
- sucLedMaxCt=sucLedFlash2+g_ucLedSleepTime*2;
- }
-
- if(++ucLedCt>sucLedMaxCt){
- ucLedCt=0;
- }
- if(ucLedCt<sucLedFlash2 && (ucLedCt&0x01)==0x01){
- if(g_ucLedSel){
- MODEM_LED1_HIGH;
- }else{
- MODEM_LED2_HIGH;
- }
- }else{
- if(g_ucLedSel){
- MODEM_LED1_LOW;
- }else{
- MODEM_LED2_LOW;
- }
- }
- }
- void SetLedFlash(unsigned char flash,unsigned char sleep)
- {
- int t=(flash+sleep)*2;
- if(t>255){
- return;
- }
- g_ucLedFlash=flash;
- g_ucLedSleepTime=sleep;
- }
- void LedSlecet(unsigned char sel)
- {
- g_ucLedSel=sel;
-
- }
- /***********************************************************************************/
|