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

配置: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,READONLY

	ENTRY  ;//程序入口点
	
	;Configures the pins of port B
	;//设置GPB5~GPB8输出端口
	ldr r0,=rGPBCON
	ldr r1,=0x55<<10
	str 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,=rGPBUP
	ldr r1,=0xffff
	str r1,[r0]
	
	;装载GPB数据寄存器的地址
	ldr r2,=rGPBDAT
	
ledloop

	ldr r1,=~(0x01<<5);//设置GPB5输出灯亮
	
	str r1,[r2];
	
	bl	delay;//调用延时子程序
	
	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 pool

	
	str 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 pool

delay1

	sub 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 即连接寄存器 R14

	END


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值