这是实验代码。
void __irq Key_ISR_Handler(void)
{
uint32 status = *AT91C_PIOA_ISR;
*AT91C_AIC_ICCR = (1 << AT91C_ID_PIOA);
if(!((1<<15) & *AT91C_PIOA_PDSR)) {
LedAllOff();
LedOn(1);
}
else if(!((1<<16) & *AT91C_PIOA_PDSR)) {
LedAllOff();
LedOn(2);
}
else if(!((1<<20)& *AT91C_PIOA_PDSR)) {
LedAllOff();
LedAllOn();
}
else if(!((1<<23) & *AT91C_PIOA_PDSR)) {
LedAllOff();
LedOn(3);
}
*AT91C_AIC_EOICR = 1;
}
void KeyIrqInit(void)
{
*AT91C_PMC_PCER |= 0x00918000; //PMC外设时钟时能
*AT91C_PIOA_PER |= 0x00918000; //KEY1-4为I/0使用
*AT91C_PIOA_ODR |= 0x00918000; //输出禁止
*AT91C_PIOA_SODR |= 0x00918000; //置位输出
*AT91C_PIOA_IER |= 0x00918000; //key1-key4中断使能
// *AT91C_PIOA_IDR |= 0x00918000; //中断禁止
*AT91C_PIOA_IFER |= 0x00918000; //毛刺滤波器使能
*AT91C_PIOA_PPUER |= 0x00918000; //上拉/时能禁止
*AT91C_AIC_IDCR |= 1<<AT91C_ID_PIOA; //系统里面禁止中断
*AT91C_AIC_ICCR |= 1<<AT91C_ID_PIOA; //中断清除
*AT91C_AIC_IECR |= 1<<AT91C_ID_PIOA; //中断使能
???? pAIC->AIC_SMR[AT91C_ID_PIOA] = AT91C_AIC_SRCTYPE_EXT_LOW_LEVEL | 0; //设置触发模式和优先级
pAIC->AIC_SVR[AT91C_ID_PIOA] = (uint32) Key_ISR_Handler;
pAIC->AIC_IECR |= (1 << AT91C_ID_PIOA); //打开AIC中断
}
上面打??的地方是遇到问题的地方。
当改用下降沿触发时容易挂。。。不知道为什么。尚在研究中?
希望有知道的兄弟留言解释下。