main.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2021, lizhengyang
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-09-02 lizhengyang first version
  9. */
  10. #include "board.h"
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. /* defined the LED1 pin: PE0 */
  14. #define LED1_PIN GET_PIN(E,0)
  15. /* defined the LED2 pin: PE0 */
  16. #define LED2_PIN GET_PIN(E,1)
  17. /* defined the KEY pin: PE13 */
  18. #define KEY_PIN GET_PIN(E,13)
  19. #define DELAY_MS (RT_TICK_PER_SECOND) /* 1s */
  20. void LED2_Toggle(void *args)
  21. {
  22. static uint8_t i;
  23. if (i % 2 == 1)
  24. {
  25. rt_pin_write(LED2_PIN, PIN_HIGH);
  26. }
  27. else
  28. {
  29. rt_pin_write(LED2_PIN, PIN_LOW);
  30. }
  31. i++;
  32. }
  33. int32_t main(void)
  34. {
  35. /* set LED1_PIN output*/
  36. rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
  37. /* set LED2_PIN output*/
  38. rt_pin_mode(LED2_PIN, PIN_MODE_OUTPUT);
  39. /*set KEY_PIN intput pullup*/
  40. rt_pin_mode(KEY_PIN, PIN_MODE_INPUT_PULLUP);
  41. /*attach KEY_PIN irq*/
  42. rt_pin_attach_irq(KEY_PIN, PIN_IRQ_MODE_FALLING, LED2_Toggle, RT_NULL);
  43. /*enable KEY_PIN irq*/
  44. rt_pin_irq_enable(KEY_PIN, PIN_IRQ_ENABLE);
  45. rt_pin_write(LED1_PIN, PIN_HIGH);
  46. while (1)
  47. {
  48. rt_pin_write(LED1_PIN, PIN_HIGH);
  49. rt_thread_delay(DELAY_MS);
  50. rt_pin_write(LED1_PIN, PIN_LOW);
  51. rt_thread_delay(DELAY_MS);
  52. }
  53. }