码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-10 23:55:23      阅读:709      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/xiaofeng6636/p/4493229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!