【EFM32开发笔记】GPIOE外部中断使用

 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的亮灭交替。

 

转载于:https://www.cnblogs.com/xiaofeng6636/p/4493229.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值