NXP MCU 技术论坛
直播中

李亮

9年用户 168经验值
擅长:可编程逻辑 电源/新能源
私信 关注
[经验]

【NXP LPC54110试用体验】4.KEY控制LED

上周分享了LED的代码,这周继续学习了一些,分享给大家。
两个外设:KEY+LED
201_meitu_2.jpg
202_meitu_1.jpg
  1. /**
  2. * This is template for main module created by MCUXpresso Project Generator. Enjoy!
  3. **/

  4. #include "board.h"
  5. #include "pin_mux.h"
  6. #include "clock_config.h"

  7. #include "fsl_gpio.h"

  8. /*!
  9. * [url=home.php?mod=space&uid=2666770]@Brief[/url] Application entry point.
  10. */
  11. int main(void) {
  12.   /* Init board hardware. */
  13.   BOARD_InitBootPins();
  14.   BOARD_InitBootClocks();
  15.   BOARD_InitDebugConsole();
  16. #ifdef SDK_PRIMARY_CORE
  17.   BOARD_StartSecondaryCore();
  18. #endif

  19.   /* Add your code here */
  20.   gpio_pin_config_t led0Config = {
  21.     kGPIO_DigitalOutput,
  22.     0,
  23.   };
  24.   
  25.   gpio_pin_config_t key0Config = {
  26.     kGPIO_DigitalInput,
  27.     0,
  28.   };
  29.   
  30.   CLOCK_EnableClock(kCLOCK_Gpio0);
  31.   CLOCK_EnableClock(kCLOCK_Gpio1);
  32.   
  33.   GPIO_PinInit(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, BOARD_INITPINS_LED0_GPIO_PIN, &led0Config);
  34.   GPIO_PinInit(BOARD_INITPINS_KEY0_GPIO, BOARD_INITPINS_KEY0_PORT, BOARD_INITPINS_KEY0_GPIO_PIN, &key0Config);

  35.   for(;;) { /* Infinite loop to avoid leaving the main function */
  36. //    __asm("NOP"); /* something to use as a breakpoint stop while looping */
  37.     if ((GPIO_ReadPinsInput(BOARD_INITPINS_KEY0_GPIO, BOARD_INITPINS_KEY0_PORT) & (1U << BOARD_INITPINS_KEY0_GPIO_PIN)) != (1U << BOARD_INITPINS_KEY0_GPIO_PIN))
  38.     {
  39.       GPIO_TogglePinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
  40.       do
  41.       {
  42.         ;
  43.       } while ((GPIO_ReadPinsInput(BOARD_INITPINS_KEY0_GPIO, BOARD_INITPINS_KEY0_PORT) & (1U << BOARD_INITPINS_KEY0_GPIO_PIN)) != (1U << BOARD_INITPINS_KEY0_GPIO_PIN));
  44.     }
  45.   }
  46. }
最近实在忙于工作,疏于学习了。

更多回帖

发帖
×
20
完善资料,
赚取积分