key.c
1#include"key.h"
2#include"uart.h"
3#include"s3c2410.h"
17
__irq
void
key_handler()
18
{
19
sendstring(
"key1 down!!!n"
);
20
21
EINTPEND |=
0x1
<<
19
;
22
SRCPND |=
0x1
<<
5
;
23
INTPND = INTPND;
24
}
25
26void
key_init()
27
{
28
INTMOD =
0x0
;
29
INTMSK &= ~(
0x1
<<
5);
31
GPECON = (GPECON & ~(
0x3
<<
22
)) |
0x1
<<
22
;
32
GPEDAT &= ~(
0x1
<<
11);
34
GPGCON = (GPGCON & ~(
0x3
<<
22
)) |
0x2
<<
22;
36
EXTINT2 = (EXTINT2 & ~(
0x7
<<
12
)) |
0x2
<<
12;
38
EINTMASK &= ~(
0x1
<<
19);
40
*(
unsigned
int
*)(
0x33ffff20
+
5
*
4
) = (
unsigned
int
)key_handler;
41
}
注意__irq 修士的key_handler 就是二级中断处理函数,这里没有查二级中断号,也没有做消除抖动处理,所以不完善,只是为了演示中断过程,用串口向pc发送了一个字符串。注意处理完成后要清除中断,否则会一直中断。还要注意中断的返回,__irq是armcc的关键字,gcc是不能用的,使用它以后,调试时看对应的汇编代码:
STMDB R13!,{R0-R3,R12,R14} ...
LDMIA R13!,{R0-R3,R12,R14}
SUBS PC,R14,#0x00000004 可知自动做了pc指针的调整,适应流水线机构。
key_init函数中的这一句
*(unsigned int *)(0x33ffff20+5*4) = (unsigned int)key_handler;
正是把二级中断处理函数的地址安装到中断向量表中。中断控制的寄存器包括pnd, mask等,专门讲中断的文章中有讲到,芯片资料说明也很详细。
main.c
1 #include "key.h"
2 #include "led.h"
3 #include "uart.h"
4 #include "s3c2410.h"
5
6
7
8 int main(void)
9 {
10 key_init();
11 uart_init();
12 sendstring("hello world!n");
13 myblink();
14 return 0;
15 }
相关文章









