外部中断实验
#include "exti.h"
#include "leds.h"
#include "key.h"void EXTI1_Init(void)
{EALLOW;SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clockEDIS;EALLOW;//KEY端口配置GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;GpioCtrlRegs.GPADIR.bit.GPIO12=0;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是GPIO12EDIS;EALLOW; // 修改被保护的寄存器,修改前应添加EALLOW语句PieVectTable.XINT1 = &EXTI1_IRQn;EDIS; // EDIS的意思是不允许修改被保护的寄存器PieCtrlRegs.PIEIER1.bit.INTx4 = 1; // 使能PIE组1的INT4XIntruptRegs.XINT1CR.bit.POLARITY = 0; // 下降沿触发中断XIntruptRegs.XINT1CR.bit.ENABLE= 1; // 使能XINT1IER |= M_INT1; // 使能CPU中断1(INT1)EINT; // 开全局中断ERTM;
}interrupt void EXTI1_IRQn(void)
{Uint32 i;for(i=0;i<10000;i++); //键盘消抖动while(!KEY_H1);LED2_TOGGLE;PieCtrlRegs.PIEACK.bit.ACK1=1;
}void EXTI2_Init(void)
{EALLOW;SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1; // GPIO input clockEDIS;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*SYSCLKOUTGpioCtrlRegs.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是GPIO13EDIS;EALLOW; // 修改被保护的寄存器,修改前应添加EALLOW语句PieVectTable.XINT2 = &EXTI2_IRQn;EDIS; // EDIS的意思是不允许修改被保护的寄存器PieCtrlRegs.PIEIER1.bit.INTx5 = 1; // 使能PIE组1的INT5XIntruptRegs.XINT2CR.bit.POLARITY = 0; // 下降沿触发中断XIntruptRegs.XINT2CR.bit.ENABLE = 1; // 使能XINT2IER |= M_INT1; // 使能CPU中断1(INT1)EINT; // 开全局中断ERTM;
}interrupt void EXTI2_IRQn(void)
{Uint32 i;for(i=0;i<10000;i++); //键盘消抖动while(!KEY_H2);LED3_TOGGLE;PieCtrlRegs.PIEACK.bit.ACK1=1;
}
#ifndef EXTI_H_
#define EXTI_H_#include "DSP2833x_Device.h" // DSP2833x 头文件
#include "DSP2833x_Examples.h" // DSP2833x 例子相关头文件void EXTI1_Init(void);
interrupt void EXTI1_IRQn(void);void EXTI2_Init(void);
interrupt void EXTI2_IRQn(void);#endif /* EXTI_H_ */
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File#include "leds.h"
#include "exti.h"/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{int i=0;InitSysCtrl();InitPieCtrl();IER = 0x0000;IFR = 0x0000;InitPieVectTable();LED_Init();EXTI1_Init();EXTI2_Init();while(1){i++;if(i%2000==0){LED1_TOGGLE;}DELAY_US(100);}
}