这个问题很基础,但是我看了手册和南哥的书,还是没能实现响应按键中断。请大家帮忙看看。
想把K5 和K6 设置为中断方式,使用的IO是GPG7 和GPG11,对应中断EINT15 EINT19.
我已经配置了IO口的模式为中断,触发方式为双边沿触发,也设置了中断屏蔽和外部中断屏蔽。
虽然贴代码很不好,但还是要贴下。
谢谢大家!! :L
#define ON 1
#define OFF 0
#define LED1_Pin (1<<5)
#define LED2_Pin (1<<6)
#define LED3_Pin (1<<7)
#define LED4_Pin (1<<8)
#define LED1(a) (a==0)?(rGPBDAT |= LED1_Pin):(rGPBDAT &= ~LED1_Pin)
#define LED2(a) (a==0)?(rGPBDAT |= LED2_Pin):(rGPBDAT &= ~LED2_Pin)
#define LED3(a) (a==0)?(rGPBDAT |= LED3_Pin):(rGPBDAT &= ~LED3_Pin)
#define LED4(a) (a==0)?(rGPBDAT |= LED4_Pin):(rGPBDAT &= ~LED4_Pin)
#define KEY1 (1<<0)
#define KEY2 (1<<3)
#define KEY3 (1<<5)
#define KEY4 (1<<6)
#define KEY5 (1<<7)
#define KEY6 (1<<11)
void __irq IRQ_KEY(void)
{
unsigned int Key = 0;
ClearPending(BIT_EINT8_23);
rEINTPEND = 0xFFFFFF;
rGPGCON &= ~((3<<14)|(3<<22)); //set gpg7 11 to input
Key = rGPGDAT;
if (!(Key & KEY5))
{
LED1(OFF);
LED2(OFF);
LED3(OFF);
LED4(OFF);
}
if (!(Key & KEY6))
{
LED1(ON);
LED2(ON);
LED3(ON);
LED4(ON);
}
rGPGCON |= ((2<<14)|(2<<22)); //set gpg7 11 to ENINT
}
void InitKey(void)
{
//set pins 0 3 5 6 7 11 to input
rGPGCON &= ~((3<<0)|(3<<6)|(3<<10)|(3<<12)|(3<<14)|(3<<22));
//config the Key5(GPG7) and Key6(GPG11) pins to EINT mode
rGPGCON &= ~((3<<14)|(3<<22));
rGPGCON |= ((2<<14)|(2<<22));
//config trigger mode
rEXTINT1 |= ((U32)7<<28); //EINT15
rEXTINT1 = 0xFFFFFFFF;
rEXTINT1 |= ((U32)7<<28); //EINT15
rEXTINT2 |= ((U32)7<<12); //EINT19
pISR_EINT8_23 = (unsigned int)IRQ_KEY;
rEINTPEND |= (((U32)1<<15)|((U32)1<<19)); //clean pending //rEINTPEND = 0xFFFFFF;
ClearPending(BIT_EINT8_23);//rSRCPND |= 0xFFFFFF;
rPRIORITY = 0;
rINTMOD = 0;
//enable Key5(GPG7/EINT15) and Key6(GPG11/EINT19) interrupt(open marsk)
rEINTMASK &= ~(((U32)1<<15)|((U32)1<<19));
rINTMSK &= ~BIT_EINT8_23;
}
void scan_key(void)
{
unsigned int Key = 0;
Key = rGPGDAT;
if (!(Key & KEY1))
LED1(ON);
if (!(Key & KEY2))
LED2(ON);
if (!(Key & KEY3))
LED3(ON);
if (!(Key & KEY4))
LED4(ON);
}
void delay(U32 tt)
{
U32 i;
for(;tt>0;tt--)
{
for(i=0;i<10000;i++){}
}
}
int Main(int argc, char **argv)
{
int i;
U8 key;
U32 mpll_val=0;
int data;
mpll_val = (92<<12)|(1<<4)|(1);
//init FCLK=400M, so change MPLL first
ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
ChangeClockDivider(key, 12);
MMU_DisableICache();
MMU_DisableDCache();
rGPBCON = 0x155555;
InitKey();
LED1(ON);LED2(ON);LED3(ON);LED4(ON);
while(1)
{
scan_key();
delay(10);
}
return 0;
}
|