LED程序


汇编语言

led.s
.text
.global _start
 
_start:
 
	LDR	R1, = 0xE0200280	@ 取 GPJ2CON 的地址
	LDR	R0, = 0x00001111 
	STR 	R0, [R1]		@ 设置 GPJ2CON 的模式为 output
 
	LDR	R1, = 0xE0200284	@ 取 GPJ2DAT 的地址
	MOV	R0, #0x00
	STR 	R0, [R1]  		@ 灯亮
 
stop:
	B 	stop
makefile
led: led.s
	arm-linux-gcc -c -o led.o led.s
	arm-linux-ld -Ttext 0x20000000 led.o -o led.elf
	arm-linux-objcopy -O binary -S led.elf led.bin
 
clean:
	rm -f *.o *.elf *.bin

命令行执行 make 指令即可完成编译和链接成可执行的二进制文件。


C语言

led.c
#include<stdio.h>
 
#define GPJ2CON_0 (*(volatile unsigned *)0xE0200280)
#define GPJ2DAT_0 (*(volatile unsigned *)0xE0200284)
 
int main(int argc, char const *argv[])
{
	GPJ2CON_0 |= 0x00001111;
	GPJ2DAT_0 = 0X00;
	return 0;
}

蜂鸣器程序


汇编语言

buzzer.s
.text
.global _start
 
_start:
 
	LDR	R1, = 0xE02000A0	@ 取 GPD0CON 的地址
	LDR	R0, = 0x01 
	STR 	R0, [R1]		@ 设置 GPD0CON 的模式为 output
 
	LDR	R1, = 0xE02000A4	@ 取 GPD0DAT 的地址
	MOV	R0, #0x1
	STR 	R0, [R1]  		@ 蜂鸣器响
 
stop:
	B 	stop
makefile
buzzer: buzzer.s
	arm-linux-gcc -c -o buzzer.o buzzer.s
	arm-linux-ld -Ttext 0x20000000 buzzer.o -o buzzer.elf
	arm-linux-objcopy -O binary -S buzzer.elf buzzer.bin
 
clean:
	rm -f *.o *.elf *.bin

命令行执行 make 指令即可完成编译和链接成可执行的二进制文件。


C语言

buzzer.c
#include<stdio.h>
 
#define GPD0CON (*(volatile signed *)0xE02000A0)
#define GPD0DAT (*(volatile signed *)0xE02000A4)
 
int main(int argc, char const *argv[])
{
	GPD0CON |= (0x1<<0); // GPD0CON |= 0x01
	GPD0DAT = 0x1;
	return 0;
}