zoukankan      html  css  js  c++  java
  • EFM32之外部中断

    设置时钟:

    CMU_ClockSelectSet(cmuClock_HF,cmuSelect_HFXO);//32MHz


    配置NVIC:

    void NVIC_Config(void)
    {
        NVIC_InitTypeDef NVIC_InitStructure;
    #ifdef VECT_TAB_RAM
        NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
    #else
        NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
    #endif
        NVIC_PriorityGropConfig(NVIC_PriorityGrop_1);//先占优先级1位,从优先级3位
        NVIC_InitStructure.NVIC_IRQChannel = TIMER0_IRQn;//定时器0中断
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//先占优先级
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;//从优先级
        NVIC_InitStructure.NVIC_IRQChannelCmd = true;
        NVIC_Init(&NVIC_InitStructure);
    
        NVIC_InitStructure.NVIC_IRQChannel = GPIO_ODD_IRQn;//配置奇数中断,这里要注意,EFM32的外部中断只有奇、偶两种处理函数
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//先占优先级
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//从优先级
        NVIC_InitStructure.NVIC_IRQChannelCmd = true;
        NVIC_Init(&NVIC_InitStructure);
    
        NVIC_InitStructure.NVIC_IRQChannel = GPIO_EVEN_IRQn;//配置偶数中断
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//先占优先级
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//从优先级
        NVIC_InitStructure.NVIC_IRQChannelCmd = true;
        NVIC_Init(&NVIC_InitStructure);
    }

    外部中断管脚配置:

    void EXTI_Config(void)
    {
        CMU_HFPRECLKEN0 |= (1<<6);//使能GPIO时钟
        GPIO->P[3].MODEH |= (3<<0);//PD8设置成输入带过滤器
        GPIO->P[3].DOUT |= (1<<8);//上拉
    
        GPIO->EXTIPSELH |= (3<<0);//选择PD8
        GPIO->EXTIRISE |= (1<<8);//PD8上升沿有效
        GPIO->IEN |= (1<<8);//外部中断8使能
    
        GPIO->P[3].MODEH |= (3<<12);//PB11设置成输入带过滤器
        GPIO->P[3].DOUT |= (1<<11);//上拉
    
        GPIO->EXTIPSELH |= (1<<12);//选择PB11
        GPIO->EXTIRISE |= (1<<11);//PB11上升沿有效
        GPIO->IEN |= (1<<11);//外部中断11使能
    }

    中断服务程序:

    当按下按键后LED灯的状态改变

    void GPIO_ODD_IRQHandler(void)
    {
        if(GPIO->IF & 0x800)
        {
            GPIO->IFC |= (1<<11);
            LED_Toggle();
        }
    }
    
    void GPIO_EVEN_IRQHandler(void)
    {
        if(GPIO->IF & 0x100)
        {
            GPIO->IFC |= (1<<8);
            LED_Toggle();
        }
    }
  • 相关阅读:
    java 面向对象(十八):包装类的使用
    java 面向对象(十七):单元测试方法
    rxjava2学习
    多线程-wait(),notify(),notifyAll()
    多线程-Thread.join()的运用
    66. Plus One
    理解Android View的事件传递机制
    78. Subsets
    程序员学习与成长的方法(转发)
    android查询天气demo,基于mvp+kotlin+rxjava2+retrofit2
  • 原文地址:https://www.cnblogs.com/zpehome/p/2986427.html
Copyright © 2011-2022 走看看