查看: 1041|回复: 0

[原创] LPC55S16板子 -- 外部中断

[复制链接]
  • TA的每日心情
    开心
    2024-4-10 10:22
  • 签到天数: 1317 天

    [LV.10]以坛为家III

    124

    主题

    2831

    帖子

    31

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    7570
    最后登录
    2024-4-10
    发表于 2020-11-18 17:17:13 | 显示全部楼层 |阅读模式
            这节学习下LPC55S16芯片的外部中断,使用板子上面的开关做测试。


        一、硬件电路


        板子上开关使用到单片机引脚PIO0_15, PIO0_16, PIO0_17。
        001.png
        002.png


        二、程序部分

        INT0 -- 上升沿中断
        INT1 -- 下降沿中断
        INT2 --  下降沿中断
       
        2.1、pint.c
    1. <font size="3">#include "fsl_pint.h"
    2. #include "fsl_inputmux.h"
    3. #include "fsl_debug_console.h"


    4. /*******************************************************************************
    5. * Definitions
    6. ******************************************************************************/
    7. #define KEY0_PIN_INT0_SRC                     kINPUTMUX_GpioPort0Pin15ToPintsel
    8. #define KEY1_PIN_INT1_SRC                     kINPUTMUX_GpioPort0Pin16ToPintsel
    9. #define KEY2_PIN_INT2_SRC                     kINPUTMUX_GpioPort0Pin17ToPintsel
    10. //#define KEY0_PINT_PIN_INT0_SRC                 kINPUTMUX_GpioPort0Pin15ToPintSecsel


    11. void pint_intr_callback(pint_pin_int_t pintr, uint32_t pmatch_status)
    12. {
    13.         if(pintr==kPINT_PinInt0)
    14.         {
    15.                 PRINTF("\r\nPINT Pin key0 Interrupt %d event detected.", pintr);
    16.         }
    17.         if(pintr==kPINT_PinInt1)
    18.         {
    19.                 PRINTF("\r\nPINT Pin key1 Interrupt %d event detected.", pintr);
    20.         }
    21.         if(pintr==kPINT_PinInt2)
    22.         {
    23.                 PRINTF("\r\nPINT Pin key2 Interrupt %d event detected.", pintr);
    24.         }
    25. }


    26. void InitPint(void)
    27. {
    28.         /* Connect trigger sources to PINT */
    29.         INPUTMUX_Init(INPUTMUX);
    30.         INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt0, KEY0_PIN_INT0_SRC);
    31.         INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt1, KEY1_PIN_INT1_SRC);
    32.         INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt2, KEY2_PIN_INT2_SRC);
    33.         //INPUTMUX_AttachSignal(INPUTMUX, kPINT_PinInt0, KEY0_PINT_PIN_INT0_SRC);
    34.         /* Turnoff clock to inputmux to save power. Clock is only needed to make changes */
    35.         INPUTMUX_Deinit(INPUTMUX);

    36.         /* Initialize PINT */
    37.         PINT_Init(PINT);

    38.         //INT0
    39.         /* Setup Pin Interrupt 0 for rising edge */
    40.         PINT_PinInterruptConfig(PINT, kPINT_PinInt0, kPINT_PinIntEnableRiseEdge, pint_intr_callback);
    41.         /* Enable callbacks for PINT0 by Index */
    42.         PINT_EnableCallbackByIndex(PINT, kPINT_PinInt0);
    43.         //INT1
    44.         PINT_PinInterruptConfig(PINT, kPINT_PinInt1, kPINT_PinIntEnableFallEdge, pint_intr_callback);
    45.         PINT_EnableCallbackByIndex(PINT, kPINT_PinInt1);
    46.         //INT2
    47.         PINT_PinInterruptConfig(PINT, kPINT_PinInt2, kPINT_PinIntEnableFallEdge, pint_intr_callback);
    48.         PINT_EnableCallbackByIndex(PINT, kPINT_PinInt2);
    49. }</font>
    复制代码


        2.2、pint.h
       
    1. <font size="3">#ifndef __PINT_H_
    2. #define __PINT_H_


    3. void InitPint(void);


    4. #endif</font>
    复制代码

        2.3、main.c
       
    1. <font size="3">//main
    2. int main(void)
    3. {
    4.         uint8_t x=0;
    5.         uint32_t port_state = 0;
    6.         POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);  /* set BOD VBAT level to 1.65V */
    7.         BOARD_BootClockPLL150M();
    8.         
    9.         InitSystick();
    10.         InitUart();
    11.         InitKey();
    12.         InitLed();
    13.         InitLcd();
    14.         InitSpi();
    15.         Init_mcp2515();
    16.         InitPint();
    17.         
    18.         LED0_OFF();
    19.         LED1_ON();
    20.         
    21.         while (1)
    22.         {
    23.                 LED0_TOG();
    24.                 LED1_TOG();
    25.                 SysTick_DelayTicks(100U);
    26.         }
    27. }</font>
    复制代码


        三、执行结果


        004.png
       


    哎...今天够累的,签到来了~
    回复

    使用道具 举报

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

    本版积分规则

    关闭

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

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

    GMT+8, 2024-4-26 15:31 , Processed in 0.111737 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

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