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) {\
#define BIT_EINT8_23 (0x1<<5)
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.
#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条评论)
登录后参与讨论