程序中语句后
有写“//自己添加的”‘’都是自己添加上去的:
//! - Xint1Count - XINT1 interrupt count
//! - Xint2Count - XINT2 interrupt count
//! - LoopCount - Idle loop count
//
//###########################################################################
//###########################################################################
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
// Prototype statements for func
tions found within this file.
__interrupt void xint3_isr(void);
__interrupt void xint4_isr(void);
__interrupt void xint1_isr(void);//自己添加的
volatile Uint32 Xint3Count;
volatile Uint32 Xint4Count;
volatile Uint32 Xint1Count;//自己添加的
Uint32 LoopCount;
#define DELAY 35.700L
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.XINT3 = &xint3_isr;
PieVectTable.XINT4 = &xint4_isr;
PieVectTable.XINT1 = &xint1_isr;//自己添加的
EDIS; // This is needed to disable write to EALLOW protected registers
Xint3Count = 0; // Count Xint1 interrupts
Xint4Count = 0; // Count XINT2 interrupts
Xint1Count = 0; // //自己添加的
LoopCount = 0; // Count times through idle loop
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // 使能PIE块 Enable the PIE block
PieCtrlRegs.PIEIER12.bit.INTx1= 1; // 使能组12 INT1 Enable PIE Gropu 12 INT1
PieCtrlRegs.PIEIER12.bit.INTx2 = 1; // 使能组12 INT2 Enable PIE Gropu 12 INT2
PieCtrlRegs.PIEIER1.bit.INTx4 = 1; // 使能组1 INT4 //自己添加的
IER |= M_INT12; // Enable CPU int1
EINT; // Enable Global Interrupts
// GPIO0 and GPIO1 are inputs
EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 0; // GPIO60 对应开关SW4
GpioCtrlRegs.GPBDIR.bit.GPIO60 = 0; // input
GpioCtrlRegs.GPBQSEL2.bit.GPIO60 = 0; // Xint1同步到SYSCLKOUT Xint1 Synch to SYSCLKOUT only Xint1同步到SYSCLKOUT
//自己添加的
GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 0; // GPIO13 对应开关SW3
GpioCtrlRegs.GPADIR.bit.GPIO13 = 0; // input
GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 0; // Xint1同步到SYSCLKOUT Xint1 Synch to SYSCLKOUT only Xint1同步到SYSCLKOUT
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO61 对应开关SW5
GpioCtrlRegs.GPBDIR.bit.GPIO61 = 0; // input
GpioCtrlRegs.GPBQSEL2.bit.GPIO61 = 2; // XINT2 Qual使用6个样本 XINT2 Qual using 6 samples
GpioCtrlRegs.GPBCTRL.bit.QUALPRD0 = 0xFF; // 每个采样窗口是510个SYSCLKOUT Each sampling window is 510*SYSCLKOUT
EDIS;
//注意一点就是外部中断1和2只能对GPIO0—GPIO31配置;
//外部中断3和4、5、6、7只对GPIO32—GPIO63配置。
//GPIO分为A(0-31)、B(32-63)、C(64-87);C组的不能配置为外部中断;
EALLOW;
GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL = 60;//0x1c; //GPIO60//28 选择GPIO中断输入源 GPIO32 至 63
GpioIntRegs.GPIOXINT4SEL.bit.GPIOSEL = 29;//0x1d; //GPIO61//29 选择GPIO中断输入源 GPIO32 至 63
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 13; //GPIO13//自己添加的
EDIS;
// Configure XINT1
XIntruptRegs.XINT3CR.bit.POLARITY = 0; // Falling edge interrupt 下降沿中断 SW4 GPIO60
XIntruptRegs.XINT4CR.bit.POLARITY = 1; // Rising edge interrupt 上升沿中断 SW5 GPIO61
XIntruptRegs.XINT1CR.bit.POLARITY = 0; // Falling edge interrupt 下降沿中断 SW3 GPIO13 //自己添加的
// Enable XINT1 and XINT2
XIntruptRegs.XINT3CR.bit.ENABLE = 1; // 使能外部中断3
XIntruptRegs.XINT4CR.bit.ENABLE = 1; // 使能外部中断4
XIntruptRegs.XINT1CR.bit.ENABLE = 1; // 使能外部中断1 //自己添加的
// 用来指示发生了中断,在中断函数中进行翻转
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO
GpioCtrlRegs.GPADIR.bit.GPIO0 = 1; // output
GpioDataRegs.GPADAT.bit.GPIO0=1; //付初值
EDIS;
LoopCount=0;
for(;;)
{
LoopCount++;
}
}
__interrupt void xint3_isr(void)
{
GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1; // GPIO0翻转
Xint3Count++;
// Acknowledge this interrupt to get more from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12;//另外还要注意PIEACK位的清除也只有软件清除,一般在中断程序的结尾向对应PIE ACK位写1来清除。
}
__interrupt void xint4_isr(void)
{
GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1; // GPIO0翻转
Xint4Count++;
// Acknowledge this interrupt to get more from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12;//另外还要注意PIEACK位的清除也只有软件清除,一般在中断程序的结尾向对应PIE ACK位写1来清除。
}
//自己添加的
__interrupt void xint1_isr(void)
{
GpioDataRegs.GPATOGGLE.bit.GPIO0 = 1; // GPIO0翻转
Xint1Count++;
// Acknowledge this interrupt to get more from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;//另外还要注意PIEACK位的清除也只有软件清除,一般在中断程序的结尾向对应PIE ACK位写1来清除。
}
仿真结果如下:我自己写的按键中断按下去一直没反应。请前辈们知道的知道一下新手小弟。