在线时间954 小时
UID336767
注册时间2011-12-29
NXP金币891
TA的每日心情 | 开心 2018-7-23 21:04 |
---|
签到天数: 103 天 连续签到: 1 天 [LV.6]常住居民II
金牌会员
 
- 积分
- 16872
- 最后登录
- 1970-1-1
|
这次来试一下LPC54114的外部中断功能。实现一个按键中断控制灯。
按下KEY0,LED0状态取反一次。
按键控制灯,非中断例子可见:LPC54110学习+按键控制灯
电路原理图如前所述,非常清楚了。
新建配置工程。
在引脚配置时,PIO1_8的按键引脚应该选择中断外设功能。
配置如下。时钟配置和之前的一样,就不多说了。
可以看到pin_mux中对中断的初始化选择。
在具体使用中断时,引脚是不用具体配置GPIO功能的,只需要初始化pint外设。
配置中断相关参数和中断回调函数。
具体程序中的中断初始化。
中断回调函数。
完整代码:
- /**
- * 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"
- #include "fsl_pint.h"
- #include "fsl_inputmux.h"
- void pint_interrupt_callback(pint_pin_int_t pintr, uint32_t pmatch_status)
- {
- GPIO_TogglePinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
- }
- /*!
- * @brief 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,
- };
-
- CLOCK_EnableClock(kCLOCK_Gpio0);
-
- GPIO_PinInit(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, BOARD_INITPINS_LED0_GPIO_PIN, &led0Config);
-
- PINT_Init(PINT);
- PINT_PinInterruptConfig(PINT, kPINT_PinInt0, kPINT_PinIntEnableFallEdge, pint_interrupt_callback);
- PINT_EnableCallback(PINT);
- for(;;) { /* Infinite loop to avoid leaving the main function */
- __asm("NOP"); /* something to use as a breakpoint stop while looping */
- }
- }
复制代码
下载到开发板,发现功能可以实现。
完整工程文件:
KEY0_Interrupt_MCUXpressoIDE_Project_cm4.rar
(4.73 MB, 下载次数: 78)
|
|