汇编语言实现led灯的跑马灯

led实验
1.看原理图
看设备工作的原理(可能需要阅读芯片手册),看设备与cpu的连接关系

GPIO具有输入输出功能。
输入:cpu想知道io引脚是高电平还是低电平那么就是输入方式
输出:cpu想控制io引脚为高电平还是低电平那么就是输出方式
跟电流的方向没有任何关系


2. cpu的相关章节
GPJ2CON control是配置这个引脚是什么功能
GPJ2有8个引脚,每个引脚由con寄存器中的4个位进行配置

GPJ2DAT 如果cpu要输出高电平或者低电平,就需要设置该寄存器,只有8位有效
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.
当配置为输入模式的时候,dat寄存器中的某一位的值由引脚设置,引脚是高电平是,对应的位为1,引脚为低电平时,对应的位为0
当配置为输出模式的时候,dat寄存器中的某一位控制引脚的电平,对应的位为1时,对应的引脚输出高电平,对应的位为0时,对应的引脚输出为低电平
其他功能模式时,读到的值是未定义的。

@gec210 light first led
.globl _start
_start:
ldr r0,=0xe0200280
mov r1,#1<<4
str r1,[r0] @config pin0 output mode

mov r1,#0
str r1,[r0,#4] @output low level

b . @same as while(1);


arm-linux-gcc -c led.S -o led.o //编译不链接
arm-linux-ld -Ttext 0x30008000 led.o -o led.elf //链接指定代码段起始位置
arm-linux-objcopy -O binary led.elf led.bin //生成二进制执行文件
arm-linux-objdump -D led.elf > led.dis //生成反汇编代码


uboot的几个常用命令
printenv 打印显示环境变量

ipaddr=192.168.1.4 //开发板的ip
serverip=192.168.1.2 //tftp服务器的ip

设置为各自的ip,只是设置到内存,掉电就没有
setenv ipaddr 192.168.1.x
setenv serverip 192.168.1.x

saveenv //保存到flash中,再次启动后为刚刚设置的值

ping //单向的,只能从开发板ping电脑
alive表示网络是通的,not alive表示网络不通


tftp 30008000 led.bin //下载二进制文件到内存0x30008000地址
go 30008000 //跳转到0x30008000运行程序


@gec210 light first led
.globl _start
_start:
ldr r0,=0xe0200280
ldr r1,=(1<<0 | 1<<4 | 1<<8 | 1<<12)
str r1,[r0] @config pin0-pin3 output mode

mov r1,#0
str r1,[r0,#4] @output low level

b . @same as while(1);

简单的makefile
APP=led

$(APP).bin:$(APP).o
arm-linux-ld -Ttext 0x30008000 $^ -o $(APP).elf
arm-linux-objcopy -O binary $(APP).elf $@
arm-linux-objdump -D $(APP).elf > $(APP).dis
cp $@ /home/gec/tftp/

%.o:%.s
arm-linux-gcc $^ -c -o $@

%.o:%.S
arm-linux-gcc $^ -c -o $@

%.o:%.c
arm-linux-gcc $^ -c -o $@


clean:
@rm -f $(APP).bin $(APP).elf $(APP).dis *.o

四个灯同时点亮或者同时熄灭
循环闪烁
@gec210 light first led
.globl _start
_start:
ldr r0,=0xe0200280
ldr r1,=(1<<0 | 1<<4 | 1<<8 | 1<<12)
str r1,[r0] @config pin0-pin3 output mode

loop:
mov r1,#0
str r1,[r0,#4] @output low level

bl delay

mov r1,#0xf
str r1,[r0,#4]

bl delay

b loop

b . @same as while(1);


delay:
mov r4,#0xff00000
delay1:
subs r4,r4,#1
bne delay1
mov pc,lr

#define GPJ2CON (unsigned long *)0xe0200280

unsigned long *p = (unsigned long *)0xe0200280;
p


练习:
第1个灯到第4个灯依次点亮,第4个灯到第1个灯依次熄灭,循环。

.globl _start
_start:
ldr r0,=0xe0200280
ldr r1,=0x1111
str r1,[r0] @config pin0 output mode

loop:
mov r1,#0xe
str r1,[r0,#4]
bl delay

mov r1,#0xc
str r1,[r0,#4]
bl delay

mov r1,#0x8
str r1,[r0,#4]
bl delay

mov r1,#0
str r1,[r0,#4]
bl delay

mov r1,#0x8
str r1,[r0,#4]
bl delay

mov r1,#0xc
str r1,[r0,#4]
bl delay

mov r1,#0xe
str r1,[r0,#4]
bl delay

mov r1,#0xf
str r1,[r0,#4]
bl delay

b loop

b . @same as while(1);

delay:
mov r4,#0xff00000
delay1:
subs r4,r4,#1
bne delay1
mov pc,lr

原文地址:https://www.cnblogs.com/liudehao/p/6075575.html