main.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <stdarg.h>
  2. #include "yc11xx.h"
  3. #include "ycdef.h"
  4. #include "yc11xx_gpio.h"
  5. #define KEY_ON 0
  6. #define KEY_OFF 1
  7. #define KEY_SCAN_GPIO 23
  8. #define LED_GPIO 28
  9. #define Led_Run(x) GPIO_CONFIG(x) = (GPIO_CONFIG(x)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
  10. /**
  11. *@brief Configure led gpio output.
  12. *@param Gpio: gpio number.
  13. *@param St false low, true high.
  14. *@return None.
  15. */
  16. void Led_Gpio_Config(uint8_t Gpio,bool St)
  17. {
  18. GPIO_SetOutput(Gpio,St);
  19. }
  20. /**
  21. *@brief check key scan gpio status KEY_ON:input low; KEY_OFF: high.
  22. *@param Gpio: gpio number.
  23. *@return KEY_ON
  24. *@return KEY_ OFF
  25. */
  26. uint8_t Key_Scan(uint8_t Gpio)
  27. {
  28. if(GPIO_GetInputStatus(Gpio) == KEY_ON)
  29. {
  30. while(GPIO_GetInputStatus(Gpio) == KEY_ON)
  31. return KEY_ON;
  32. }
  33. else
  34. return KEY_OFF;
  35. }
  36. void delay_ems(uint32_t time)
  37. {
  38. unsigned int cnt,j;
  39. for(cnt=0;cnt<time;cnt++)
  40. {
  41. for(j=0;j<4000;j++);
  42. }
  43. }
  44. void delay_eus(uint32_t time)
  45. {
  46. while(time--)
  47. {
  48. for(int i=0;i<250000;i++);
  49. }
  50. }
  51. /**
  52. *@brief Configure key scan gpio input.
  53. *@param Gpio: gpio number.
  54. *@param St false pullup, true pulldown.
  55. *@return None.
  56. */
  57. void Key_Gpio_Config(uint8_t Gpio,bool St)
  58. {
  59. GPIO_SetInput(Gpio,St);
  60. }
  61. int main(void)
  62. {
  63. Key_Gpio_Config(KEY_SCAN_GPIO,false);
  64. Led_Gpio_Config(LED_GPIO,true);
  65. delay_eus(10000);
  66. Led_Gpio_Config(LED_GPIO,false);
  67. delay_eus(10);
  68. Led_Gpio_Config(LED_GPIO,true);
  69. while(1)
  70. {
  71. if(Key_Scan(KEY_SCAN_GPIO) == KEY_ON)
  72. {
  73. Led_Gpio_Config(LED_GPIO,false);
  74. Led_Gpio_Config(LED_GPIO,true);
  75. }
  76. }
  77. }