Led.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**********************************************************************************
  2. * File Name: LedTask.c
  3. * Function Describe:The task for LED display
  4. * Relate Module:
  5. * Explain: 控制指示灯显示任务。在其他任务中可通过SetLedFlash函数设置显示方式
  6. * Writer: ShiLiangWen
  7. * Date: 2015.2.10
  8. **********************************************************************************/
  9. #include "includes.h"
  10. unsigned char g_ucLedSel;
  11. unsigned char g_ucLedFlash; //LED闪烁次数,每次亮0.5秒灭0.5秒
  12. unsigned char g_ucLedSleepTime; //LED熄灭时间,单位:秒
  13. void LedInit(void)
  14. {
  15. GPIO_InitTypeDef GPIO_InitStructure;
  16. //Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull
  17. //在PowerCtrlInit中已经禁止JTAG-DP功能,这里不需要了。
  18. // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//复用功能IO 时钟使能 这里必须先使能复用IO的时钟,再关闭JTAG功能
  19. // GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); // JTAG-DP Disabled and SW-DP Enabled
  20. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  21. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  22. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  23. GPIO_InitStructure.GPIO_Pin = MODEM_LED1_PIN;
  24. GPIO_Init(MODEM_LED1_PORT, &GPIO_InitStructure);
  25. GPIO_InitStructure.GPIO_Pin = MODEM_LED2_PIN;
  26. GPIO_Init(MODEM_LED2_PORT, &GPIO_InitStructure);
  27. MODEM_LED1_LOW;
  28. MODEM_LED2_LOW;
  29. g_ucLedSel=LED_SEL_BLUE;
  30. g_ucLedFlash=0; //LED闪烁次数,每次亮0.5秒灭0.5秒
  31. g_ucLedSleepTime=0; //LED熄灭时间,单位:秒
  32. }
  33. /*******************************************************************
  34. *LedTask
  35. ********************************************************************/
  36. void LedTickMsg(void)
  37. {
  38. unsigned char ucLedCt=0;
  39. static unsigned char sucLedMaxCt=0;
  40. static unsigned char sucLedFlash2=0;
  41. static unsigned char sucLastLedFlash=0xff;
  42. static unsigned char sucLastLedSleepTime=0xff;
  43. //喂狗
  44. IWDG_ReloadCounter();
  45. if(g_ucLedFlash==0){ //长灭
  46. if(g_ucLedSel){
  47. MODEM_LED1_LOW;
  48. }else{
  49. MODEM_LED2_LOW;
  50. }
  51. return;
  52. }else if(g_ucLedSleepTime==0){//长亮
  53. if(g_ucLedSel){
  54. MODEM_LED1_HIGH;
  55. }else{
  56. MODEM_LED2_HIGH;
  57. }
  58. return;
  59. }
  60. if(sucLastLedFlash!=g_ucLedFlash || sucLastLedSleepTime!=g_ucLedSleepTime){
  61. ucLedCt=0;
  62. sucLastLedFlash=g_ucLedFlash;
  63. sucLastLedSleepTime=g_ucLedSleepTime;
  64. sucLedFlash2=g_ucLedFlash*2;
  65. sucLedMaxCt=sucLedFlash2+g_ucLedSleepTime*2;
  66. }
  67. if(++ucLedCt>sucLedMaxCt){
  68. ucLedCt=0;
  69. }
  70. if(ucLedCt<sucLedFlash2 && (ucLedCt&0x01)==0x01){
  71. if(g_ucLedSel){
  72. MODEM_LED1_HIGH;
  73. }else{
  74. MODEM_LED2_HIGH;
  75. }
  76. }else{
  77. if(g_ucLedSel){
  78. MODEM_LED1_LOW;
  79. }else{
  80. MODEM_LED2_LOW;
  81. }
  82. }
  83. }
  84. void SetLedFlash(unsigned char flash,unsigned char sleep)
  85. {
  86. int t=(flash+sleep)*2;
  87. if(t>255){
  88. return;
  89. }
  90. g_ucLedFlash=flash;
  91. g_ucLedSleepTime=sleep;
  92. }
  93. void LedSlecet(unsigned char sel)
  94. {
  95. g_ucLedSel=sel;
  96. }
  97. /***********************************************************************************/