ARM入门笔记——按键
嵌入式硬件平台:TQ2440开发软件:gcc + gdb + vim
软件环境:VM + ubuntu + SecureCRT + dnw
按下按键 点亮对应的led 带松手检测 四个led分别接在 GPB5 GPB6 GPB7 GPB8四个按键接在 GPF0 GPF2 GPF4 GPF1
代码基本上和上一篇“点灯”很像 http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=5191993&bbs_id=1032
启动代码:
.text
.global _start
_start:
ldr r0, =0x53000000
mov r1, #0x0
str r1,
ldr sp, =4*1024
bl main
halt_loop:
b halt_loop
makefile:
CFLAG :=-Wall -O2
obj :=start.o key.o
key.bin : $(obj)
arm-linux-ld -Ttext 0x00000000 $^ -o key_elf
arm-linux-objcopy -O binary -S key_elf key.bin
arm-linux-objdump -D -m arm key_elf > key.dis
%.o : %.s
arm-linux-gcc $(CFLAG) -c $< -o $@
%.o : %.c
arm-linux-gcc $(CFLAG) -c $< -o $@
.PHONY : clean
clean:
rm -rf key.dis key_elf key.bin *.o
key.c
#include "2440addr.h"
#define GPB5_out (1 << (2*5))
#define GPB6_out (1 << (2*6))
#define GPB7_out (1 << (2*7))
#define GPB8_out (1 << (2*8))
#define GPF0_in (0 << (2*0))
#define GPF2_in (0 << (2*2))
#define GPF4_in (0 << (2*4))
#define GPF1_in (0 << (2*1))
#define Led1_on GPBDAT &= ~(1 << 5)
#define Led2_on GPBDAT &= ~(1 << 6)
#define Led3_on GPBDAT &= ~(1 << 7)
#define Led4_on GPBDAT &= ~(1 << 8)
#define Led1_off GPBDAT |= (1 << 5)
#define Led2_off GPBDAT |= (1 << 6)
#define Led3_off GPBDAT |= (1 << 7)
#define Led4_off GPBDAT |= (1 << 8)
#define key1 GPFDAT & (1<<0)
#define key2 GPFDAT & (1<<2)
#define key3 GPFDAT & (1<<4)
#define key4 GPFDAT & (1<<1)
int main(void)
{
GPFCON &= ~(GPF0_in|GPF2_in|GPF4_in|GPF1_in);
GPBCON |= GPB5_out|GPB6_out|GPB7_out|GPB8_out;
//GPBDAT |= (1 << 5)|(1 << 6)|(1 << 7)|(1 << 8);
while(1)
{
while(~key1)
Led1_on;
Led1_off;
while(~key2)
Led2_on;
Led2_off;
while(~key3)
Led3_on;
Led3_off;
while(~key4)
Led4_on;
Led4_off;
}
}
点击此处下载 ourdev_694276V7H3B0.zip(文件大小:8K) (原文件名:key.zip) make 后生成的文件如下
http://cache.amobbs.com/bbs_upload782111/files_47/ourdev_694288XZ0WRX.jpg
(原文件名:生成文件.jpg)
其中key.dis是反汇编文件 顶顶
页:
[1]