GPIO_LED.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include "GPIO_LED.h"
  2. unsigned char LED[2];
  3. extern unsigned int LocalTime;
  4. int GPIO_LED_init(void)
  5. {
  6. GPIO_InitTypeDef GPIO_InitStructure;
  7. //打开相应GPIO口的时钟
  8. LED0_RccOpen();
  9. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  10. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  11. GPIO_InitStructure.GPIO_Pin = LED0_LINE;
  12. GPIO_Init(LED0_Port,&GPIO_InitStructure);
  13. GPIO_ResetBits(LED0_Port,LED0_LINE);
  14. //打开相应GPIO口的时钟
  15. LED1_RccOpen();
  16. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  17. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  18. GPIO_InitStructure.GPIO_Pin = LED1_LINE;
  19. GPIO_Init(LED1_Port,&GPIO_InitStructure);
  20. GPIO_ResetBits(LED1_Port,LED1_LINE);
  21. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  22. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
  23. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  24. GPIO_Init(GPIOB,&GPIO_InitStructure);
  25. LED[0]=0;
  26. LED[1]=0;
  27. return 1;
  28. }
  29. void GPIO_LED_Tick(void)
  30. {
  31. static unsigned int LedTime=0;
  32. static unsigned char LedFlag=0;
  33. //===============================
  34. if(LocalTime>LedTime)
  35. {
  36. LedTime=LocalTime+500;
  37. if(LedFlag==0)
  38. LedFlag=1;
  39. else
  40. LedFlag=0;
  41. }
  42. //===============================
  43. switch(LED[1])
  44. {
  45. case 1:
  46. GPIO_SetBits(LED0_Port,LED0_LINE);
  47. break;
  48. case 0:
  49. GPIO_ResetBits(LED0_Port,LED0_LINE);
  50. break;
  51. case 2:
  52. GPIO_WriteBit(LED0_Port,LED0_LINE,(BitAction)LedFlag);
  53. break;
  54. }
  55. //===============================
  56. switch(LED[0])
  57. {
  58. case 1:
  59. GPIO_SetBits(LED1_Port,LED1_LINE);
  60. break;
  61. case 0:
  62. GPIO_ResetBits(LED1_Port,LED1_LINE);
  63. break;
  64. case 2:
  65. GPIO_WriteBit(LED1_Port,LED1_LINE,(BitAction)LedFlag);
  66. break;
  67. }
  68. //===============================
  69. }