用汇编点亮一个led
1 看原理图 GPK4=0 ,led亮 GPK4=1,led灭
2 怎么让GPK4输出高低电平 (看芯片手册,操作寄存器实现)
配置功能:输入/输出/其他
设置其输出高/低电平
3 查看芯片手册
GPK4 [19:16]
0000 = Input 0001 = Output
0010 = Host I/F DATA[4] 0011 = HSI TX READY
0100 = Reserved 0101 = DATA_CF[4]
0110 = Reserved 0111 = Reserved
GPKDAT 在第4位写写0 就对应GPK4
GPK[15:0] [15:0]
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.
Register Address R/W Description Reset Value
GPKCON0 0x7F008800 R/W Port K Configuration Register 0 0x22222222
GPKCON1 0x7F008804 R/W Port K Configuration Register 1 0x22222222
GPKDAT 0x7F008808 R/W Port K Data Register Undefined
GPKPUD 0x7F00880C R/W Port K Pull-up/down Register 0x55555555
Register Address R/W Description Reset Value
WTCON 0x7E004000 R/W Watchdog timer control register 0x8021
示例代码如下:
start.S文件
..globl _start
_start:
/*硬件的相关设置:把外设的基地址告诉cpu*/
ldr r0, =0x70000000
orr r0,r0,#0x13
mcr p15,0,r0,c15,c2,4
/*关闭看门狗*/
ldr r0,=0x7E004000
mov r1,#0
str r1,[r0]
/*设置GPKCON GPK4作为输出引脚*/
ldr r1, =0x7F008800
mov r0,#0x10000000
str r0,[r1]
/*设置GPKDAT让GPK4输出0*/
ldr r1, =0x7F008808
mov r0,#0
str r0,[r1]
halt:
b halt
Makefile文件
led.bin: start.o
arm-linux-ld -Ttext 0 -o led.elf start.o
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led.dis
start.o : start.S
arm-linux-gcc -o start.o start.S -c
clean:
rm *.o led.elf led.bin led.dis
编译 make
将led_on.bin烧写到nand flash中,如同烧写linux类似,将led_on.bin放到images目录下
修改friendlyARM.ini
Action=install
OS=UserBin
UserBin-Image=led_on.bin
点亮四个led灯,示例代码如下:
start.S文件
.globl _start
_start:
/*硬件相关设置*/
ldr r0,=0x70000000
orr r0,r0,#0x13
mcr p15,0,r0,c15,c2,4
/*关闭看门狗*/
ldr r0,=0x7e004000
mov r1,#0
str r1,[r0]
/*设置GPKCON GPK4/5/6/7作为输出*/
ldr r1,=0x7F008800
ldr r0,=0x11110000
str r0,[r1]
/*设置GPKDAT让GPK4输出0*/
ldr r1,=0x7F0088080
mov r0,#0
loop:
str r0,[r1]
add r0,r0,#1
cmp r0,#16
moveq r0,#0
bl delay
b loop
delay:
mov r2,#0x10000000
delay_loop:
sub r2,r2,#1
cmp r2,#0
bne delay_loop
mov pc,lr
halt:
b halt
Makefile文件同上
用c语言来实现点灯
1 硬件相关设置
2 调用c函数
示例代码如下:
void delay(){
volatile int i=0x10000000;
while (i--);
}
int main(){
int i=0;
volatile unsigned long *gpkcon = (volatile unsigned long *)0x7F008800;
volatile unsigned long *gpkdat = (volatile unsigned long *)0x7F008808;
*gpkcon=0x11110000;
while(1){
*gpkdat=i;
i++;
if(i==16)
i=0;
delay();
}
return 0;
}
.globl _start
_start:
/*硬件相关设置*/
ldr r0,=0x70000000
orr r0,r0,#0x13
mcr p15,0,r0,c15,c2,4
/*关看门狗*/
ldr r0,=0x7E004000
mov r1,#0
str r1,[r0]
/*设置栈*/
ldr sp,=8*1024
bl main
Halt:
B halt
led.bin: start.o led.o
arm-linux-ld -Ttext 0 -o led.elf start.o led.o
arm-linux-objcopy -O binary led.elf led.bin
arm-linux-objdump -D led.elf > led.dis
start.o : start.S
arm-linux-gcc -o start.o start.S -c
led.o:led.c
arm-linux-gcc -o led.o led.c -c
clean:
rm *.o led.elf led.bin led.dis