#include "at91SAM7S64.H"
#include "Board.H"
#include "aic.H"
#include "SystemClock.h"
#include "LED.H"
#define AT91S_PIO *pPIO = AT91C_BASE_PIOA ; //PIOA寄存器地址
#define AT91S_AIC *pAIC = AT91C_BASE_AIC ; //AIC寄存器地址
void PIOA_interrupt(void) //irq //中断服务子程序
{
DelayXms(20);
AT91C_BASE_PIOA->PIO_SODR=LED_MASK;
AT91C_BASE_PIOA->PIO_CODR=LED1;
*AT91C_AIC_EOICR=0xff;
}
else if(*AT91C_PIOA_PDSR == (1<<20) ) // 检测按键2是否按下
{
AT91C_BASE_PIOA->PIO_SODR=LED_MASK;
AT91C_BASE_PIOA->PIO_CODR=LED2;
// while(!((*AT91C_PIOA_PDSR) & 0x1));
*AT91C_AIC_EOICR=0xff;
}
else if(*AT91C_PIOA_PDSR == (1<<14) ) // 检测按键是否按下
{
AT91C_BASE_PIOA->PIO_SODR=LED_MASK;
AT91C_BASE_PIOA->PIO_CODR=LED3;
//while(!((*AT91C_PIOA_PDSR) & 0x1));
*AT91C_AIC_EOICR=0xff;
}*/
}
static void PIOA_Init(void) //PIOA初始化
{
AT91C_BASE_PIOA->PIO_PER = LED_MASK|SW_MASK; //LED和开关使能
//*AT91C_PIOA_PDR=SW_MASK; //按键设为外设
//*AT91C_PIOA_ASR=SW_MASK; //按键设为外设A
*AT91C_PIOA_ODR = SW_MASK; // 按键输出禁用
AT91C_BASE_PIOA->PIO_OER=LED_MASK; //LED输出使能
AT91C_BASE_PIOA->PIO_SODR=LED_MASK; //关闭灯的状态
//*AT91C_PIOA_IER = SW_MASK; //SW 输入中断使能
//AT91C_BASE_AIC->AIC_IDCR=AT91C_ID_PIOA;
//*AT91C_PIOA_PPUER = (1<<0); //上拉使能
//*AT91C_PIOA_OWER = (1<<1); //输出写使能
//*AT91C_PMC_SCER=AT91C_CKGR_MOSCEN; //系统时钟使能
//*AT91C_PMC_PCER = (1 << AT91C_ID_PIOA); //系统外设时钟使能
}
static void AIC_Init(void) //AIC初始化
{
AT91C_BASE_AIC->AIC_IDCR = (1<<AT91C_ID_PIOA) ; //关闭中断
AT91C_BASE_AIC->AIC_SVR[2] = (unsigned long ) * PIOA_interrupt ; //中断服务程序地址
AT91C_BASE_AIC->AIC_SMR[2] = (0X1<<5)|1; //下降沿触发,最高优先级
AT91C_BASE_AIC->AIC_ICCR = (1<<AT91C_ID_PIOA) ; //中断清除命令
*AT91C_PIOA_IER = SW_MASK; //中断使能命令
*AT91C_PIOA_IDR = LED_MASK; //LED中断禁止
AT91C_BASE_AIC->AIC_IECR = (1<<AT91C_ID_PIOA) ; //中断源使能
}
void main()
{
//SystemClockInit(); //初始化时钟
*AT91C_PMC_SCER=AT91C_CKGR_MOSCEN; //使能主时钟
*AT91C_PMC_PCER = (1 << AT91C_ID_PIOA); //使能外设时钟
PIOA_Init();
AIC_Init();
while(1)
{
//DelayXms(500);
}
}
不能进入中断,哪位大神有按键中断的程序,发一份 给我参考参考
|