`今天,主要给大家分享是是一个流水灯的历程。
上图是LED分别对应的IO口位置,下面是对应的代码:
- /**
- * This is template for main module created by MCUXpresso Project Generator. Enjoy!
- **/
- #include "board.h"
- #include "pin_mux.h"
- #include "clock_config.h"
- #include "fsl_gpio.h"
- void delay(void)
- {
- volatile uint32_t i = 0;
- for (i = 0; i < 1000000; ++i)
- {
- __asm("NOP"); /* delay */
- }
- }
- /*!
- * [url=home.php?mod=space&uid=2666770]@Brief[/url] Application entry point.
- */
- int main(void) {
- /* Init board hardware. */
- BOARD_InitBootPins();
- BOARD_InitBootClocks();
- BOARD_InitDebugConsole();
- #ifdef SDK_PRIMARY_CORE
- BOARD_StartSecondaryCore();
- #endif
- /* Add your code here */
- gpio_pin_config_t config_low = {
- kGPIO_DigitalOutput,
- 0,
- };
- gpio_pin_config_t config_high = {
- kGPIO_DigitalOutput,
- 1,
- };
-
- CLOCK_EnableClock(kCLOCK_Gpio0);
- GPIO_PinInit(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, BOARD_INITPINS_LED0_GPIO_PIN, &config_low);
- GPIO_PinInit(BOARD_INITPINS_LED1_GPIO, BOARD_INITPINS_LED1_PORT, BOARD_INITPINS_LED1_GPIO_PIN, &config_low);
- GPIO_PinInit(BOARD_INITPINS_LED2_GPIO, BOARD_INITPINS_LED2_PORT, BOARD_INITPINS_LED2_GPIO_PIN, &config_low);
- GPIO_PinInit(BOARD_INITPINS_LED3_GPIO, BOARD_INITPINS_LED3_PORT, BOARD_INITPINS_LED3_GPIO_PIN, &config_low);
- GPIO_PinInit(BOARD_INITPINS_LED4_GPIO, BOARD_INITPINS_LED4_PORT, BOARD_INITPINS_LED4_GPIO_PIN, &config_high);
- GPIO_PinInit(BOARD_INITPINS_LED5_GPIO, BOARD_INITPINS_LED5_PORT, BOARD_INITPINS_LED5_GPIO_PIN, &config_high);
- GPIO_PinInit(BOARD_INITPINS_LED6_GPIO, BOARD_INITPINS_LED6_PORT, BOARD_INITPINS_LED6_GPIO_PIN, &config_high);
- GPIO_PinInit(BOARD_INITPINS_LED7_GPIO, BOARD_INITPINS_LED7_PORT, BOARD_INITPINS_LED7_GPIO_PIN, &config_high);
- for(;;) { /* Infinite loop to avoid leaving the main function */
- __asm("NOP"); /* something to use as a breakpoint stop while looping */
- GPIO_SetPinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
- delay();
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
- GPIO_SetPinsOutput(BOARD_INITPINS_LED1_GPIO, BOARD_INITPINS_LED1_PORT, 1U << BOARD_INITPINS_LED1_GPIO_PIN);
- delay();
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED1_GPIO, BOARD_INITPINS_LED1_PORT, 1U << BOARD_INITPINS_LED1_GPIO_PIN);
- GPIO_SetPinsOutput(BOARD_INITPINS_LED2_GPIO, BOARD_INITPINS_LED2_PORT, 1U << BOARD_INITPINS_LED2_GPIO_PIN);
- delay();
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED2_GPIO, BOARD_INITPINS_LED2_PORT, 1U << BOARD_INITPINS_LED2_GPIO_PIN);
- GPIO_SetPinsOutput(BOARD_INITPINS_LED3_GPIO, BOARD_INITPINS_LED3_PORT, 1U << BOARD_INITPINS_LED3_GPIO_PIN);
- delay();
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED3_GPIO, BOARD_INITPINS_LED3_PORT, 1U << BOARD_INITPINS_LED3_GPIO_PIN);
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED4_GPIO, BOARD_INITPINS_LED4_PORT, 1U << BOARD_INITPINS_LED4_GPIO_PIN);
- delay();
- GPIO_SetPinsOutput(BOARD_INITPINS_LED4_GPIO, BOARD_INITPINS_LED4_PORT, 1U << BOARD_INITPINS_LED4_GPIO_PIN);
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED5_GPIO, BOARD_INITPINS_LED5_PORT, 1U << BOARD_INITPINS_LED5_GPIO_PIN);
- delay();
- GPIO_SetPinsOutput(BOARD_INITPINS_LED5_GPIO, BOARD_INITPINS_LED5_PORT, 1U << BOARD_INITPINS_LED5_GPIO_PIN);
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED6_GPIO, BOARD_INITPINS_LED6_PORT, 1U << BOARD_INITPINS_LED6_GPIO_PIN);
- delay();
- GPIO_SetPinsOutput(BOARD_INITPINS_LED6_GPIO, BOARD_INITPINS_LED6_PORT, 1U << BOARD_INITPINS_LED6_GPIO_PIN);
- GPIO_ClearPinsOutput(BOARD_INITPINS_LED7_GPIO, BOARD_INITPINS_LED7_PORT, 1U << BOARD_INITPINS_LED7_GPIO_PIN);
- delay();
- GPIO_SetPinsOutput(BOARD_INITPINS_LED7_GPIO, BOARD_INITPINS_LED7_PORT, 1U << BOARD_INITPINS_LED7_GPIO_PIN);
- }
- }
复制代码
近日奔波于找工作中,如有错误还望指出。
`
|