ARM笔记:外部按键中断程序
扫描二维码
随时随地手机看文章
.externmain
.text
.global_start
_start:
bReset
HandleUndef:
bHandleUndef
HandleSWI:
bHandleSWI
HandlePrefetchAbort:
bHandlePrefetchAbort
HandleDataAbort:
bHandleDataAbort
HandleNotUsed:
bHandleNotUsed
bHandleIRQ
HandleFIQ:
bHandleFIQ
Reset:
ldrsp,=4096
bldisable_watch_dog
msrcpsr_c,#0xd2
ldrsp,=3072
msrcpsr_c,#0xd3
ldrsp,=4096
blinit_led
blinit_irq
msrcpsr_c,#0x5f
ldrlr,=halt_loop
ldrpc,=main
halt_loop:
bhalt_loop
HandleIRQ:
sublr,lr,#4
stmdbsp!,{r0-r12,lr}
ldrlr,=int_return
ldrpc,=EINT_Handle
int_return:
ldmiasp!,{r0-r12,pc}^
#include "s3c2440.h"
#define GPF4_OUT(1<<(4*2))
#defineGPF5_OUT(1<<(5*2))
#define GPF6_OUT(1<<(6*2))
#define GPF4_MSK(3<<(4*2))
#define GPF5_MSK(3<<(5*2))
#define GPF6_MSK(3<<(6*2))
#define GPF0_EINT(0x2<<(0*2))
#define GPF2_EINT(0x2<<(2*2))
#define GPG3_EINT(0x2<<(3*2))
#define GPG11_EINT(0X2<<(11*2))
#define GPF0_MSK(3<<(0*2))
#define GPF2_MSK(3<<(0*2))
#define GPG3_MSK(3<<(3*2))
#define GPG11_MSK(3<<(11*2))
void disable_watch_dog(void)
{
WATCH_DOG=0;//置0,关闭WATCH
}
void init_led(void)
{
GPFCON&=~(GPF4_MSK|GPF5_MSK|GPF6_MSK);
GPFCON|=GPF4_OUT|GPF5_OUT|GPF6_OUT;
}
void init_irq(void)
{
//GPIO设置为中断引脚
GPFCON&=~(GPF0_MSK|GPF2_MSK);
GPFCON|=GPF0_EINT|GPF2_EINT;
GPGCON&=~(GPG3_MSK|GPG11_MSK);
GPGCON|=GPG3_EINT|GPG11_EINT;
//EINT8~23要使能
//使能EINT11,EINTMASK11置0
EINTMASK&=(~(1<<11))&(~(1<<19));
PRIORITY=(PRIORITY&((~0x01)|(0x3<<7))|0x0<<7);
//EINT0 、EINT2、EINT8_23使能
INTMSK&=(~(1<<0))&(~(1<<2))&(~(1<<5));
}
#include "s3c2440.h"
void EINT_Handle(void)
{
unsigned long oft=INTOFFSET;
unsigned long val;
switch(oft)
{
//S2被按下
case 0:
{
GPFDAT|=(0x7<<4);
GPFDAT&=~(1<<4);
break;
}
//S3被按下
case 2:
{
GPFDAT|=(0x7<<4);
GPFDAT&=~(1<<5);
break;
}
//S4被按下
case 5:
{
GPFDAT|=(0x7<<4);//所有LED为0
//寄存器为5即位【5】为1时,EINT8~EINT23中至少有一个中断发生呢个,需进读取EINTPEND寄存器判断
val=EINTPEND;
if(val&(1<<19))
{
GPFDAT|=(0x7<<4);
GPFDAT&=~(1<<6);
}
if(val&(1<<11))
{
GPFDAT|=(0X7<<4);
GPFDAT&=~((1<<4)|(1<<5)|(1<<6));
}
break;
}
default:
break;
}
//清除中断
if(oft==5)
EINTPEND=(1<<11)|(1<<19);
SRCPND=1<
int main()
{
while(1);
return0;
}