key_printf(小结8-5)

来源:互联网 发布:贵阳块数据公司 编辑:程序博客网 时间:2024/05/04 07:03

概要:

我们用一种论循的方式,检查按键按下的时候,我们就打印:hello my_key


下面是按健的三个寄存器:

Register     Address        R/W     Description
GPNCON  0x7F008830   R/W    Port N Configuration Register
GPNDAT   0x7F008834   R/W    Port N Data Register
GPNPUD   0x7F008838  R/W    Port N Pull-up/down Register


1.

      配制GPNCON的低两位为1;

s3c6410中的第一个按键所对应的GPNCON中的低两位:

00 = Input

01 = Output 

10 = Ext. Interrupt[0]

11 = Key pad ROW[0] 


2.

GPNDAT用来检测按键的输入:0为有按下,1为没有动静。

When the port is configured as input port, the corresponding bit is the pin state.

When the port is configured as output port, the pin state is the same as the

corresponding bit. When the port is configured as functional pin, the undefined

value will be read.




汇编如下:

#key,when key down  ===>pritnf

.section .text   //程序代码段

.global main

main:

mov ip,sp

stmdb sp!,{fp,ip,lr}

sub fp,ip,#4


           #*0x7f008830 &= ~0x3

ldr r1,=0x7F008830   //设置GPNCON

ldr r2,[r1]

mvn r3,#0x3      

add r2,r3,r2

str r2,[r1]

 

key_detection:

 //检测GPNDAT

      ldr r2,=0x7F008834

ldr r3,[r2]

ldr r1,=0xfffd

bic r3,r3,r1   //判断是否最低一位为0(按下)

cmp r3,#0

bne key_detection  //如果没有按下,就一直在这里检测。

   

key_down_printf:

ldr r0,=string    //在arm中我们默认为把对一个函数的调用需要的参数放在r0~r3

ldr r3,=string1  //取string1的地址,string1中的内容为0x57e11d4c

ldr r2,[r3] 

blx r2  //调用u-boot里面的打印函数

nop

b key_detection //跳回去,成为一个论循,有点笨着。

sub sp,fp,#8

ldmia sp,{fp,sp,pc}

.section .data

string:

.asciz "hello my_key\n"

.align 2

string1:

.word 0x57e11d4c