利用中断控制-按键-led亮灭
按照普中给的教程可以完成key1,key4,控制led1和led2的亮灭,即利用中断XINT1和XINT2。
依据上述程序想实现key7控制led3的亮灭实现不了。
百度许多资料,都没能解决。
现在有个疑惑就是,key1和key4输入位是gpio12和gpio13,能够配置外部中断INT1和XINT2。
key7是gpio14没有外部中断可用,而外部中断3——XINT3需要的GPIO是32-63.
这种情况怎么解决?
下面是程序
#include "ex
ti.h"
#include "leds.h"
#include "key.h"
//
//
void EXTI1_Init(void)
{
EALLOW;
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clock 使能IO口时钟,SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK=1
EDIS;
EALLOW;
//KEY端口配置
GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;
GpioCtrlRegs.GPADIR.bit.GPIO12=0; //配置IO口为输入
GpioCtrlRegs.GPAPUD.bit.GPIO12=0;
GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 0; // 外部中断1(XINT1)与系统时钟SYSCLKOUT同步
GpioCtrlRegs.GPBMUX2.bit.GPIO48=0;
GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
GpioCtrlRegs.GPBPUD.bit.GPIO48=0;
GpioDataRegs.GPBCLEAR.bit.GPIO48=1;
EDIS;
EALLOW;
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 12; // XINT1是GPIO12,设置IO口与中断线映射关系
EDIS;
EALLOW; // 修改被保护的寄存器,修改前应添加EALLOW语句
PieVectTable.XINT1 = &EXTI1_IRQn; //指定中断向量表中断服务函数地址
EDIS; // EDIS的意思是不允许修改被保护的寄存器
PieCtrlRegs.PIEIER1.bit.INTx4 = 1; // 使能PIE组1的INT4
XIntruptRegs.XINT1CR.bit.POLARITY = 0; // 下降沿触发中断
XIntruptRegs.XINT1CR.bit.ENABLE= 1; // 使能XINT1
IER |= M_INT1; // 使能CPU中断1(INT1)
EINT; // 开全局中断
ERTM;
}
interrupt void EXTI1_IRQn(void)
{
Uint32 i;
for(i=0;i<10000;i++); //键盘消抖动
while(!KEY_H1);
LED1_TOGGLE;
PieCtrlRegs.PIEACK.bit.ACK1=1;
}
//
//
void EXTI2_Init(void)
{
EALLOW;
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clock
EDIS;
EALLOW;
//KEY端口配置
GpioCtrlRegs.GPAMUX1.bit.GPIO13=0;
GpioCtrlRegs.GPADIR.bit.GPIO13=0;
GpioCtrlRegs.GPAPUD.bit.GPIO13=0;
GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 2; // 外部中断2(XINT2)输入限定6个采样窗口
GpioCtrlRegs.GPACTRL.bit.QUALPRD1 = 0xFF; // 每个采样窗口的周期为510*SYSCLKOUT
GpioCtrlRegs.GPBMUX2.bit.GPIO48=0;
GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
GpioCtrlRegs.GPBPUD.bit.GPIO48=0;
GpioDataRegs.GPBCLEAR.bit.GPIO48=1;
EDIS;
EALLOW;
GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = 13; // XINT2是GPIO13
EDIS;
EALLOW; // 修改被保护的寄存器,修改前应添加EALLOW语句
PieVectTable.XINT2 = &EXTI2_IRQn;
EDIS; // EDIS的意思是不允许修改被保护的寄存器
PieCtrlRegs.PIEIER1.bit.INTx5 = 1; // 使能PIE组1的INT5
XIntruptRegs.XINT2CR.bit.POLARITY = 0; // 下降沿触发中断
XIntruptRegs.XINT2CR.bit.ENABLE = 1; // 使能XINT2
IER |= M_INT1; // 使能CPU中断1(INT1)
EINT; // 开全局中断
ERTM;
}
interrupt void EXTI2_IRQn(void)
{
Uint32 i;
for(i=0;i<10000;i++); //键盘消抖动
while(!KEY_H2);
LED2_TOGGLE;
PieCtrlRegs.PIEACK.bit.ACK1=1;
}
//
////
////
void EXTI3_Init(void)
{
EALLOW;
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clock
EDIS;
EALLOW;
//KEY端口配置
GpioCtrlRegs.GPAMUX1.bit.GPIO14=0;
GpioCtrlRegs.GPADIR.bit.GPIO14=0;
GpioCtrlRegs.GPAPUD.bit.GPIO14=0;
GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 0;
GpioCtrlRegs.GPBMUX2.bit.GPIO48=0;
GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
GpioCtrlRegs.GPBPUD.bit.GPIO48=0;
GpioDataRegs.GPBCLEAR.bit.GPIO48=1;
EDIS;
EALLOW;
GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL =14; // XINT3是GPIO14
EDIS;
EALLOW; // 修改被保护的寄存器,修改前应添加EALLOW语句
PieVectTable.XINT3= &EXTI3_IRQn;
EDIS; // EDIS的意思是不允许修改被保护的寄存器
PieCtrlRegs.PIEIER12.bit.INTx1 = 1; // 使能PIE组12的INTx1
XIntruptRegs.XINT3CR.bit.POLARITY = 0; // 下降沿触发中断
XIntruptRegs.XINT3CR.bit.ENABLE = 1; // 使能XINT3
IER |= M_INT12; // 使能CPU中断12(INT12)
EINT; // 开全局中断
ERTM;
}
interrupt void EXTI3_IRQn(void)
{
Uint32 i;
for(i=0;i<10000;i++); //键盘消抖动
while(!KEY_H3);
LED3_TOGGLE;
PieCtrlRegs.PIEACK.bit.ACK1=1;
}