ARM7 的中断寄存器的设置方法

以设置外部中断2(EINT2)为例,进行ARM7中断寄存器的设置,并编写其相应的中断程序如下:

//设置中断类型
rEXTINT = 0x22221122 ;  //EINT2高电平触发中断 

//给定中断服务程序入口
pISR_EINT2 = (unsigned)Encoder_int;

//打开全局中断和eINT2中断
rINTMSK &= ~(BIT_GLOBAL|BIT_EINT2); 

/*
当ExINT2为高电平时,旋转编码器有新值,你先读低字节,再读高字节。其中低15位为旋转编码器的值,最高位为其按键的状态。
*/

//定义编码器的低地址
#define ENCODER_LOW_ADDR  (*(volatile unsigned char *)(0x06000000 + 0x400004))

//定义编码器的高地址
#define ENCODER_HIGH_ADDR  (*(volatile unsigned char *)(0x06000000 + 0x400005))

//编码器的中断服务程序实现
void __irq Encoder_int(void)
{
    unsigned int encoderVal = 0;

    rPCONG = rPCONG & (~0x30);//INPUT

   if(rINTPND & BIT_EINT2) {
  //encoder flag is true, means the status of rotate encoder is changed;      
        encoderVal = ENCODER_HIGH_ADDR<<8|ENCODER_LOW_ADDR;
        debugprintf("the rotate encoder value is :%x\n", encoderVal);
    }
    rI_ISPC = BIT_EINT2;//置位时,标志此中断请求已经被处理了.
    rPCONG =rPCONG | 0x30;//EINT2
}

同理,其它的中断也可照样完成。
posted @ 2015-07-27 13:13  chenqiangzhishen  阅读(279)  评论(0编辑  收藏  举报