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();
    }
}

 

posted @ 2013-03-28 22:31  zpehome  阅读(2196)  评论(0编辑  收藏  举报