原创 外部中断 key YLP-S3C2440

2009-2-27 20:50 2753 5 5 分类: MCU/ 嵌入式

rar


Register       Address R/W              Description                 Reset Value<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />


EXTINT0 0x56000088 R/W External Interrupt control Register 0 0x000000


EXTINT1 0x5600008c R/W External Interrupt control Register 1 0x000000


EXTINT2 0x56000090 R/W External Interrupt control Register 2 0x000000


 


点击看大图


 


 


点击看大图


 


 


 点击看大图


 

PRIORITY


点击看大图


 

 #define ClearPending(bit) {\
                rSRCPND = bit;\
                rINTPND = bit;\
                rINTPND;\
                }

 


aa0969f5-0dc5-40e3-9fef-1f1505c90140.jpg


0b090dca-f89f-4ff4-bfe8-b5ebfcdfae94.jpg


 


37ed05a9-72b9-44f6-a5b7-ba05adf6e4a2.jpg


 


1ab317cb-6f40-4c5f-85ba-5b8f8129fe9b.jpg


 


#define BIT_EINT8_23   (0x1<<5)


 

点击看大图


 


点击看大图


 


20875a89-aebd-4bea-acff-397ecbbf658d.jpg


If an interrupt mode is set to FIQ mode in the INTMOD register, FIQ interrupt will not affect both INTPND and
INTOFFSET registers. In this case, the two registers are valid only for IRQ mode interrupt source.


 


 


 


58424adc-665c-4804-b5f4-16d5a09fd140.jpg


 


27fc9d70-4f68-4df2-b7d0-937ef34f9725.jpg


 


5371d081-3030-4068-8817-fae451fd7ee8.jpg


 


点击看大图


 


 


#include "2440addr.h"


#define    KEY1      (1 << 0)  //GPF0,EINT0       GPB6


#define    KEY2      (1 << 0)  //GPF0,EINT0       GPB7


#define    KEY3      (1 << 5)  //GPG5,EINT13     GPB6


#define    KEY4      (1 << 5)  //GPG5,EINT13     GPB7


 


#define LED1  (1 << 4)  //GPF4


#define LED2  (1 << 5)  //GPF5


#define LED3  (1 << 6)  //GPF6


#define LED4  (1 << 7)  //GPF7


 


void __irq IRQ_KEY12()


{


    ClearPending(BIT_EINT0);


    rEINTPEND = 0xffffff;


    rGPFCON = rGPFCON & (~(3 << 0) );             //设置为输入状态


 


       rGPBDAT = rGPBDAT & (~(1<<6));                 //set GPB6 low


       rGPBDAT = (rGPBDAT | (1<<7));                     //set GPB7 high


       if (rGPFDAT & KEY1)  {


              rGPFDAT |= LED1;                                   //熄灭LED1


       }


       else {


              rGPFDAT &= ~LED1;                               //点亮LED1


       }


      


       rGPBDAT = rGPBDAT & (~(1<<7));                 //set GPB7 low


       rGPBDAT = (rGPBDAT | (1<<6));                     //set GPB6 high


       if (rGPFDAT & KEY2)  {


              rGPFDAT |= LED2;                                   //熄灭LED2


       }


       else {


              rGPFDAT &= ~LED2;                               //点亮LED2


       }


    rGPFCON |= (2 << 0);                              //重新设置外部中断输入功能


}


 


 


void __irq IRQ_KEY34()


{


    ClearPending(BIT_EINT8_23);


    rEINTPEND = 0xffffff;


    rGPGCON = rGPGCON & (~(3 << 5) );            //设置为输入状态


   


       rGPBDAT = rGPBDAT & (~(1<<6));                 //set GPB6 low


       rGPBDAT = (rGPBDAT | (1<<7));                     //set GPB7 high


       if (rGPGDAT & KEY3)  {


              rGPFDAT |= LED3;                                   //熄灭LED3


       }


       else {


              rGPFDAT &= ~LED3;                               //点亮LED3


       }


      


       rGPBDAT = rGPBDAT & (~(1<<7));                 //set GPB7 low


       rGPBDAT = (rGPBDAT | (1<<6));                     //set GPB6 high


       if (rGPGDAT & KEY4)  {


              rGPFDAT |= LED4;                                   //熄灭LED4


       }


       else {


              rGPFDAT &= ~LED4;                               //点亮LED4


       }


    rGPGCON |= (2 << 5);                              //重新设置外部中断输入功能


}


 


void eint_init()


{


       rGPFCON = rGPFCON & (~(3<<0)) | (2 << 0); 


       rGPGCON = rGPGCON & (~(3<<10)) | (2 << 10);        //设置外部中断输入功能


       rEXTINT0 = rEXTINT0 & (~(7 << 0));                          //EINT0低电平触发中断


       rEXTINT1 = rEXTINT1 & (~(7 << 20));                       //EINT13低电平触发中断


       pISR_EINT0 = (unsigned int)IRQ_KEY12;


       pISR_EINT8_23 = (unsigned int)IRQ_KEY34;             //设置中断入口函数


       rPRIORITY = 0x00000000;                                           // 使用默认的固定的优先级


       ClearPending(BIT_EINT0);                                           // 清除中断标志位


       ClearPending(BIT_EINT8_23);


       rEINTPEND = 0xffffff;                                                // 清除中断信号


       rINTMOD = 0x00000000;                                          // 所有中断均为IRQ中断


       rINTMSK &= ~( (BIT_EINT0) | (BIT_EINT8_23) ); // 使能外部中断0、8_23


       rEINTMASK &= ~(1 << 13);                                    //使用能EINT13


}


 


void Init()


{


       rGPFCON = (rGPFCON & 0x00ff) | 0x5500;            //set GPF[7:4] output


       rGPFDAT |= LED1 | LED2 | LED3 | LED4;         //熄灭


       rGPBCON = (rGPBCON & (~((3<<12)|(3<<14)))) \


                            | ( (1<<12)|(1<<14) );                  //set GPB[7:6] output


       rGPBDAT = rGPBDAT & (~((1<<6) | (1<<7)));


}


 


void Main()


{


       Init();


       eint_init();


       while(1) {


              rGPBDAT = rGPBDAT & (~((1<<6) | (1<<7)));


       }


}


 


 


 

文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /2 下一条