void InitGpio(void)
{
EALLOW;
// Each GPIO pin can be:
// a) a GPIO input/output
// b) peripheral function 1
// c) peripheral function 2
// d) peripheral function 3
// By default, all are GPIO Inputs
GpioCtrlRegs.GPAMUX1.all = 0x0000; // GPIO functionality GPIO0-GPIO15
GpioCtrlRegs.GPAMUX2.all = 0x0000; // GPIO functionality GPIO16-GPIO31
GpioCtrlRegs.GPBMUX1.all = 0x0000; // GPIO functionality GPIO32-GPIO34
GpioCtrlRegs.AIOMUX1.all = 0x0000; // Dig.IO funct. applies to AIO2,4,6,10,12,14
GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF; // GPIO0-GPIO31 are GP outputs
GpioCtrlRegs.GPBDIR.all = 0x0000; // GPIO32-GPIO34 are inputs
GpioCtrlRegs.AIODIR.all = 0x0000; // AIO2,4,6,19,12,14 are digital inputs
GpioCtrlRegs.GPADIR.bit.GPIO12=0; //GPIO12 is input pin
// Each input can have different qualification
// a) input synchronized to SYSCLKOUT
// b) input qualified by a sampling window
// c) input sent asynchronously (valid for peripheral inputs only)
GpioCtrlRegs.GPAQSEL1.all = 0x0000; // GPIO0-GPIO15 Synch to SYSCLKOUT
GpioCtrlRegs.GPAQSEL2.all = 0x0000; // GPIO16-GPIO31 Synch to SYSCLKOUT
GpioCtrlRegs.GPBQSEL1.all = 0x0000; // GPIO32-GPIO34 Synch to SYSCLKOUT
GpioCtrlRegs.GPAQSEL1.bit.GPIO12=2; // six samples
GpioCtrlRegs.GPACTRL.bit.QUALPRD1=0x0f // 14 * SYSCLKOUT
// Pull-ups can be enabled or disabled.
GpioCtrlRegs.GPAPUD.all = 0x0000; // Pullup's enabled GPIO0-GPIO31
GpioCtrlRegs.GPBPUD.all = 0x0000; // Pullup's enabled GPIO32-GPIO34
//GpioCtrlRegs.GPAPUD.all = 0xFFFF; // Pullup's disabled GPIO0-GPIO31
//GpioCtrlRegs.GPBPUD.all = 0xFFFF; // Pullup's disabled GPIO32-GPIO34
GpioCtrlRegs.GPAPUD.bit.GPIO12=1; // Pullup's disabled GPIO12
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL=12; // GPIO12 is the XINT1's source
EDIS;
}
写完GPIO.c文件,现在要写外部中断程序,中断函数直接去TI提供的F2802x_DefaultIsr.c文件修改就行了,修改后如下:
interrupt void XINT1_ISR(void)
{
// Insert ISR Code here
GpioDataRegs.GPATOGGLE.all=0x000000ff;
// To receive more interrupts from this PIE group, acknowledge this interrupt
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
// Next two lines for debug only to halt the processor here
// Remove after inserting ISR Code
// asm (" ESTOP0");
// for(;;);
}
现在就剩最后一个主函数了,大家要记得,我们外部函数相关的开关都没开,我准备都放在主函数这里,我已经迫不及待了,马上去写出来给大家
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2802x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is found in the DSP2802x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
InitGpio();
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2802x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2802x_DefaultIsr.c.
// This function is found in DSP2802x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2802x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
// Step 5. User specific code:
GpioDataRegs.GPADAT.all = 0x00000000; //GPIO0-GPIO31 initial value are 0
EALLOW;
XIntruptRegs.XINT1CR.bit.POLARITY=0;
XIntruptRegs.XINT1CR.bit.ENABLE=1;
PieCtrlRegs.PIEIER1.bit.INTx4 = 1;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
IER = 0x0001;
EINT;
EDIS;
while(1)
{
// GpioDataRegs.GPATOGGLE.all=0x000000ff;
// DELAY_US(1000);
}
}
总算把主程序调完贴出来了,效果图如下: