GPIO口中断例程_MK20DX128VLH5_K20系列
/* cpu:MK20DX128VLH5  */

#include "MK20D5.h"
#include "system_MK20D5.h"

void LEDConfig(void);
void GPIOConfig(void);
void Delay_ms(unsigned int ms);
void InterruptGpioConfig(void);

int main(void)
{   
    LEDConfig();
    InterruptGpioConfig();  
    PTA->PSOR |= (1<<2);
    while(1)
    {
        Delay_ms(10);
        PTA->PTOR |= (1<<13);   //翻转PA13    
    }
}

void LEDConfig(void)    //PA2配置为输出,在中断例程中翻转
{
    SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
    PORTA->PCR[2] &= ~PORT_PCR_MUX_MASK;
    PORTA->PCR[2] |= PORT_PCR_MUX(1);
    PTA->PDDR |= (1<<2);
    PTA->PCOR |= (1<<2);
}

//================================================
//  J2_1#: PA13, 主循环中输出周期波形
//================================================
void GPIOConfig(void)
{
    SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
    PORTA->PCR[13] &= ~PORT_PCR_MUX_MASK;
    PORTA->PCR[13] |= PORT_PCR_MUX(1);
    PTA->PDDR |= (1<<13);
}

//================================================
//  J2_2#: PA12,配置为下降沿中断
//================================================
void InterruptGpioConfig(void)
{
    SIM->SCGC5 |= SIM_SCGC5_PORTA_MASK;
    PORTA->PCR[12] &= ~PORT_PCR_MUX_MASK;
    PORTA->PCR[12] |= PORT_PCR_MUX(1);
    PORTA->PCR[12] &= ~PORT_PCR_IRQC_MASK;
    PORTA->PCR[12] |= PORT_PCR_IRQC(0x0A); //配置为下降沿中断
    PTA->PDDR &= ~(1<<12); 
    NVIC_EnableIRQ(PORTA_IRQn);
}

void Delay_ms(unsigned int ms)
{
    unsigned int Val;
    Val = SystemCoreClock/1000/4*ms;
    while(--Val != 0);      
}    

void PORTA_IRQHandler(void)
{
    /*进中断后先清楚中断标志位,不然,可能会出问题 */
    PORTA->ISFR |= (1<<12);
    //  PORTA->PCR[12] |= PORT_PCR_ISF_MASK;  //仿真调试显示这一句和上面一句效果一样
    PTA->PTOR |= (1<<2); //翻转PA2 
}
阅读更多
文章标签: interrupt
个人分类: 飞思卡尔M4
想对作者说点什么? 我来说一句

STM32F407 IO口中断

外部中断

mlpxnn mlpxnn

2015-08-12 15:07:32

阅读数:1680

没有更多推荐了,返回首页

不良信息举报

GPIO口中断例程_MK20DX128VLH5_K20系列

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭