上周分享了LED的代码,这周继续学习了一些,分享给大家。
两个外设:KEY+LED
- /**
- * 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"
- /*!
- * [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 led0Config = {
- kGPIO_DigitalOutput,
- 0,
- };
-
- gpio_pin_config_t key0Config = {
- kGPIO_DigitalInput,
- 0,
- };
-
- CLOCK_EnableClock(kCLOCK_Gpio0);
- CLOCK_EnableClock(kCLOCK_Gpio1);
-
- GPIO_PinInit(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, BOARD_INITPINS_LED0_GPIO_PIN, &led0Config);
- GPIO_PinInit(BOARD_INITPINS_KEY0_GPIO, BOARD_INITPINS_KEY0_PORT, BOARD_INITPINS_KEY0_GPIO_PIN, &key0Config);
- for(;;) { /* Infinite loop to avoid leaving the main function */
- // __asm("NOP"); /* something to use as a breakpoint stop while looping */
- if ((GPIO_ReadPinsInput(BOARD_INITPINS_KEY0_GPIO, BOARD_INITPINS_KEY0_PORT) & (1U << BOARD_INITPINS_KEY0_GPIO_PIN)) != (1U << BOARD_INITPINS_KEY0_GPIO_PIN))
- {
- GPIO_TogglePinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
- do
- {
- ;
- } while ((GPIO_ReadPinsInput(BOARD_INITPINS_KEY0_GPIO, BOARD_INITPINS_KEY0_PORT) & (1U << BOARD_INITPINS_KEY0_GPIO_PIN)) != (1U << BOARD_INITPINS_KEY0_GPIO_PIN));
- }
- }
- }
最近实在忙于工作,疏于学习了。