S3C2440之裸机之C语言按键点亮LED灯

虚拟机环境:Oracle VM VirtualBox
Linux系统:ubuntu_14.04.6
交叉编译工具:[100ask分享的所有文件](https://eyun.baidu.com/s/3b1UtLc)
100ask分享的所有文件 > 002_JZ2440资料光盘_20180516(免费) > 资料光盘 > A盘 > tools.zip > arm-linux-gcc-4.3.2.tar.bz2
gcc-3.4.5-glibc-2.3.6/bin

第一步:查看原理图
在这里插入图片描述
在这里插入图片描述

left middle right
nLED4 nLED2 nLED1
GPF6 GPF5 GPF4

输出低电平点亮LED灯
输出高电平熄灭LED灯

S3C2440之裸机之C语言按键点亮LED灯_第1张图片

left middle right
EINT0 EINT2 EINT11
GPF0 GPF2 GPG3

抬起为高电平
按下为低电平

第二步:查看芯片手册
在这里插入图片描述
相应引脚配置为输出
输出低电平

第三步:编写程序
crt0.S:

.text
.global _start

_start:
	ldr r0,=0x53000000
	mov r1,#0x0
	str r1,[r0]

	ldr sp,=1024*4
	bl main

halt_loop:
	b halt_loop

key_led.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)

/*
nLED1   GPF4
nLED2   GPF5
nLED4   GPF6

EINT0   GPF0
EINT2   GPF2
EINT11  GPG3
EINT19  GPG11
*/

int main(void)
{
	unsigned long dwDat;

	GPFCON = 0x00001500;
	GPGCON = 0x00000000;

	while (1) {
		dwDat = GPFDAT;

		if (dwDat & (1<<0))
			GPFDAT |= (1<<6);
		else
			GPFDAT &= ~(1<<6);

		if (dwDat & (1<<2))
			GPFDAT |= (1<<5);
		else
			GPFDAT &= ~(1<<5);

		dwDat = GPGDAT;

		if (dwDat & (1<<3))
			GPFDAT |= (1<<4);
		else
			GPFDAT &= ~(1<<4);

		if (dwDat & (1<<11))
			GPFDAT |= (1<<4) | (1<<5) | (1<<6);
		else
			GPFDAT &=~((1<<4) | (1<<5) | (1<<6));
	}

	return 0;
}

第四步:编写makefile
makefile:

ARM_LINUX_XXX=/home/xlbtlmy/Desktop/ARM_Linux/gcc-3.4.5-glibc-2.3.6/bin

CC=$(ARM_LINUX_XXX)/arm-linux-gcc
LD=$(ARM_LINUX_XXX)/arm-linux-ld
OBJCOPY=$(ARM_LINUX_XXX)/arm-linux-objcopy
OBJDUMP=$(ARM_LINUX_XXX)/arm-linux-objdump
TARGET=$(OPT)

src_c=$(shell ls *.c)
objs_c=$(patsubst %.c,%.o,$(src_c))

src_s=$(shell ls *.S)
objs_s=$(patsubst %.S,%.o,$(src_s))

objs=$(objs_c) $(objs_s)

BIN=$(TARGET).bin
ELF=$(TARGET).elf
DIS=$(TARGET).dis

$(BIN):$(objs)
	$(LD) -Ttext 0x00000000 crt0.o key_led.o -o $(ELF)
	$(OBJCOPY) -O binary -S $(ELF) $(BIN)
	$(OBJDUMP) -D -m arm $(ELF) > $(DIS)

%.o:%.c
	$(CC) -c -o $@ $<

%.o:%.S
	$(CC) -c -o $@ $<

.PHONY:clean
clean:
	rm -f *.o *.bin *.elf *.dis

make OPT=key_led

第五步:烧录运行
eop.bat:

@echo off

:JTAG(0:OpenJTAG 1:DongleJTAG 2:Wiggler)
SET JTAG=0
:CPU(0:S3C2410 1:S3C2440 2:S3C6410)
SET CPU=1
:Flash(0:Nand 1:Nor)
SET Flash=0
:Access(0:Write 1:Read)
SET Access=0
:Offset()
SET Offset=0
:File()
SET File=key_led.bin

oflash %JTAG% %CPU% %Flash% %Access% %Offset% %File%

pause

注意问题:

1.编写makefile时,要注意链接时,要将crt0.o放在key_led.o前面,否则现象异常

第五步:观察实验现象
按对应位置的按键,对应位置的LED亮

你可能感兴趣的:(S3C2440)