led.c 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "led.h"
  2. #include "stm32f10x.h"
  3. #include "stdint.h"
  4. void led_init()
  5. {
  6. GPIO_InitTypeDef GPIO_InitStructure;
  7. RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
  8. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
  9. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  10. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  11. GPIO_Init(GPIOB, &GPIO_InitStructure);
  12. GPIO_SetBits(GPIOB, GPIO_Pin_14 | GPIO_Pin_15);
  13. }
  14. void led_flash()
  15. {
  16. static uint8_t flag = 0;
  17. if(flag)
  18. {
  19. flag = 0;
  20. GPIO_SetBits(GPIOB, GPIO_Pin_14);
  21. }else
  22. {
  23. flag = 1;
  24. GPIO_ResetBits(GPIOB, GPIO_Pin_14);
  25. }
  26. }
  27. void led_status()
  28. {
  29. static uint8_t flag = 0;
  30. if(flag)
  31. {
  32. flag = 0;
  33. GPIO_SetBits(GPIOB, GPIO_Pin_15);
  34. }else
  35. {
  36. flag = 1;
  37. GPIO_ResetBits(GPIOB, GPIO_Pin_15);
  38. }
  39. }
  40. void led_clear()
  41. {
  42. GPIO_SetBits(GPIOB, GPIO_Pin_14);
  43. GPIO_SetBits(GPIOB, GPIO_Pin_15);
  44. }