#define
GLOBAL_CLK
1
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
void key_init(void);
static void __irq key_handler(void);
/*************************************************
延时函数
**************************************************/
void delay(int times)
{
int i,j;
for(i=0;i<times;i++)
for(j=0;j<400;j++);
}
/*************************************************
LED初始化
**************************************************/
void Led1_init(void)
{
rGPBCON &= ~(3<<10);
rGPBCON |= (1<<10);
}
/*************************************************
点亮LED
**************************************************/
void Led1_run(void)
{
rGPBDAT &=~(1<<5); /*LED亮还是灭?*/
delay(1000);
rGPBDAT |=(1<<5);
delay(1000);
}
/*************************************************
主函数
**************************************************/
void Main(void)
{
MMU_Init();
Led1_init();
key_init();
while(1);
}
/*************************************************
按键初始化
**************************************************/
void key_init(void)
{
rGPGCON &= ~(0x3<<0);
rGPGCON |= (0x2<<0);//GPG0 [1:0]--->10 = EINT[8]
设置GPG0为中断模式
rEXTINT1 &= ~(0xf<<0); //EINT8 [2:0] ----> 000 = Low level
//FLTEN8 [3] ------->0 = Filter Disable
rEINTPEND |= (1<<8); //EINT8 [8] It is cleard by writing “1”
rEINTMASK &= ~(1<<8); //EINT8 [8]--------> 0 = enable interrupt
允许EINT8中断
/*设置ISR*/
pISR_EINT8_23=(U32)key_handler;
//将中断服务函数的地址传给对应的中断向量表位置
EnableIrq(BIT_EINT8_23);
//#define
EnableIrq(bit)
rINTMSK &= ~(bit)
//EINT8_23 [5] ---->0 = Service available, 1 = Masked
}
/*************************************************
按键中断处理函数
**************************************************/
static void __irq key_handler(void)
{
/*判断是否是按键K1产生的中断*/
if(rINTPND==BIT_EINT8_23) //INTPND:EINT8_23 [5] 0 = Not requested, 1 = Requested
{
ClearPending(BIT_EINT8_23);
if(rEINTPEND&(1<<8))
rEINTPEND |= 1<< 8;//清EINT8中断
Led1_run();
}
}
在2440addr.h头文件中:
#define BIT_EINT8_23 (0x1<<5)
__inline void ClearPending(int bit) { register i; rSRCPND = bit;//清EINT8_23中断 rINTPND = bit;//清EINT8_23中断 i = rINTPND; }
|