External interrupt - press the button to turn the LED on and off. Use a matrix keyboard and use key delay to improve anti-interference ability. #include "DSP2833x_Project.h" /**************Function declaration**************/ void Gpio_setup(void); interrupt void xint1_isr(void); /***************Function declaration**************/ //Global variables used in this example; volatile Uint32 Xint1Count; //Number of times external interrupt 1 occurs; /***************Main function**************/ int main(void) { InitSysCtrl(); //Initialize system control Gpio_setup(); //Sub-function, gpio port settings DINT; //Disable interrupt InitPieCtrl(); //Initialize interrupt control IER = 0x0000; IFR = 0x0000; InitPieVectTable();//Initialize interrupt vector table EALLOW; //Modify the protected register, add EALLOW statement before modification PieVectTable.XINT1 = &xint1_isr; //Point the xint1_isr interrupt sub-function to the address of PieVectTable.XINT1EDIS; // EDIS means that the protected register is not allowed to be modifiedXint1Count = 0; // Count external interrupt 1 (XINT1) PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable peripheral interrupt extension PIE modulePieCtrlRegs.PIEIER1.bit.INTx4 = 1; // Enable INT4 of PIE group 1 IER |= M_INT1; EINT; ERTM; EALLOW; GpioDataRegs.GPBSET.bit.GPIO60 = 1; // Output high levelGpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; // Select as general I/O portGpioCtrlRegs.GPBDIR.bit.GPIO60 = 1; // Direction defined as outputEDIS; EALLOW; GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; // Select as general I/O port GpioCtrlRegs.GPADIR.bit.GPIO12 = 0; // Direction defined as input GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 0; // External interrupt 1 (XINT1) synchronized with system clock SYSCLKOUT EDIS; EALLOW; GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 0x0C; // XINT1 is GPIO12 EDIS; XIntruptRegs.XINT1CR.bit.POLARITY = 0; // Falling edge triggered interrupt XIntruptRegs.XINT1CR.bit.ENABLE = 1; // Enable XINT1 for(;;); } void Gpio_setup(void) { EALLOW; //////Set the following IO ports as outputs for column scan///////// //Initialize GPIO50 in row 3 GpioCtrlRegs.GPBPUD.bit.GPIO50 = 0; // Enable pullup on GPIO50 GpioDataRegs.GPBCLEAR.bit.GPIO50 = 1; // Load output latch GpioCtrlRegs.GPBMUX2.bit.GPIO50 = 0; // GPIO50 = GPIO GpioCtrlRegs.GPBDIR.bit.GPIO50 = 1; // GPIO50 = output EDIS; } interrupt void xint1_isr(void) { DELAY_US(5000); //Keyboard debounce while(GpioDataRegs.GPADAT.bit.GPIO12==0); GpioDataRegs.GPBTOGGLE.bit.GPIO60 = 1; //GPIO60-GPIO61 output level inversion Xint1Count++; // Clear bit 1 of the response register to 0 in response to other interrupts in the same group; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; }