|
一个外部中断的例子,此例中使用了不可屏蔽中断,中断触发引脚GPIO16,触发方式边沿触发,供大家参考。主程序如下,工程见附件。
#include "DSP2833x_Device.h" // Headerfile Include File
#include "DSP2833x_Examples.h" // Examples Include File
#define LED1 GpioDataRegs.GPBDAT.bit.GPIO60
#define LED2 GpioDataRegs.GPBDAT.bit.GPIO61
#define inpt GpioDataRegs.GPADAT.bit.GPIO16
interrupt void nmi_isr(void);
void configtestled(void);
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.XNMI = &nmi_isr;
EDIS;
EINT; // Enable Global Interrupts
configtestled();
// GPIO16 is input
EALLOW;
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO16 = 0; // input
GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 0; // XNMI Synch to SYSCLKOUT only
EDIS;
// GPIO16 is XNMI
EALLOW;
GpioIntRegs.GPIOXNMISEL.bit.GPIOSEL = 16; // XNMI is GPIO16
EDIS;
EALLOW;
// Configure NMI
XIntruptRegs.XNMICR.bit.POLARITY = 3; // Rising & Falling edge interrupt
// Enable XNMI
XIntruptRegs.XNMICR.bit.ENABLE = 1; // Enable XNMI
XIntruptRegs.XNMICR.bit.SELECT = 0;
EDIS;
LED1 = 1;
LED2 = 1;
DINT;
for(;;)
{
}
}
interrupt void nmi_isr(void)
{
LED1 = ~LED1;
if (inpt == 1)
LED2 = 0;
else
LED2 = 1;
EDIS;
}
void configtestled(void)
{
EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; // GPIO60 = GPIO60
GpioCtrlRegs.GPBDIR.bit.GPIO60 = 1;
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO61 = GPIO61
GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1;
EDIS;
}
|
赞赏
-
1
查看全部赞赏
-
|