1,linux开发环境搭建
2,汇编版程序测试
3, C语言版程序
4 C语言LED轮流亮
5 C语言按键控制LED
下载:easyOpentag驱动安装,打开连接,选择ARM-linux
下载:arm-linux-gcc-3.4.5-glibc-2.3.6.tar.bz2
打开连接,选择ARM-linux
链接:http://pan.baidu.com/s/1pJKK4w7 密码:a0re
我的开发板是JZ2440 4.3寸屏款,
把led_on.bin程序传到Windows平台,
FTD2XX.dll
oflash.exe
led_on.bin 烧录好的程序
放在一起就可以,我放在 D:\ARM 嵌入式Linux\my>
烧录技巧
D:\ARM 嵌入式Linux\my>oflash.exe 0 1 0 0 0 led_on_c.bin
1,环境搭建
我的系统版本 root@ubuntu:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 14.04.3 LTS Release: 14.04 Codename: trusty root@ubuntu:~# 安装 arm-linux-gcc 解压 arm-linux-gcc-3.4.5-glibc-2.3.6.tar.bz2 来自韦东山教学光盘 tar xf arm-linux-gcc-3.4.5-glibc-2.3.6.tar.bz2 环境变量 root@ubuntu:~# export PATH=$PATH:/home/chunli/gcc-3.4.5-glibc-2.3.6/bin/ 一劳永逸: root@ubuntu:~# vim /etc/profile export PATH=$PATH:/home/chunli/gcc-3.4.5-glibc-2.3.6/bin/ 安装 sudo apt-get install lsb-core 否则可能出现No such file or directory root@ubuntu:~/leds# arm-linux-objcopy bash: /home/chunli/gcc-3.4.5-glibc-2.3.6/bin/arm-linux-objcopy: No such file or directory 看看我的系统 编译环境搭建好了 chunli@ubuntu:~$ arm-linux-gcc -v Reading specs from /home/chunli/gcc-3.4.5-glibc-2.3.6/bin/../lib/gcc/arm-linux/3.4.5/specs Configured with: /work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/gcc-3.4.5/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/work/tools/gcc-3.4.5-glibc-2.3.6 --with-float=soft --with-headers=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include --with-local-prefix=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long Thread model: posix gcc version 3.4.5 chunli@ubuntu:~$
编写一个点亮LED的程序:
写一个点亮JZ2440开发板的一个汇编小程序
JZ2440开发板:
从JZ2440v2_sch.pdf中可以看出
nLED_2 上拉到3.3V
nLED_2 另一脚是接在GPF5 这个IO功能引脚上
查S3C2440官方手册
GPFCON 的地址是 0x56000050 ,此寄存器的值设为 0x00000400 配置GPF5这个引脚为输出
GPFDAT 的地址是 0x56000054 控制GPF5输出低电平
chunli@ubuntu:~/hardware$ mkdir my
chunli@ubuntu:~/hardware$ cd my/
chunli@ubuntu:~/hardware/my$ vim led_on.S
chunli@ubuntu:~/mytest$ cat led_on.S
@******************************************************************************
@ File:led_on.S
@ 功能:LED点灯程序,点亮LED1
@******************************************************************************
.text
.global _start
_start:
LDR R0,=0x56000050 @ R0设为GPFCON寄存器。此寄存器用于选择各引脚的功能:是输出、是输入、还是其他
MOV R1,#0x00001500 @ 设置 GPF4,GPF5,GPF6为输出引脚,每两位确定一种功能
STR R1,[R0] @ 把0x00001500装入地址为0x56000050的寄存器中
LDR R0,=0x56000054 @ R0设为GPFDAT寄存器。此寄存器用于读/写引脚的数据
MOV R1,#0x0000005F @ 此值改为0x0000002F, 可让LED4 LED6 发光,0x5F就只亮LED5
STR R1,[R0] @ 把0x0000002F装入地址为0x56000054的寄存器中
MAIN_LOOP:
B MAIN_LOOP
编写Makefile文件
chunli@ubuntu:~/hardware/my$ vim Makefile
led_on.bin : led_on.S
arm-linux-gcc -g -c -o led_on.o led_on.S
arm-linux-ld -Ttext 0x0000000 -g led_on.o -o led_on_elf
arm-linux-objcopy -O binary -S led_on_elf led_on.bin
clean:
rm -f led_on.bin led_on_elf *.o
注意:从本文网页复制过去的Makefile代码不能正常执行,需要将每条编译命令前面改成tab制表符其中一段代码arm-linux-ld -Ttext 0x0000000 意思是代码段的地址是0000000
编译
chunli@ubuntu:~/hardware/my$ make
arm-linux-gcc -g -c -o led_on.o led_on.S
arm-linux-ld -Ttext 0x0000000 -g led_on.o -o led_on_elf
arm-linux-objcopy -O binary -S led_on_elf led_on.bin
没有报错
chunli@ubuntu:~/hardware/my$ echo $?
0
chunli@ubuntu:~/hardware/my$ ll
-rwxrwxr-x 1 chunli chunli 36 Apr 12 22:20 led_on.bin*
-rwxrwxr-x 1 chunli chunli 34144 Apr 12 22:20 led_on_elf*
-rw-rw-r-- 1 chunli chunli 1412 Apr 12 22:20 led_on.o
-rw-rw-r-- 1 chunli chunli 1035 Apr 12 22:19 led_on.S
-rw-rw-r-- 1 chunli chunli 218 Apr 12 22:20 Makefile
把led_on.bin程序传到Windows平台,
FTD2XX.dll
oflash.exe
led_on.bin
放在一起就可以
运行oflash.exe小程序,
D:\ARM 嵌入式Linux\my>oflash.exe
+---------------------------------------------------------+
| Flash Programmer v1.3 for OpenJTAG of www.100ask.net |
| OpenJTAG is a USB to JTAG & RS232 tool based FT2232 |
| This programmer supports both of S3C24X0 & S3C6410 |
| Author: Email/MSN(thisway.diy@163.com), QQ(17653039) |
+---------------------------------------------------------+
Usage:
1. oflash, run with cfg.txt or prompt
2. oflash [file], write [file] to flash with prompt
3. oflash [-f config_file]
4. oflash [jtag_type] [cpu_type] [flash_type] [read_or_write] [offset] [file]
Can't open cfg.txt, you should follow the prompt
Select the JTAG type:
0. OpenJTAG
1. Dongle JTAG(parallel port)
2. Wiggler JTAG(parallel port)
Enter the number: 0
Select the CPU:
0. S3C2410
1. S3C2440
2. S3C6410
Enter the number: 1
device: 4 "2232C"
deviceID: 0x14575118
SerialNumber: FTSht3gzA
Description: USB<=>JTAG&RS232 AS3C2440 detected, cpuID = 0x0032409d
[Main Menu]
0:Nand Flash prog 1:Nor Flash prog 2:Memory Rd/Wr 3:Exit
Select the function to test:0
Enter the file name: led_on.bin
[NAND Flash JTAG Programmer]
Scan nand flash:
Device 0: NAND 256MiB 3,3V 8-bit, sector size 128 KiB
Total size: 256 MiB
0:Nand Flash Program 1:Nand Flash Print BlkPage 2:Exit
Select the function to test :0
[NAND Flash Writing Program]
Source size: 0x24
Available target block number: 0~2047
Input target block number:0
target start block number =0
target size (0x20000*1) =0x20000
STATUS:
Ep
D:\ARM 嵌入式Linux\my>
等5秒,开发板的小灯亮起
3 C语言版:点亮LED
int a;
int * p;
p = &a;
* p = 0x100;
* p = (int *) 0x56000050;
*((int *) 0x56000050) = 0x100;
*(( volatile int *) 0x56000050) = 0x100;
相当于把 * p = 0x100
转换为 *(( volatile int *) 0x56000050) = 0x100; // 往 0x56000050寄存器地址写入0x100
#defin GPFCON (*(volatile unsigned long *) 0x56000050)
然后 GPFCON = 0x100;
D:\ARM 嵌入式Linux\my>oflash.exe 0 1 0 0 0 led_on.bin
源代码
chunli@ubuntu:~/my02$ ll
total 12
-rw-rw-r-- 1 chunli chunli 817 Apr 13 01:02 crt0.S
-rw-rw-r-- 1 chunli chunli 279 Apr 13 01:29 led_on_c.c
-rw-rw-r-- 1 chunli chunli 361 Apr 13 01:03 Makefile
chunli@ubuntu:~/my02$ cat crt0.S
@******************************************************************************
@ File:crt0.S
@ 功能:通过它转入C程序
@******************************************************************************
.text
.global _start
_start:
ldr r0, =0x56000010 @ WATCHDOG寄存器地址
mov r1, #0x0
str r1, [r0] @ 写入0,禁止WATCHDOG,否则CPU会不断重启
ldr sp, =1024*4 @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
@ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
bl main @ 调用C程序中的main函数
halt_loop:
b halt_loop
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$ cat led_on_c.c
#define GPBCON (*(volatile unsigned long *)0x56000050)
#define GPBDAT (*(volatile unsigned long *)0x56000054)
int main()
{
GPBCON = 0x00000100; // 设置GPF4为输出口, 位[11:10]=0b01
GPBDAT = 0x00000000; // GPB5输出0,LED1点亮
return 0;
}
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$ cat Makefile
led_on_c.bin : crt0.S led_on_c.c
arm-linux-gcc -g -c -o crt0.o crt0.S
arm-linux-gcc -g -c -o led_on_c.o led_on_c.c
arm-linux-ld -Ttext 0x0000000 -g crt0.o led_on_c.o -o led_on_c_elf
arm-linux-objcopy -O binary -S led_on_c_elf led_on_c.bin
arm-linux-objdump -D -m arm led_on_c_elf > led_on_c.dis
clean:
rm -f led_on_c.dis led_on_c.bin led_on_c_elf *.o
chunli@ubuntu:~/my02$
查看反汇编:
chunli@ubuntu:~/my02$ cat led_on_c.dis
led_on_c_elf: file format elf32-littlearm
Disassembly of section .text:
00000000 <_start>:
0: e59f0010 ldr r0, [pc, #16] ; 18 <.text+0x18>
4: e3a01000 mov r1, #0 ; 0x0
8: e5801000 str r1, [r0]
c: e3a0da01 mov sp, #4096 ; 0x1000
10: eb000001 bl 1c <main>
00000014 <halt_loop>:
14: eafffffe b 14 <halt_loop>
18: 56000010 undefined
0000001c <main>:
1c: e1a0c00d mov ip, sp
20: e92dd800 stmdb sp!, {fp, ip, lr, pc}
24: e24cb004 sub fp, ip, #4 ; 0x4
28: e3a03456 mov r3, #1442840576 ; 0x56000000
2c: e2833050 add r3, r3, #80 ; 0x50
30: e3a02c01 mov r2, #256 ; 0x100
34: e5832000 str r2, [r3]
38: e3a03456 mov r3, #1442840576 ; 0x56000000
3c: e2833054 add r3, r3, #84 ; 0x54
40: e3a02000 mov r2, #0 ; 0x0
44: e5832000 str r2, [r3]
48: e3a03000 mov r3, #0 ; 0x0
4c: e1a00003 mov r0, r3
50: e89da800 ldmia sp, {fp, sp, pc}
Disassembly of section .comment:
00000000 <.comment>:
0: 43434700 cmpmi r3, #0 ; 0x0
4: 4728203a undefined
8: 2029554e eorcs r5, r9, lr, asr #10
c: 2e342e33 mrccs 14, 1, r2, cr4, cr3, {1}
10: Address 0x10 is out of bounds.
Disassembly of section .debug_aranges:
00000000 <.debug_aranges>:
0: 0000001c andeq r0, r0, ip, lsl r0
4: 00000002 andeq r0, r0, r2
8: 00040000 andeq r0, r4, r0
...
14: 0000001c andeq r0, r0, ip, lsl r0
...
20: 0000001c andeq r0, r0, ip, lsl r0
24: 003f0002 eoreqs r0, pc, r2
28: 00040000 andeq r0, r4, r0
2c: 00000000 andeq r0, r0, r0
30: 0000001c andeq r0, r0, ip, lsl r0
34: 00000038 andeq r0, r0, r8, lsr r0
...
Disassembly of section .debug_pubnames:
00000000 <.debug_pubnames>:
0: 00000017 andeq r0, r0, r7, lsl r0
4: 003f0002 eoreqs r0, pc, r2
8: 00610000 rsbeq r0, r1, r0
c: 00420000 subeq r0, r2, r0
10: 616d0000 cmnvs sp, r0
14: 00006e69 andeq r6, r0, r9, ror #28
18: Address 0x18 is out of bounds.
Disassembly of section .debug_info:
00000000 <.debug_info>:
0: 0000003b andeq r0, r0, fp, lsr r0
4: 00000002 andeq r0, r0, r2
8: 01040000 tsteq r4, r0
...
14: 0000001c andeq r0, r0, ip, lsl r0
18: 30747263 rsbccs r7, r4, r3, ror #4
1c: 2f00532e swics 0x0000532e
20: 656d6f68 strvsb r6, [sp, #-3944]!
24: 7568632f strvcb r6, [r8, #-815]!
28: 2f696c6e swics 0x00696c6e
2c: 3230796d eorccs r7, r0, #1785856 ; 0x1b4000
30: 554e4700 strplb r4, [lr, #-1792]
34: 20534120 subcss r4, r3, r0, lsr #2
38: 35312e32 ldrcc r2, [r1, #-3634]!
3c: 5d800100 stfpls f0, [r0]
40: 02000000 andeq r0, r0, #0 ; 0x0
44: 00001400 andeq r1, r0, r0, lsl #8
48: 36010400 strcc r0, [r1], -r0, lsl #8
4c: 54000000 strpl r0, [r0]
50: 1c000000 stcne 0, cr0, [r0], {0}
54: 47000000 strmi r0, [r0, -r0]
58: 4320554e teqmi r0, #327155712 ; 0x13800000
5c: 342e3320 strcct r3, [lr], #-800
60: 0100352e tsteq r0, lr, lsr #10
64: 5f64656c swipl 0x0064656c
68: 635f6e6f cmpvs pc, #1776 ; 0x6f0
6c: 2f00632e swics 0x0000632e
70: 656d6f68 strvsb r6, [sp, #-3944]!
74: 7568632f strvcb r6, [r8, #-815]!
78: 2f696c6e swics 0x00696c6e
7c: 3230796d eorccs r7, r0, #1785856 ; 0x1b4000
80: 6d010200 sfmvs f0, 4, [r1]
84: 006e6961 rsbeq r6, lr, r1, ror #18
88: 00590501 subeqs r0, r9, r1, lsl #10
8c: 001c0000 andeqs r0, ip, r0
90: 00540000 subeqs r0, r4, r0
94: 5b010000 blpl 4009c <__bss_end__+0x38048>
98: 746e6903 strvcbt r6, [lr], #-2307
9c: 00050400 andeq r0, r5, r0, lsl #8
Disassembly of section .debug_abbrev:
00000000 <.debug_abbrev>:
0: 10001101 andne r1, r0, r1, lsl #2
4: 12011106 andne r1, r1, #-2147483647 ; 0x80000001
8: 1b080301 blne 200c14 <__bss_end__+0x1f8bc0>
c: 13082508 tstne r8, #33554432 ; 0x2000000
10: 00000005 andeq r0, r0, r5
14: 10011101 andne r1, r1, r1, lsl #2
18: 11011206 tstne r1, r6, lsl #4
1c: 13082501 tstne r8, #4194304 ; 0x400000
20: 1b08030b blne 200c54 <__bss_end__+0x1f8c00>
24: 02000008 andeq r0, r0, #8 ; 0x8
28: 0c3f002e ldceq 0, cr0, [pc], #-184
2c: 0b3a0803 bleq e82040 <__bss_end__+0xe79fec>
30: 13490b3b cmpne r9, #60416 ; 0xec00
34: 01120111 tsteq r2, r1, lsl r1
38: 00000a40 andeq r0, r0, r0, asr #20
3c: 03002403 tsteq r0, #50331648 ; 0x3000000
40: 3e0b0b08 fmacdcc d0, d11, d8
44: 0000000b andeq r0, r0, fp
Disassembly of section .debug_line:
00000000 <.debug_line>:
0: 00000032 andeq r0, r0, r2, lsr r0
4: 001a0002 andeqs r0, sl, r2
8: 01020000 tsteq r2, r0
c: 000a0efb streqd r0, [sl], -fp
10: 01010101 tsteq r1, r1, lsl #2
14: 01000000 tsteq r0, r0
18: 74726300 ldrvcbt r6, [r2], #-768
1c: 00532e30 subeqs r2, r3, r0, lsr lr
20: 00000000 andeq r0, r0, r0
24: 00020500 andeq r0, r2, r0, lsl #10
28: 17000000 strne r0, [r0, -r0]
2c: 2d2d2c2c stccs 12, cr2, [sp, #-176]!
30: 0004022d andeq r0, r4, sp, lsr #4
34: 00350101 eoreqs r0, r5, r1, lsl #2
38: 00020000 andeq r0, r2, r0
3c: 0000001e andeq r0, r0, lr, lsl r0
40: 0efb0102 cdpeq 1, 15, cr0, cr11, cr2, {0}
44: 0101000a tsteq r1, sl
48: 00000101 andeq r0, r0, r1, lsl #2
4c: 6c000100 stfvss f0, [r0], {0}
50: 6f5f6465 swivs 0x005f6465
54: 2e635f6e cdpcs 15, 6, cr5, cr3, cr14, {3}
58: 00000063 andeq r0, r0, r3, rrx
5c: 05000000 streq r0, [r0]
60: 00001c02 andeq r1, r0, r2, lsl #24
64: 80641300 rsbhi r1, r4, r0, lsl #6
68: 04022c81 streq r2, [r2], #-3201
6c: Address 0x6c is out of bounds.
Disassembly of section .debug_frame:
00000000 <.debug_frame>:
0: 0000000c andeq r0, r0, ip
4: ffffffff swinv 0x00ffffff
8: 7c010001 stcvc 0, cr0, [r1], {1}
c: 000d0c0e andeq r0, sp, lr, lsl #24
10: 0000001c andeq r0, r0, ip, lsl r0
14: 00000000 andeq r0, r0, r0
18: 0000001c andeq r0, r0, ip, lsl r0
1c: 00000038 andeq r0, r0, r8, lsr r0
20: 440c0d44 strmi r0, [ip], #-3396
24: 038d028e orreq r0, sp, #-536870904 ; 0xe0000008
28: 0c44048b cfstrdeq mvd0, [r4], {139}
2c: 0000040b andeq r0, r0, fp, lsl #8
chunli@ubuntu:~/my02$
效果图
4 LED 轮流闪烁:
chunli@ubuntu:~/my02$ cat crt0.S
@******************************************************************************
@ File:crt0.S
@ 功能:通过它转入C程序
@******************************************************************************
.text
.global _start
_start:
ldr r0, =0x56000010 @ WATCHDOG寄存器地址
mov r1, #0x0
str r1, [r0] @ 写入0,禁止WATCHDOG,否则CPU会不断重启
ldr sp, =1024*4 @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
@ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
bl main @ 调用C程序中的main函数
halt_loop:
b halt_loop
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$ cat led_on_c.c
#define GPFCON (*(volatile unsigned long *)0x56000050)
#define GPFDAT (*(volatile unsigned long *)0x56000054)
#define GPF4_out (1<<(4*2))
#define GPF5_out (1<<(5*2))
#define GPF6_out (1<<(6*2))
#define GPF7_out (1<<(7*2))
void wait(volatile unsigned long dly)
{
for(; dly > 0; dly--);
}
int main(void)
{
unsigned long i = 0;
GPFCON = GPF4_out|GPF5_out|GPF6_out; // 将LED1-3对应的GPF4/5/6三个引脚设为输出
while(1){
wait(30000);
GPFDAT = (~(i<<4)); // 根据i的值,点亮LED1-3
if(++i == 8)
i = 0;
}
return 0;
}
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$ cat Makefile
led_on_c.bin : crt0.S led_on_c.c
arm-linux-gcc -g -c -o crt0.o crt0.S
arm-linux-gcc -g -c -o led_on_c.o led_on_c.c
arm-linux-ld -Ttext 0x0000000 -g crt0.o led_on_c.o -o led_on_c_elf
arm-linux-objcopy -O binary -S led_on_c_elf led_on_c.bin
arm-linux-objdump -D -m arm led_on_c_elf > led_on_c.dis
clean:
rm -f led_on_c.dis led_on_c.bin led_on_c_elf *.o
chunli@ubuntu:~/my02$
C语言,按键控制LED
chunli@ubuntu:~/my02$ cat crt0.S
@******************************************************************************
@ File:crt0.S
@ 功能:通过它转入C程序
@******************************************************************************
.text
.global _start
_start:
ldr r0, =0x56000010 @ WATCHDOG寄存器地址
mov r1, #0x0
str r1, [r0] @ 写入0,禁止WATCHDOG,否则CPU会不断重启
ldr sp, =1024*4 @ 设置堆栈,注意:不能大于4k, 因为现在可用的内存只有4K
@ nand flash中的代码在复位后会移到内部ram中,此ram只有4K
bl main @ 调用C程序中的main函数
halt_loop:
b halt_loop
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$ cat led_on_c.c
#define GPFCON (*(volatile unsigned long *)0x56000050)
#define GPFDAT (*(volatile unsigned long *)0x56000054)
#define GPGCON (*(volatile unsigned long *)0x56000060)
#define GPGDAT (*(volatile unsigned long *)0x56000064)
/*
* LED1-4对应GPF4、GPF5、GPF6
*/
#define GPF4_out (1<<(4*2)) // 5,4 位 变0,1
#define GPF5_out (1<<(5*2)) // 7,6 位 变0,1
#define GPF6_out (1<<(6*2)) // 9,8 位 变0,1
/*
* K1-K4对应GPG11、GPG3、GPF2、GPF0
*/
#define GPG3_in 3<<(3*2) // 7,6 位 变1,1
#define GPF2_in 3<<(2*2) // 5,4 位 变1,1
#define GPF0_in 3<<(0*2) // 1,0 位 变1,1
int main()
{
unsigned long dwDat;
// GPF4,GPF5,GPF6,接的3个LED 对应的3根引脚设为输出
GPFCON &= ~(GPF4_out | GPF5_out | GPF6_out) ; //清零对应的3个引脚的配置位,不要影响其他位
GPFCON |= (GPF4_out | GPF5_out | GPF6_out) ; //对这3个引脚配置为01输出,不要影响其他位
// GPG3 对应的按键引脚设为输入
GPGCON &= ~( GPG3_in) ;
GPGCON |= ( GPG3_in) ;
// GPF0,GPF2,对应的2个按键引脚设为输入
GPFCON &= ~( GPF2_in | GPF0_in) ;
GPFCON |= ( GPF2_in | GPF0_in) ;
while(1){
//若Kn为0(表示按下),则令LEDn为0(表示点亮)
dwDat = GPGDAT; // 读取GPG管脚电平状态
if (dwDat & (1<<3)) // GPG3 为按键
GPFDAT |= (1<<6); // 控制GPF6的亮灭,1灭
else
GPFDAT &= ~(1<<6); // GPF6 0 亮
dwDat = GPFDAT; // 读取GPF管脚电平状态
if (dwDat & (1<<2)) // GPF2 为按键
GPFDAT |= (1<<4); // 控制GPF4的亮灭,1灭
else
GPFDAT &= ~(1<<4); //GPF4 0 亮
if (dwDat & (1<<0)) // GPF0 为按键
GPFDAT |= (1<<5); // 控制GPF5的亮灭,1灭
else
GPFDAT &= ~(1<<5); // GPF5 0 亮
}
return 0;
}
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$
chunli@ubuntu:~/my02$ cat Makefile
led_on_c.bin : crt0.S led_on_c.c
arm-linux-gcc -g -c -o crt0.o crt0.S
arm-linux-gcc -g -c -o led_on_c.o led_on_c.c
arm-linux-ld -Ttext 0x0000000 -g crt0.o led_on_c.o -o led_on_c_elf
arm-linux-objcopy -O binary -S led_on_c_elf led_on_c.bin
arm-linux-objdump -D -m arm led_on_c_elf > led_on_c.dis
clean:
rm -f led_on_c.dis led_on_c.bin led_on_c_elf *.o
chunli@ubuntu:~/my02$
按下这旁边的三个按键,对应的三个led就会亮起
转载于:https://blog.51cto.com/990487026/1763228