.extern main
.text
.global _start
_start:
b Reset
HandleUndef:
b HandleUndef
HandleSWI:
b HandleSWI
HandlePrefetchAbort:
b HandlePrefetchAbort
HandleDataAbort:
b HandleDataAbort
HandleNotUsed:
b HandleNotUsed
b HandleIRQ
HandleFIQ:
b HandleFIQ
Reset:
ldr sp,=4096
bl disable_watch_dog
msr cpsr_c,#0xd2
ldr sp,=3072
msr cpsr_c,#0xd3
ldr sp,=4096
bl init_led
bl init_irq
msr cpsr_c,#0x5f
ldr lr,=halt_loop
ldr pc,=main
halt_loop:
b halt_loop
HandleIRQ:
sub lr,lr,#4
stmdb sp!,{r0-r12,lr}
ldr lr,=int_return
ldr pc,=EINT_Handle
int_return:
ldmia sp!,{r0-r12,pc}^
#include "s3c2440.h"
#define GPF4_OUT (1<<(4*2))
#define GPF5_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);
return 0;
}
上一篇:ARM笔记:外部中断
下一篇:ARM笔记: GPIO口LED程序
推荐阅读最新更新时间:2024-03-16 15:45