微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > 3.流水灯

3.流水灯

时间:10-02 整理:3721RD 点击:
今天,主要给大家分享是是一个流水灯的历程。


上图是LED分别对应的IO口位置,下面是对应的代码:

  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. void delay(void)
  9. {
  10.     volatile uint32_t i = 0;
  11.     for (i = 0; i < 1000000; ++i)
  12.     {
  13.         __asm("NOP"); /* delay */
  14.     }
  15. }

  16. /*!
  17. * [url=home.php?mod=space&uid=2666770]@Brief[/url] Application entry point.
  18. */
  19. int main(void) {
  20.   /* Init board hardware. */
  21.   BOARD_InitBootPins();
  22.   BOARD_InitBootClocks();
  23.   BOARD_InitDebugConsole();
  24. #ifdef SDK_PRIMARY_CORE
  25.   BOARD_StartSecondaryCore();
  26. #endif

  27.   /* Add your code here */
  28.   gpio_pin_config_t config_low = {
  29.     kGPIO_DigitalOutput,
  30.     0,
  31.   };
  32.   gpio_pin_config_t config_high = {
  33.     kGPIO_DigitalOutput,
  34.     1,
  35.   };
  36.   
  37.   CLOCK_EnableClock(kCLOCK_Gpio0);
  38.   GPIO_PinInit(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, BOARD_INITPINS_LED0_GPIO_PIN, &config_low);
  39.   GPIO_PinInit(BOARD_INITPINS_LED1_GPIO, BOARD_INITPINS_LED1_PORT, BOARD_INITPINS_LED1_GPIO_PIN, &config_low);
  40.   GPIO_PinInit(BOARD_INITPINS_LED2_GPIO, BOARD_INITPINS_LED2_PORT, BOARD_INITPINS_LED2_GPIO_PIN, &config_low);
  41.   GPIO_PinInit(BOARD_INITPINS_LED3_GPIO, BOARD_INITPINS_LED3_PORT, BOARD_INITPINS_LED3_GPIO_PIN, &config_low);
  42.   GPIO_PinInit(BOARD_INITPINS_LED4_GPIO, BOARD_INITPINS_LED4_PORT, BOARD_INITPINS_LED4_GPIO_PIN, &config_high);
  43.   GPIO_PinInit(BOARD_INITPINS_LED5_GPIO, BOARD_INITPINS_LED5_PORT, BOARD_INITPINS_LED5_GPIO_PIN, &config_high);
  44.   GPIO_PinInit(BOARD_INITPINS_LED6_GPIO, BOARD_INITPINS_LED6_PORT, BOARD_INITPINS_LED6_GPIO_PIN, &config_high);
  45.   GPIO_PinInit(BOARD_INITPINS_LED7_GPIO, BOARD_INITPINS_LED7_PORT, BOARD_INITPINS_LED7_GPIO_PIN, &config_high);

  46.   for(;;) { /* Infinite loop to avoid leaving the main function */
  47.     __asm("NOP"); /* something to use as a breakpoint stop while looping */
  48.     GPIO_SetPinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
  49.     delay();
  50.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);

  51.     GPIO_SetPinsOutput(BOARD_INITPINS_LED1_GPIO, BOARD_INITPINS_LED1_PORT, 1U << BOARD_INITPINS_LED1_GPIO_PIN);
  52.     delay();
  53.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED1_GPIO, BOARD_INITPINS_LED1_PORT, 1U << BOARD_INITPINS_LED1_GPIO_PIN);

  54.     GPIO_SetPinsOutput(BOARD_INITPINS_LED2_GPIO, BOARD_INITPINS_LED2_PORT, 1U << BOARD_INITPINS_LED2_GPIO_PIN);
  55.     delay();
  56.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED2_GPIO, BOARD_INITPINS_LED2_PORT, 1U << BOARD_INITPINS_LED2_GPIO_PIN);

  57.     GPIO_SetPinsOutput(BOARD_INITPINS_LED3_GPIO, BOARD_INITPINS_LED3_PORT, 1U << BOARD_INITPINS_LED3_GPIO_PIN);
  58.     delay();
  59.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED3_GPIO, BOARD_INITPINS_LED3_PORT, 1U << BOARD_INITPINS_LED3_GPIO_PIN);

  60.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED4_GPIO, BOARD_INITPINS_LED4_PORT, 1U << BOARD_INITPINS_LED4_GPIO_PIN);
  61.     delay();
  62.     GPIO_SetPinsOutput(BOARD_INITPINS_LED4_GPIO, BOARD_INITPINS_LED4_PORT, 1U << BOARD_INITPINS_LED4_GPIO_PIN);

  63.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED5_GPIO, BOARD_INITPINS_LED5_PORT, 1U << BOARD_INITPINS_LED5_GPIO_PIN);
  64.     delay();
  65.     GPIO_SetPinsOutput(BOARD_INITPINS_LED5_GPIO, BOARD_INITPINS_LED5_PORT, 1U << BOARD_INITPINS_LED5_GPIO_PIN);

  66.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED6_GPIO, BOARD_INITPINS_LED6_PORT, 1U << BOARD_INITPINS_LED6_GPIO_PIN);
  67.     delay();
  68.     GPIO_SetPinsOutput(BOARD_INITPINS_LED6_GPIO, BOARD_INITPINS_LED6_PORT, 1U << BOARD_INITPINS_LED6_GPIO_PIN);

  69.     GPIO_ClearPinsOutput(BOARD_INITPINS_LED7_GPIO, BOARD_INITPINS_LED7_PORT, 1U << BOARD_INITPINS_LED7_GPIO_PIN);
  70.     delay();
  71.     GPIO_SetPinsOutput(BOARD_INITPINS_LED7_GPIO, BOARD_INITPINS_LED7_PORT, 1U << BOARD_INITPINS_LED7_GPIO_PIN);
  72.   }
  73. }

复制代码

近日奔波于找工作中,如有错误还望指出。

下次进行项目的实现

学习学习

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top