S3C2440流水灯(汇编语言+RealView-MDK4.12)

来源:互联网 发布:windows 安装linux 编辑:程序博客网 时间:2024/04/29 05:14

配置:GPB5~GPB8 连接4个led 低电平点亮,RAM1起始地址为0x30000000

启动代码S3C2440.s(由RealView-MDK自动生成)

用户程序Main.s:

rGPBCON   EQU    0x56000010;//定义端口  rGPBDAT   EQU    0x56000014;rGPBUP    EQU    0x56000018;;导出符号__main;连接到启动代码EXPORT __main;__main函数 相应于C语言的main()函数AREA __main,CODE,READONLYENTRY  ;//程序入口点;Configures the pins of port B;//设置GPB5~GPB8输出端口ldr r0,=rGPBCONldr r1,=0x55<<10str r1,[r0];GPBUP :Pull-up disable register for port B;0: The pull up function attached to the corresponding port pin is enabled.;1: The pull up function is disabled.;//设置GPBUP为禁止设置为上拉电阻ldr r0,=rGPBUPldr r1,=0xffffstr r1,[r0];装载GPB数据寄存器的地址ldr r2,=rGPBDATledloopldr r1,=~(0x01<<5);//设置GPB5输出灯亮str r1,[r2];bldelay;//调用延时子程序ldr r1,=~(0x03<<5);//设置GPB5GPB6输出低电平,灯亮str r1,[r2];bl delay;ldr r1,=~(0x07<<5);//设置GPB5~7输出灯亮str r1,[r2];bl delay;ldr r1,=~(0x0f<<5);//设置GPB5~8输出灯亮str r1,[r2];bl delay;ldr r1,=~(0x00<<5);//设置全灭;The LDR Rd,=const pseudo-instruction can construct any 32-bit numeric constant in a single instruction;generates an LDR instruction with a program-relative address that reads the constant from the literal poolstr r1,[r2];STR{cond} Rd, [Rn];Rn is used as address value. ;STR{cond} Rd, [Rn, offset];Rn and offset are added and used as address value.;STR{cond} Rd, [Rn, offset]!;Rn and offset are added and used as address value. The new address value is written to Rn.;STR{cond} Rd, label;The assembler calculates the PC offset and generates STR{cond} Rd, [R15], offset.;STR{cond} Rd, [Rn], offset ;Rn is used as address value. After memory transfer, the offset is added to Rn.;Store register 32-bit words to Memory. The address must be 32-bit word-aligned.bl delay;;BL{cond} label;Copy address of next instruction to R14 and jump to label. The jump distance must be within ±4Mb of the current instruction. ;Note that this mnemonic is generated as two 16-bit Thumb instructions. b ledloop;B{cond} label;The jump distance must be within -252 to +258 bytes for conditional and ±2 KBytes for unconditional branch. ;不影响标志位delay;延时子函数ldr r3,=0x10000;The LDR Rd,=const pseudo-instruction can construct any 32-bit numeric constant in a single instruction;generates an LDR instruction with a program-relative address that reads the constant from the literal pooldelay1sub r3,r3,#1              cmp r3,#0x0;CMP {cond} Rn, Op2;subtracts the value of Op2 from the value in Rn (equals to the SUBS instruction with a discarded result).;This instruction updates the condition flags, but do not place a result in a register.;N, Z, C and V flags are updated.bne delay1;B{cond} label;The jump distance must be within -252 to +258 bytes for conditional and ±2 KBytes for unconditional branch. ;不影响标志位BX LR;mov pc,lr;//返回主程序;LR 即连接寄存器 R14END

原创粉丝点击