汇编实现LED1/LED2/LED3三盏灯点亮,一亮一灭过程

汇编代码实现:


.text 
.global _start
_start: 
	/**********LED1点灯LED1----->PE10/
LED1_INIT:
	/**************RCC章节*************/
	@1.通过RCC_MP_AHB4ENSETR寄存器设置GPIOE时钟使能 0x50000A28[4] = 1
	ldr r0,=0x50000A28
	ldr r1,[r0]
	orr r1,r1,#(0x1 << 4)
	orr r1,r1,#(0x1 << 5)
	str r1,[r0]

	/**************GPIO章节************/
	@1.通过GPIOE_MODER寄存器设置PE10引脚为输出模式 0x50006000[21:20] = 01
	ldr r0,=0x50006000
	ldr r2,=0x50007000
	ldr r1,[r0]
	ldr r3,[r2]
	orr r1,r1,#(0x1 << 20)
	and r1,r1,#(~(0x1 << 21))
	orr r3,r3,#(0x1 << 20)
	and r3,r3,#(~(0x1 << 21))
	orr r1,r1,#(0x1 << 16)
	and r1,r1,#(~(0x1 << 17))
	str r1,[r0]
	str r3,[r2]
	@2.通过GPIOE_OTYPER寄存器设置PE10引脚为推晚输出模式 0x50006004[10] = 0
	ldr r0,=0x50006004
	ldr r2,=0x50007004
	ldr r1,[r0]
	ldr r3,[r2]
	and r1,r1,#(~(0x1 << 8))
	and r1,r1,#(~(0x1 << 10))
	and r3,r3,#(~(0x1 << 10))
	str r1,[r0]
	str r3,[r2]
	@3.通过GPIOE_OSPEEDR寄存器设置PE10引脚为低速输出模式 0x50006008[21:20] = 00
	ldr r0,=0x50006008
	ldr r2,=0x50007008
	ldr r1,[r0]
	ldr r3,[r2]
	and r1,r1,#(~(0x3 << 16))
	and r1,r1,#(~(0x3 << 20))
	and r3,r3,#(~(0x3 << 20))
	str r1,[r0]
	str r3,[r2]
	@4.通过GPIOE_PUPDR寄存器设置PE10引脚禁止上下拉电阻 0x5000600C[21:20] = 00
	ldr r0,=0x5000600c
	ldr r2,=0x5000700c
	ldr r1,[r0]
	ldr r3,[r2]
	and r1,r1,#(0x3 << 16)
	and r1,r1,#(0x3 << 20)
	and r3,r3,#(0x3 << 20)
	str r1,[r0]
	str r3,[r2]

LED1_ON:
	@1.通过GPIOE_ODR寄存器设置PE10引脚输出高电平 0x50006014[10] = 1
	ldr r0,=0x50006014
	ldr r2,=0x50007014
	ldr r1,[r0]
	ldr r3,[r2]
	orr r1,r1,#(0x1 << 8)
	orr r1,r1,#(0x1 << 10)
	orr r3,r3,#(0x1 << 10)
	str r1,[r0]
	str r3,[r2]
	bl delay_1s
LED1_OFF:
	@1.通过GPIOE_ODR寄存器设置PE10引脚输出低电平 0x50006014[10] = 0
	ldr r0,=0x50006014
	ldr r2,=0x50007014
	ldr r1,[r0]
	ldr r3,[r2]
	and r1,r1,#(~(0x1 << 8))
	and r1,r1,#(~(0x1 << 10))
	and r3,r3,#(~(0x1 << 10))
	str r1,[r0]
	str r3,[r2]
	bl delay_1s
	b LED1_ON


@ 大概1s的延时函数
delay_1s:
	mov r3, #0x10000000
	mm:
	cmp r3, #0
	subne r3, r3, #1
	bne mm
	mov pc, lr

.end


汇编实现LED1/LED2/LED3三盏灯点亮,一亮一灭过程_第1张图片

你可能感兴趣的:(代码作业,单片机,嵌入式硬件)