1 /**************************************************************************//** 2 * @brief Gpio回调函数 3 * @param pin - pin which triggered interrupt 4 *****************************************************************************/ 5 void gpioCallback(uint8_t pin) 6 { 7 if (pin == 9) 8 { 9 BSP_LedToggle(3); //端口翻转,LED亮灭交替 10 } 11 else if (pin == 10) 12 { 13 BSP_LedToggle(0); 14 } 15 } 16 17 /**************************************************************************//** 18 * @brief Gpio setup. Setup button pins to trigger falling edge interrupts. 19 * Register callbacks for that interrupts. 20 *****************************************************************************/ 21 void gpioSetup(void) 22 { 23 /* Enable GPIO in CMU */ 24 CMU_ClockEnable(cmuClock_GPIO, true); 25 26 /* Initialize GPIO interrupt dispatcher */ 27 GPIOINT_Init(); 28 29 /* Configure PB9 and PB10 as input */ 30 GPIO_PinModeSet(gpioPortB, 9, gpioModeInput, 0); 31 GPIO_PinModeSet(gpioPortB, 10, gpioModeInput, 0); 32 33 /* Register callbacks before setting up and enabling pin interrupt. */ 34 GPIOINT_CallbackRegister(9, gpioCallback); 35 GPIOINT_CallbackRegister(10, gpioCallback); 36 37 /* Set falling edge interrupt for both ports */ 38 GPIO_IntConfig(gpioPortB, 9, false, true, true); 39 GPIO_IntConfig(gpioPortB, 10, false, true, true); 40 } 41 42 /**************************************************************************//** 43 * @brief Main function 44 *****************************************************************************/ 45 int main(void) 46 { 47 /* Chip errata */ 48 CHIP_Init(); 49 50 /* If first word of user data page is non-zero, enable eA Profiler trace */ 51 BSP_TraceProfilerSetup(); 52 53 /* Initialize gpio */ 54 gpioSetup(); 55 56 /* Initialize LED driver */ 57 BSP_LedsInit(); 58 59 /* Infinite loop */ 60 while (1); 61 }
按下板上的按键(PB0、PB1)将会实现LED的亮灭交替。
时间: 2024-10-04 18:15:46