本帖最后由 dosculler 于 2011-4-25 09:09 编辑
//主程序init.c如下
//LED1-4分别为GPF0-3,KEY1-4分别为GPF4-7
#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 rEXTINT0 (*(volatile unsigned *)0x56000088) //External interrupt control register 0
#define rEINTMASK (*(volatile unsigned *)0x560000a4) //External interrupt mask
#define rEINTPEND (*(volatile unsigned *)0x560000a8) //External interrupt pending
#define rINTPND (*(volatile unsigned *)0x4a000010) //Interrupt request status
#define EnableIrq(bit) rINTMSK &= ~(bit)
#define BIT_EINT4_7 (0x1<<4)
#define LED1ON 0xFE
#define LED2ON 0xFD
#define LED3ON 0xFB
#define LED4ON 0xF7
#define LEDOFF 0xFF //LED熄灭值为0xFF
void __irq EintHandler(void);
void Main(void)
{
rGPFCON = (rGPFCON|0xFFFF)&0xFFFFaa55; //GPF4-7设置为EINT4-7,GPF0-3为输出
rGPFUP &= 0xFF00; //打开上拉功能
rGPFDAT |= 0xF;
rEXTINT0 &= ~(7<<16 | 7<<20 | 7<<24 | 7<<28);
rEXTINT0 |= (2<<16 | 2<<20 | 2<<24 | 2<<28) ; //设置外部中断4_7下降沿触发
rEINTPEND |= (1<<4|1<<5|1<<6|1<<7); //clear eint 4
rEINTMASK &= ~(1<<4|1<<5|1<<6|1<<7); //enable eint 4
// ClearPending(BIT_EINT4_7);
pISR_EINT4_7=(unsigned)EintHandler; //外部中断4_7中断服务子程序入口地址
EnableIrq(BIT_EINT4_7);
while(1);
}
//====================================================
// 语法格式: void __irq Eint0Handler(void)
// 功能描述: 点亮或者熄灭LED5-8 中断函数
// 入口参数: 无
// 出口参数: 无
//====================================================
void __irq EintHandler(void)
{
if(rINTPND==BIT_EINT4_7)
{
ClearPending(BIT_EINT4_7);
if(rEINTPEND&(1<<4))
{
// Uart_Printf("eint 4\n");
rGPFDAT = LED1ON;
// Delay(500);
rGPFDAT = LEDOFF;
rEINTPEND |= 1<< 4;
}
if(rEINTPEND&(1<<5))
{
// Uart_Printf("eint 5\n");
rGPFDAT = LED2ON;
// Delay(500);
rGPFDAT = LEDOFF;
rEINTPEND |= 1<< 5;
}
if(rEINTPEND&(1<<6))
{
// Uart_Printf("eint 6\n");
rGPFDAT = LED3ON;
// Delay(500);
rGPFDAT = LEDOFF;
rEINTPEND |= 1<< 6;
}
if(rEINTPEND&(1<<7))
{
// Uart_Printf("eint 7\n");
rGPFDAT = LED4ON;
// Delay(500);
rGPFDAT = LEDOFF;
rEINTPEND |= 1<< 7;
}
}
}
//Makefile如下:
objs := init.o
int.bin: $(objs)
arm-linux-ld -Ttext 0x00000000 -o int_elf $^
arm-linux-objcopy -O binary -S int_elf $@
arm-linux-objdump -D -m arm int_elf > int.dis
%.o:%.c
arm-linux-gcc -Wall -O2 -c -o $@ $<
%.o:%.S
arm-linux-gcc -Wall -O2 -c -o $@ $<
clean:
rm -f int.bin int_elf int.dis *.o
//另外有2440的一些通用寄存器的宏定义,这个大侠们应该知道
//在执行"make"时出现如下错误,请问是为什么,前辈能花点帮我修改下程序不,刚学,实在是无奈,看不通,非常感谢 |