📄 playled.c
字号:
#include ".\include\system.h"
#include ".\Common\PlaySound.h"
#include ".\Common\PlayLed.h"
unsigned int LedActionStatus, LedActionNo, LedActionOffset, LedActionDelay;
void InitLed()
{
P_IOB_Dir->W |= IOPORT_LED1+IOPORT_LED2+IOPORT_LED3;
P_IOB_Attrib->W |= IOPORT_LED1+IOPORT_LED2+IOPORT_LED3;
P_IOB_Data->W = P_IOB_Buffer->W&(~(IOPORT_LED1+IOPORT_LED2+IOPORT_LED3));
}
void CheckLedDelayEnd()
{
if (--LedActionDelay == 0)
{
//End of led delay
LedActionStatus &= 0xfffd;
LedActionOffset ++;
GetLedAction();
}
}
const int SceneCLedReserved[]=
{
EndLedSeq
};
const int SceneCLedPattern1[]=
{
(LedPlay+Led1ON+Led2ON+Led3ON),
EndLedSeq
};
const int SceneCLedPattern2[]=
{
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
EndLedSeq
};
const int SceneCLedPattern3[]=
{
(LedPlay+Led1ON+Led2OFF+Led3OFF),
EndLedSeq
};
const int SceneCLedPattern4[]=
{
(LedPlay+Led1OFF+Led2ON+Led3OFF),
EndLedSeq
};
const int SceneCLedPattern5[]=
{
(LedPlay+Led1OFF+Led2OFF+Led3ON),
EndLedSeq
};
const int SceneCLedPattern6[]=
{
(LedPlay+Led1ON+Led2ON+Led3OFF),
EndLedSeq
};
const int SceneCLedPattern7[]=
{
(LedPlay+Led1ON+Led2OFF+Led3ON),
EndLedSeq
};
const int SceneCLedPattern8[]=
{
(LedPlay+Led1OFF+Led2ON+Led3ON),
EndLedSeq
};
const int SceneCLedPattern9[]=
{
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern10[]=
{
(LedPlay+Led1ON+Led2OFF+Led3OFF),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern11[]=
{
(LedPlay+Led1OFF+Led2ON+Led3OFF),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern12[]=
{
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern13[]=
{
(LedPlay+Led1ON+Led2ON+Led3OFF),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern14[]=
{
(LedPlay+Led1ON+Led2OFF+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern15[]=
{
(LedPlay+Led1OFF+Led2ON+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern16[]=
{
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern17[]=
{
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern18[]=
{
(LedPlay+Led1ON+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern19[]=
{
(LedPlay+Led1OFF+Led2ON+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern20[]=
{
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern21[]=
{
(LedPlay+Led1ON+Led2ON+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern22[]=
{
(LedPlay+Led1ON+Led2OFF+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern23[]=
{
(LedPlay+Led1OFF+Led2ON+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
LedLoopMark
};
const int SceneCLedPattern24[]=
{
(LedPlay+Led1ON+Led2OFF+Led3OFF),
(LedDelay + 3),
(LedPlay+Led1OFF+Led2ON+Led3OFF),
(LedDelay + 3),
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 3),
LedLoopMark
};
const int SceneCLedPattern25[]=
{
(LedPlay+Led1ON+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1ON+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1ON+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
EndLedSeq
};
const int SceneCLedPattern26[]=
{
(LedPlay+Led1OFF+Led2ON+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2ON+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2ON+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
EndLedSeq
};
const int SceneCLedPattern27[]=
{
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3OFF),
(LedDelay + 2),
EndLedSeq
};
const int SceneCLedPattern28[]=
{
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 4),
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 4),
EndLedSeq
};
const int SceneCLedPattern29[]=
{
(LedPlay+Led1ON+Led2ON+Led3ON),
(LedDelay + 2),
(LedPlay+Led1OFF+Led2OFF+Led3ON),
(LedDelay + 2),
LedLoopMark
};
const int* const LedActionTableAddr[]=
{
SceneCLedReserved,
SceneCLedPattern1, // Turn on Led#1, Led#2, Led#3
SceneCLedPattern2, // Turn Off Led#1, Led#2, Led#3
SceneCLedPattern3, // Turn on Led#1
SceneCLedPattern4, // Turn on Led#2
SceneCLedPattern5, // Turn on Led#3
SceneCLedPattern6, // Turn on Led#1, Led#2
SceneCLedPattern7, // Turn on Led#1, Led#3
SceneCLedPattern8, // Turn on Led#2, Led#3
SceneCLedPattern9, // Blink Led#1, Led#2, Led#3
SceneCLedPattern10, // Blink Led#1
SceneCLedPattern11, // Blink Led#2
SceneCLedPattern12, // Blink Led#3
SceneCLedPattern13, // Blink Led#1, Led#2
SceneCLedPattern14, // Blink Led#1, Led#3
SceneCLedPattern15, // Blink Led#2, Led#3
SceneCLedPattern16, // Blink All 3 Times
SceneCLedPattern17, // Blink All Loop
SceneCLedPattern18, // Blink Led#1 Loop
SceneCLedPattern19, // Blink Led#2 Loop
SceneCLedPattern20, // Blink Led#3 Loop
SceneCLedPattern21, // Blink Led#1, Led#2 Loop
SceneCLedPattern22, // Blink Led#1, Led#3 Loop
SceneCLedPattern23, // Blink Led#2, Led#3 Loop
SceneCLedPattern24, // Blink One Led Loop
SceneCLedPattern25, // Blink Led#1 3 Times
SceneCLedPattern26, // Blink Led#2 3 Times
SceneCLedPattern27, // Blink Led#3 3 Times
SceneCLedPattern28,
SceneCLedPattern29
};
void ForceStopLedAction()
{
//P_IOB_Buffer->W = 0x0000;
LedActionNo = 0xffff;
LedActionOffset = 0x0000;
LedActionStatus = 0x0000;
}
void GetLedAction()
{
int i;
i = LedActionTableAddr[LedActionNo][LedActionOffset];
i &= 0xff00;
switch (i)
{
case 0x0000:
i = LedActionTableAddr[LedActionNo][LedActionOffset];
i &= IOPORT_LED1+IOPORT_LED2+IOPORT_LED3;
P_IOB_Data->W = i+ (P_IOB_Buffer->W&(~(IOPORT_LED1+IOPORT_LED2+IOPORT_LED3)));
LedActionOffset ++;
GetLedAction();
break;
case 0x0100:
//delay
LedActionStatus &= 0x0000;
LedActionStatus |= 0x0002;
i = 2*LedActionTableAddr[LedActionNo][LedActionOffset];
i &= 0x00ff;
LedActionDelay = i;
break;
case 0x0200:
LedActionOffset=0;
GetLedAction();
break;
case 0xff00:
//end of sound sequence
//P_IOB_Buffer->W = 0x0000;
LedActionNo = 0xffff;
LedActionOffset = 0x0000;
LedActionStatus = 0x8000;
break;
default:
break;
}
}
void CheckLedAction()
{
if (LedActionNo != 0xffff)
{
if ((LedActionStatus & 0x0002) == 0x0002)
{
CheckLedDelayEnd();
return;
}
GetLedAction();
}
}
void PlayLedNo(int TempLedNo)
{
ForceStopLedAction();
LedActionNo=TempLedNo;
LedActionOffset=0x0000;
}
int CheckPlayLedSeqEnd()
{
if ((LedActionStatus&0x8000)==0x8000)
return 1;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -