//=============================================================================
// File Name : 2440addr.h
// Function : TQ2440 Define Address Register
// Revision : 1.0
//=============================================================================
//#define _RAM_STARTADDRESS 0x30000000
#define _ISR_STARTADDRESS 0x33ffff00
//#define _MMUTT_STARTADDRESS 0x33ff8000
//#define _STACK_BASEADDRESS 0x33ff8000
//#define HEAPEND 0x33ff0000
//#define _NONCACHE_STARTADDRESS 0x31000000
#ifndef __2440ADDR_H__
#define __2440ADDR_H__
#define rGPBCON (*(volatile unsigned *)0x56000010) //Port B control
#define rGPBDAT (*(volatile unsigned *)0x56000014) //Port B data
#define rGPBUP (*(volatile unsigned *)0x56000018) //Pull-up control B
#define rGPFCON (*(volatile unsigned *)0x56000050) //Port F control
#define rGPFDAT (*(volatile unsigned *)0x56000054) //Port F data
#define rGPFUP (*(volatile unsigned *)0x56000058) //Pull-up control F
#define rEINTPEND (*(volatile unsigned *)0x560000a8) //External interrupt pending
#define rEXTINT0 (*(volatile unsigned *)0x56000088)
#define BIT_EINT0 (0x1)
#define BIT_EINT1 (0x1<<1)
#define BIT_EINT2 (0x1<<2)
#define BIT_EINT4_7 (0x1<<4)
#define rSRCPND (*(volatile unsigned *)0x4a000000) //Interrupt request status
#define rINTMSK (*(volatile unsigned *)0x4a000008)
#define rINTPND (*(volatile unsigned *)0x4a000010) //Interrupt request status
__inline void ClearPending(int bit)
{
register i;
rSRCPND = bit;
rINTPND = bit;
i = rINTPND;
}
#define pISR_EINT0 (*(unsigned *)(_ISR_STARTADDRESS+0x20))
#define pISR_EINT1 (*(unsigned *)(_ISR_STARTADDRESS+0x24))
#define pISR_EINT2 (*(unsigned *)(_ISR_STARTADDRESS+0x28))
#define pISR_EINT4_7 (*(unsigned *)(_ISR_STARTADDRESS+0x30))
#define EnableIrq(bit) rINTMSK &= ~(bit)
#define rEINTMASK (*(volatile unsigned *)0x560000a4) //External interrupt mask
#endif
/*****************启动程序Init.s******************
WTCON EQU 0x53000000
IMPORT ledMain
AREA Init,CODE,READONLY
CODE32
ENTRY
;打开IQR
mrs r2,CPSR
bic r2,r2,#0x80
msr CPSR_cxsf,r2
ldr r0, =WTCON ; WATCHDOG寄存器,R/W,复位值0x8021
mov r1, #0x0
str r1, [r0] ; 写入0,禁止WATCHDOG复位,否则CPU会不断重启
LDR SP, =1024*4 ; 设置栈。注意:不能超过4K,因为是在SRAM上运行
; NAND FLASH中的代码,在复位后,硬件自动将其复制到内部SRAM
bl ledMain ; 调用C函数
halt_loop
b halt_loop
END
/*********************C程序部*******************************
#include "2440addr.h" //头文件,包含宏定义及清除挂起寄存器的ClearPending()函数
#define TEST
static void __irq Key_ISR( void );//中断函数声明
static void led_init(void );
static void key_init( void);
void ledMain(void)
{
led_init( );
key_init();
while(1);//等待中断发生
}
static void led_init(void )
{
//01 0101 0100 0000 0000;GPB5,GPB6,GPB7,GPB8设置为输出
rGPBCON = 0x15400;
// 4个LED全亮
rGPBDAT =0x0;
}
static void key_init( void)
{
//ClearPending(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7);//清外部中断0,1,2,4
//K1->GPF1,K2->GPF4,K3->GPF2,K4->GPF0工作在第二功能状态,即中断
rGPFCON &=~((3<<(0*2))|(3<<(1*2))|(3<<(2*2))|(3<<(2*4))) ;
//( <<) 11 0011 11 11
//( ~ ) 00 1100 00 00
//( &=) 00 XX00 00 00
rGPFCON |= ((2<<(0*2))|(2<<(1*2))|(2<<(2*2))|(2<<(2*4))) ;
//( <<) 10 0010 10 10
//( |=) 10 XX10 10 10
rEXTINT0=0x0;//低电平触发
rEINTPEND=(1<<4); //清外部中断挂起寄存器,清的是外部中断4
rEINTMASK=~(1<<4); //使能外部中断4
pISR_EINT0= pISR_EINT1 =pISR_EINT2 = pISR_EINT4_7=(unsigned int )Key_ISR;//设中断服务函数地址
EnableIrq(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7);//使能中断,即使INTMSK相应位为0
}
static void __irq Key_ISR()//中断服务函数,__irq用来声明通用中断函数
{
char key;//用来标识是哪一个按键按下
#ifdef TEST
rGPBDAT =0x20;
#endif
rINTMSK=0xffffffff;//这是屏蔽所有中断
if(rINTPND==BIT_EINT0) { //因为4个中断用的是同一个中断服务函数,所以判断是哪一个中断发生
ClearPending(BIT_EINT0); //并清除挂起寄存器,获得键值
key=1;
}else if(rINTPND==BIT_EINT1) {
ClearPending(BIT_EINT2);
key=2;
}else if(rINTPND==BIT_EINT2) {
ClearPending(BIT_EINT2);
key=3;
}else if(rINTPND==BIT_EINT4_7){
rEINTPEND=(1<<4);
ClearPending(BIT_EINT4_7);
key=4;
}
switch(key){ //根据键值控制4个LED亮灭变化
case 1: rGPBDAT = (1<<5);
break;
case 2: rGPBDAT = (1<<6);
break;
case 3: rGPBDAT = (1<<7);
break;
case 4: rGPBDAT = (1<<8);
break;
}
EnableIrq(BIT_EINT0|BIT_EINT1|BIT_EINT2|BIT_EINT4_7);//再打开中断
}
出现问题:无**常中断,我没分析出原因,求指教....谢谢 |