#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#define GPGCON (*(volatile unsigned *)0x56000060)
#define GPGDAT (*(volatile unsigned *)0x56000064)
#define GPBCON (*(volatile unsigned *)0x56000010)
#define GPBDAT (*(volatile unsigned *)0x56000014)
#define SRCPND (*(volatile unsigned *)0x4a000000)//源挂起寄存器
//0 中断未被请求 1 中断源声明了中断请求
#define INTMOD (*(volatile unsigned *)0x4a000004)//中断模式寄存器
//0 外部中断 1 快速中断
#define INTMASK (*(volatile unsigned *)0x4a000008)//中断屏蔽寄存器
//0 可服务 1 屏蔽
#define INTPND (*(volatile unsigned *)0x4a000010)//中断挂起寄存器
//0 未请求 1 请求
#define EINTPEND (*(volatile unsigned *)0x560000a8)//外部中断挂起寄存器
//0 使能中断 1 禁止中断
#define EXTINT1 (*(volatile unsigned *)0x5600008c)//外部中断控制器
//配置信号触发方式,此处为上升沿触发(10x)
#define EXTINT2 (*(volatile unsigned *)0x56000090)
#define EINTMASK (*(volatile unsigned *)0x560000a4)
//#define pISR_EINT0 (*(unsigned *)(
//#define BIT_EINT0 (1)
//#define BIT_EINT2 (1<<2)
//#define BIT_EINT8_23 (1<<5)
#define Enableirq(bit) INTMASK &= ~(bit)
#define Disableirq(bit) INTMASK |=(bit)
__inline void Clearpending(int bit)
{
register i;
SRCPND =bit;
INTPND =bit;
i=INTPND;
}
U8 Key_scan(void)
{
Delay(80);
if((GPGDAT & (1<<0))==0)
{
GPBDAT &=(0<<5);
Delay(1000);
GPBDAT |=(1<<5);
return 1;
}
else if((GPGDAT & (1<<3))==0)
{
GPBDAT &=(0<<6);
Delay(1000);
GPBDAT |=(1<<6);
return 2;
}
else if((GPGDAT & (1<<5))==0)
{
GPBDAT &=(0<<7);
Delay(1000);
GPBDAT |=(1<<7);
return 3;
}
else if((GPGDAT & (1<<6))==0)
{
GPBDAT &=(0<<8);
Delay(1000);
GPBDAT |=(1<<8);
return 4;
}
else if((GPGDAT & (1<<7))==0)
return 5;
else if((GPGDAT & (1<<11))==0)
return 6;
else
return 0xff;
}
static void __irq Key_ISR(void)
{
U8 key;
U32 r;
EnterCritical(&r);
if(INTPND==BIT_EINT8_23)
{
Clearpending(BIT_EINT8_23);
if(EINTPEND & (1<<8))//写1清零此位
EINTPEND |=(1<<8);
if(EINTPEND & (1<<11))
EINTPEND |=(1<<11);
if(EINTPEND & (1<<13))
EINTPEND |=(1<<13);
if(EINTPEND & (1<<14))
EINTPEND |=(1<<14);
if(EINTPEND & (1<<15))
EINTPEND |=(1<<15);
if(EINTPEND & (1<<19))
EINTPEND |=(1<<19);
}
key=Key_scan();
if(key==0xff)
Uart_Printf("Interrupt occur... key is released!\n");
else
Uart_Printf("Interrupt occur... key %d is pressed!\n",key);
ExitCritical(&r);
}
void Main(void)
{
GPBCON|=(1<<10)|(1<<12)|(1<<14)|(1<<16);
GPBDAT=GPBDAT |(1<<5)|(1<<6)|(1<<7)|(1<<8);
GPGCON=GPGCON | (2<<0)|(2<<6)|(2<<10)|(2<<12)|(2<<14)|(2<<22);
EXTINT1 &=~(7<<0);
EXTINT1 |=(0<<0);
EXTINT1 &=~(7<<12);
EXTINT1 |=(0<<12);
EXTINT1 &=~(7<<20);
EXTINT1 &=~(7<<24);
EXTINT1 &=~(7<<28);
EXTINT2 &=~(0xf<<12);
EINTPEND |=(1<<8)|(1<<11)|(1<<13)|(1<<14)|(1<<15)|(1<<19);
EINTMASK &=(0<<8)&(0<<11)&(0<<13)&(0<<14)&(0<<15)&(0<<19);
Clearpending(BIT_EINT0|BIT_EINT2|BIT_EINT8_23);
pISR_EINT0=pISR_EINT2=pISR_EINT8_23=(U32)Key_ISR;
INTMASK =0x0;
//Enableirq(BIT_EINT0|BIT_EINT2|BIT_EINT8_23);
while(1);
Disableirq(BIT_EINT0|BIT_EINT2|BIT_EINT8_23);
}