自己编写的mini240外部按键中断程序

功能:按键K1--K4 相应的灯亮 且闪烁
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "def.h"
#include "Option.h"
 
 
  
void  delay(unsigned long dly)
{
for(; dly > 0; dly--);
}
 
 
 void __irq IRQ_KEY()
{
 if(rINTPND==BIT_EINT8_23) 
 
{ ClearPending(BIT_EINT8_23);//清除中断标志
 
 
if(rEINTPEND&(1<<8)) 
{
rGPBDAT = ~(1<<5);//点亮led1
 
delay(40000000);
 
rGPBDAT = (1<<5);//点亮其他led
 
delay(40000000);
         
            
    }
      else if(rEINTPEND&(1<<11))
        {
 rGPBDAT = ~(1<<6);//点亮led2
 
delay(40000000);
 
rGPBDAT = (1<<6);//点亮其他led
 
delay(40000000);
 }
  else if(rEINTPEND&(1<<13)) 
  {
        
        rGPBDAT = ~(1<<7);//点亮led3
 
delay(40000000);
 
rGPBDAT = (1<<7);//点亮其他led
 
delay(40000000);  
   }
else
       {
 rGPBDAT = ~(1<<8);//点亮led4
 
delay(40000000);
 
rGPBDAT = (1<<8);//点亮其他led
 
delay(40000000);
           
  }
 
 }
 
 rGPGCON =rGPGCON & (~((3<<22)|(3<<6)|(3<<0)|(3<<10)|(3<<12)|(3<<14))) |
                         ((2<<22)|(2<<6)|(2<<0)|(2<<10)|(2<<12)|(2<<14));
 
 
 
rEINTPEND |=((1<< 8)|(1<<11)|(1<<13)|(1<<14));//外部中断悬挂寄存器,清0无请求,1时有中断请求
rSRCPND |= (1<<5);//指示中断源状态,0无中断源请求,1时有中断源请求
rINTPND |=(1<<5);//指示中断状态,0无中断请求,1时有中断请求
 
}
void EINT_Init()
{
 
rGPGCON =rGPGCON & (~((3<<22)|(3<<6)|(3<<0)|(3<<10)|(3<<12)|(3<<14))) |
                         ((2<<22)|(2<<6)|(2<<0)|(2<<10)|(2<<12)|(2<<14));
 
 
 rEXTINT0=0x2;//设置为下降沿触发
 
 
 pISR_EINT8_23=(unsigned int)IRQ_KEY;
 
 rINTMOD=0;//所用中断都是IRQ
 
 rINTMSK=0xffffffdf;//开EINT0中断
 
 rEINTMASK &=(~((1<<8)|(1<<11)|(1<<13)|(1<<14)));//使能各个所需要的具体中断
 
}
void Main(void)
 
 MMU_Init();
 
 rGPBCON =0x55555554;//// 将LED1-4对应的GPB5/6/7/8四个引脚设为输出
 rGPBUP|=0x1e0;
 rGPBDAT=~(1<<5);//开led
 delay(40000000);
 
 EINT_Init();
  while(1)
 {
  rGPBDAT=~0;//关闭led
 }
}

posted on 2013-03-16 21:27  AI_JJ  阅读(110)  评论(0)    收藏  举报

导航