查看: 4467|回复: 1

[分享] LPC54110学习+按键中断控制灯

[复制链接]
  • TA的每日心情
    开心
    2018-7-23 21:04
  • 签到天数: 103 天

    连续签到: 1 天

    [LV.6]常住居民II

    228

    主题

    5379

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    16872
    最后登录
    1970-1-1
    发表于 2017-4-7 20:45:38 | 显示全部楼层 |阅读模式
    这次来试一下LPC54114的外部中断功能。实现一个按键中断控制灯。
    按下KEY0,LED0状态取反一次。
    按键控制灯,非中断例子可见:LPC54110学习+按键控制灯

    电路原理图如前所述,非常清楚了。
    QQ截图20170407112531.png

    QQ截图20170407112554.png
    新建配置工程。
    QQ截图20170407203107.png
    在引脚配置时,PIO1_8的按键引脚应该选择中断外设功能。
    QQ截图20170407203156.png
    配置如下。时钟配置和之前的一样,就不多说了。
    QQ截图20170407203216.png
    可以看到pin_mux中对中断的初始化选择。
    QQ截图20170407203351.png
    在具体使用中断时,引脚是不用具体配置GPIO功能的,只需要初始化pint外设。
    QQ截图20170407203523.png
    配置中断相关参数和中断回调函数。
    QQ截图20170407203548.png
    具体程序中的中断初始化。
    QQ截图20170407203439.png
    中断回调函数。
    QQ截图20170407203450.png
    完整代码:
    1. /**
    2. * This is template for main module created by MCUXpresso Project Generator. Enjoy!
    3. **/

    4. #include "board.h"
    5. #include "pin_mux.h"
    6. #include "clock_config.h"

    7. #include "fsl_gpio.h"
    8. #include "fsl_pint.h"
    9. #include "fsl_inputmux.h"

    10. void pint_interrupt_callback(pint_pin_int_t pintr, uint32_t pmatch_status)
    11. {
    12.   GPIO_TogglePinsOutput(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, 1U << BOARD_INITPINS_LED0_GPIO_PIN);
    13. }

    14. /*!
    15. * @brief Application entry point.
    16. */
    17. int main(void) {
    18.   /* Init board hardware. */
    19.   BOARD_InitBootPins();
    20.   BOARD_InitBootClocks();
    21.   BOARD_InitDebugConsole();
    22. #ifdef SDK_PRIMARY_CORE
    23.   BOARD_StartSecondaryCore();
    24. #endif

    25.   /* Add your code here */
    26.   gpio_pin_config_t led0Config = {
    27.     kGPIO_DigitalOutput,
    28.     0,
    29.   };
    30.   
    31.   CLOCK_EnableClock(kCLOCK_Gpio0);
    32.   
    33.   GPIO_PinInit(BOARD_INITPINS_LED0_GPIO, BOARD_INITPINS_LED0_PORT, BOARD_INITPINS_LED0_GPIO_PIN, &led0Config);
    34.   
    35.   PINT_Init(PINT);
    36.   PINT_PinInterruptConfig(PINT, kPINT_PinInt0, kPINT_PinIntEnableFallEdge, pint_interrupt_callback);

    37.   PINT_EnableCallback(PINT);

    38.   for(;;) { /* Infinite loop to avoid leaving the main function */
    39.     __asm("NOP"); /* something to use as a breakpoint stop while looping */
    40.   }
    41. }
    复制代码

    下载到开发板,发现功能可以实现。
    QQ截图20170407112259.png

    完整工程文件:
    KEY0_Interrupt_MCUXpressoIDE_Project_cm4.rar (4.73 MB, 下载次数: 78)
    回复

    使用道具 举报

    该用户从未签到

    0

    主题

    12

    帖子

    0

    注册会员

    Rank: 2

    积分
    77
    最后登录
    2023-5-18
    发表于 2017-7-6 16:53:00 | 显示全部楼层
    楼主这个配置软件能不能分享下,2564760880@qq.com  谢谢
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-9-12 13:39 , Processed in 0.092886 second(s), 21 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表