gpio.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "gpio.h"
  2. void beep_init(void)
  3. {
  4. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  5. GPIO_InitTypeDef GPIO_StructInit;
  6. GPIO_StructInit.GPIO_Mode = GPIO_Mode_OUT;
  7. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  8. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  9. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  10. GPIO_StructInit.GPIO_Pin = GPIO_BEEP_PIN;
  11. GPIO_Init(GPIO_BEEP_PORT, &GPIO_StructInit);
  12. }
  13. void led_init(void)
  14. {
  15. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
  16. GPIO_InitTypeDef GPIO_StructInit;
  17. GPIO_StructInit.GPIO_Mode = GPIO_Mode_OUT;
  18. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  19. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  20. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  21. GPIO_StructInit.GPIO_Pin = GPIO_LED1_PIN;
  22. GPIO_Init(GPIO_LED1_PORT, &GPIO_StructInit);
  23. }
  24. void key_init(void)
  25. {
  26. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  27. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
  28. GPIO_InitTypeDef GPIO_StructInit;
  29. GPIO_StructInit.GPIO_Mode = GPIO_Mode_IN;
  30. GPIO_StructInit.GPIO_OType = GPIO_OType_PP;
  31. GPIO_StructInit.GPIO_Speed = GPIO_Speed_100MHz;
  32. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_UP;
  33. GPIO_StructInit.GPIO_Pin = GPIO_KEY0_PIN | GPIO_KEY1_PIN | GPIO_KEY2_PIN;
  34. GPIO_Init(GPIO_KEY0_PORT, &GPIO_StructInit);
  35. GPIO_StructInit.GPIO_PuPd = GPIO_PuPd_DOWN;
  36. GPIO_StructInit.GPIO_Pin = GPIO_KEY_UP_PIN;
  37. GPIO_Init(GPIO_KEY_UP_PORT, &GPIO_StructInit);
  38. }
  39. void gpio_init(void)
  40. {
  41. led_init();
  42. key_init();
  43. beep_init();
  44. }