关闭

外部中断(按键1)

标签: key
441人阅读 评论(0) 收藏 举报
分类:

外部中断学习:

*******************************************************************

------------------------

cpsr第七位

------------------------

状态   VICxIRQSTATUS  VICxIRQSTATUS  /***内部中断控制管理器***/

选择 VICxINTSELECT

使能 VICxINTENABLE

记录 VICxRAWINTR

------------------------

中断源

------------------------

   Register    Address /*外部中断 028

EINT0CON0    0x7F008900

EINT0CON1    0x7F008904 配置

EINT0MASK    0x7F008920 开关

EINT0PEND 记录

------------------------

 

通过按键来触发外部中断的过程:

step1:set cpsr

step2:set:vic0

step3:eint0

step4:gpio

step5:interrupt source

 

注:内部中断在,中断源处清中断;外部中断在,外部中断管理器里清中断

****************************************************************************************

test.c:按一下按键,打印一句话。


#include ".h"

void hander_irq();
int (*printf)(char *,...) = (void *)0x57e11d4c;
int tmp=0;
int count=0;
void led_on();
int main()
{
*(volatile unsigned long *)0x56000000 = hander_irq;//将这个函数的地址放在0x56000000这个内存中。
//cpsr开中断
__asm__ __volatile__(
"mrs r0,cpsr\n"
"bic r0,r0,#0x80\n"
"msr cpsr,r0\n"
:
:
:"r0","memory"
);
//enable
VIC0INTENABLE |=(1<<0);
//select

VIC0INTSELECT &=~(1<<0);


//key 配成中断
GPNCON = 2; 
//ext_interrupt下降沿
EINT0CON0 |= (1<<1);
EINT0MASK &= ~(1<<0);
//EINT0PEND |= (1<<0);
}
void hander_irq()
{
EINT0PEND |= (1<<0);
printf("this key interrupt\n");

}

***************************************************************************

key.h:

//interrupt
#define VIC0INTENABLE (*(volatile unsigned long *)0x71200010)
#define VIC0INTSELECT (*(volatile unsigned long *)0x7120000C)
//模拟
#define VIC0SOFTINT (*(volatile unsigned long *)0x71200018)
#define VIC0SOFTINTCLAR (*(volatile unsigned long *)0x7120001C)
//watdog
#define WTCON    (*(volatile unsigned long *)0x7E004000) 
#define WTDAT    (*(volatile unsigned long *)0x7E004004) 
#define WTCNT    (*(volatile unsigned long *)0x7E004008) 
#define WTCLRINT (*(volatile unsigned long *)0x7E00400C)
//led
#define GPMCON (*(volatile unsigned long *)0x7F008820)
#define GPMDAT (*(volatile unsigned long *)0x7F008824)
//key
#define GPNCON (*(volatile unsigned long *)0x7F008830)
#define GPNDAT (*(volatile unsigned long *)0x7F008834)
//ex_interrupt
#define EINT0CON0    (*(volatile unsigned long *)0x7F008900)
#define EINT0CON1    (*(volatile unsigned long *)0x7F008904)
#define EINT0MASK     (*(volatile unsigned long *)0x7F008920)
#define EINT0PEND    (*(volatile unsigned long *)0x7F008924)

*****************************************************************************

vector.s文件:
b reset
b und
b swi
b pre_abt
b data_abt
.word 0x0
b irq
b firq
reset:
und:
mov sp,#0x56000000
mov ip,sp
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

ldr r0,=string_und
ldr r1,printf
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
swi:
mov sp,#0x56000000
mov ip,sp
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

ldr r0,=string_swi
ldr r1,printf
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
pre_abt:
data_abt:
mov sp,#0x56000000
mov ip,sp
sub lr,lr,#4
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

ldr r0,=string_pre_abt
ldr r1,printf
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
irq:
mov sp,#0x56000000
mov ip,sp
sub lr,lr,#4
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

mov r0,#0x56000000
ldr r1,[r0]
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
firq:
printf:
.word 0x57e11d4c
string_und:
.asciz "hello undefine \n"
.align 2
string_swi:
.asciz "hello swi\n"
.align 2
string_pre_abt:
.asciz "hell data_abt\n"
.align 2
string_irq:
.asciz "hello irq ,wang wang wang  \n"
.align 2
********************************************************************

makefiel文件:

all:
arm-none-linux-gnueabi-gcc -c vector.s -o vector.o
arm-none-linux-gnueabi-ld -Ttext=0 vector.o -o vector
arm-none-linux-gnueabi-objcopy -Ielf32-littlearm -O binary vector vector.bin
cp vector.bin /tftpboot/
arm-none-linux-gnueabi-gcc -c test.c -o test.o
arm-none-linux-gnueabi-ld -Ttext=0x50000000 test.o -o test
arm-none-linux-gnueabi-objcopy -Ielf32-littlearm -O binary test test.bin
cp test.bin /tftpboot/
clean:
rm -rf *.o *.bin   /tftpboot/*.bin


0
0
猜你在找
【套餐】Hadoop生态系统零基础入门
【套餐】嵌入式Linux C编程基础
【套餐】2017软考系统集成项目——任铄
【套餐】Android 5.x顶级视频课程——李宁
【套餐】深度学习入门视频课程——唐宇迪
【直播】广义线性模型及其应用——李科
【直播】从0到1 区块链的概念到实践
【直播】计算机视觉原理及实战——屈教授
【直播】机器学习之凸优化——马博士
【直播】机器学习&数据挖掘7周实训--韦玮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:122054次
    • 积分:4221
    • 等级:
    • 排名:第7176名
    • 原创:302篇
    • 转载:50篇
    • 译文:2篇
    • 评论:7条
    最新评论