1、实现1+2+3------+100
AREA test02,CODE,READONLY
start
MOV R0,#0
MOV R1,#1
MOV R2,#1
LOOP
ADD R2,R2,R0
ADD R1,R1,#1
CMP R1,#101
BEQ label
ADD R2,R2,R1
B LOOP
label
NOP
NOP
NOP
END
2、汇编LED测试
/************************************
*注意修改段名为testLED(两处修改)
*在MDK中,要添加簇文件RuninRAM.sct
*在MDK中,要添加初始化文件Ext_RAM.ini
**************************************/
AREA testLED,CODE,READWRITE
ENTRY
rGPBCON EQU 0x56000010
rGPBDAT EQU 0x56000014
rGPBUP EQU 0x56000018
start
ldr r0, =rGPBCON
ldr r1, [r0]
bic r1,r1,#(0xff<<10)
orr r1,r1,#0x01
orr r1,r1,#(0x55<<10)
str r1,[r0]
ldr r0, =rGPBUP
mov r1, #0xff
str r1,[r0]
LED_LOOP
ldr r0, =rGPBDAT
mov r1, #0xE0
str r1, [r0]
mov r2, #0x120000
delay1
sub r2, r2, #1
cmp r2, #0
bne delay1
ldr r0, =rGPBDAT
mov r1, #0x00
str r0, [r0]
mov r2, #0x120000
delay2
sub r2, r2, #1
cmp r2,#0
bne delay2
b LED_LOOP
end
3、C语言LED测试
/*******************************************************
*在MDK中需要修改段名(RESET)
*在MDK中S3C2440A.S初始化文件已存在
*在MDK中需要添加簇文件RuninRAM.sct
******************************************************/
#define rGPBCON (*(volatile unsigned *)0x56000010)
#define rGPBDAT (*(volatile unsigned *)0x56000014)
#define rGPBUP (*(volatile unsigned *)0x56000018)
void msdelay(int time)
{
volatile unsigned int i,j;
for(i=0;i<2000;i++)
for(j=0;j
一、编写源代码
源代码:
/*******************************led_off.S**************************/
.text
.global _start
_start:
LDR R0,=0x56000010
MOV R1,#0x00015400
STR R1,[R0]
LDR R0,=0x56000014
MOV R1,#0x0df
STR R1,[R0]
MAIN_LOOP:
B MAIN_LOOP
/*******************************Makefile****************************/
*指定链接文件地址
*指定链接文件顺序
*********************************************************************/
led_off.bin : led_off.S
arm-linux-gcc -g -c -o led_off.o led_off.S
arm-linux-ld -Ttext 0x0000000 -g led_off.o -o led_off_elf
arm-linux-objcopy -O binary -S led_off_elf led_off.bin
clean:
rm -f led_off.bin led_off_elf *.o
/*******************************************************************/
二、使用Jlink下载led_off.bin到nand flash(参考烧写Uboot方法)
5.1 打开 J-Link Commander,输入-r
5.2 speed 12000
5.3 J-Link Commonder 输入loadbin f:init.bin 0
5.4 setpc 0
5.5 g
5.5 h
5.6 J-Link Commonder 输入loadbin f:u-boot.bin_openjtag 0x33f80000
5.7 setpc 0x33f80000
5.8 g
5.9 h
5.10 J-Link Commonder 输入loadbin f:u-boot.bin 0x30000000
******************************************************************************************
J-Link Commonder 输入loadbin f:led_off.bin 0x30000000,即可以烧写汇编程序
******************************************************************************************
5.11 g
5.12 h
5.13 在secretcat 中输入nand scrub
5.14 y
5.15 在secretcat 中输入nand erase 0 0x40000
5.16 在secretcat 中输入nand write.jffs2 30000000 0 0x40000
5.17 重新启动进入nand flash
三、开发板重启即可。
一、编写源程序(init.S、testledC.lds、testledC.c、Makefile)
@******************************************************************************
@ File:init.S
@ 功能:通过它转入C程序
@******************************************************************************
.text
.global _start
_start:
ldr r0, =0x53000000 @ 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
/***********************************
*功能:链接文件TestledC.lds
*************************************/
SECTIONS {
. = 0x00;
.text : { *(.text) }
.rodata ALIGN(4) : {*(.rodata)}
.data ALIGN(4) : { *(.data) }
.bss ALIGN(4) : { *(.bss) *(COMMON) }
}
SECTIONS {
. = 0x00;
.text : { *(.text) }
.rodata ALIGN(4) : {*(.rodata)}
.data ALIGN(4) : { *(.data) }
.bss ALIGN(4) : { *(.bss) *(COMMON) }
}
/**************************************
*编写testledC.c源程序
*************************************/
/*************************************************
* File: testledC.c
* funtion:stream light
* author:zhaochuang
* data: 2013.5.8
* vision 1.0
**************************************************/
#define rGPBCON (*(volatile unsigned *)0x56000010)
#define rGPBDAT (*(volatile unsigned *)0x56000014)
#define rGPBUP (*(volatile unsigned *)0x56000018)
void msdelay(int time)
{
volatile unsigned int i,j;
for(i=0;i<2000;i++)
for(j=0;j
int main()
{
rGPBCON &= ~((3<<10)|(3<<12)|(3<<14)|(3<<16));
rGPBCON |= (1<<10)|(1<<12)|(1<<14)|(1<<16);
rGPBDAT = rGPBDAT|(LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF);
while (1)
{
rGPBDAT = rGPBDAT&(LED1_ON);
dely(100);
rGPBDAT = rGPBDAT|(LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF);
dely(100);
rGPBDAT = rGPBDAT&(LED2_ON);
dely(100);
rGPBDAT = rGPBDAT|(LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF);
dely(100);
rGPBDAT = rGPBDAT&(LED3_ON);
dely(100);
rGPBDAT = rGPBDAT|(LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF);
dely(100);
rGPBDAT = rGPBDAT&(LED4_ON);
dely(100);
rGPBDAT = rGPBDAT|(LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF);
dely(100);
}
}
***********************************************************************/
/*********************************************************************************
*Makefile编写规则
***********************************************************************************/
CFLAGS := -Wall -O2
testledC.bin : init.S testledC.c
arm-linux-gcc $(CFLAGS) -c -o init.o init.S
arm-linux-gcc $(CFLAGS) -c -o testledC.o testledC.c
arm-linux-ld -TtestledC.lds init.o testledC.o -o testledC_elf
arm-linux-objcopy -O binary -S testledC_elf testledC.bin
arm-linux-objdump -D -m arm testledC_elf > testledC.dis
clean:
rm -f testledC.bin testledC_elf testledC.dis *.o