ARM--day4(电灯实验、分析RCC、GPIO控制器,PMOS管、NMOS管的基本原理)

电灯实验代码:

.text 
.global _start
_start: 
	/**********LED1点灯**************/

RCC_INIT:
	@1.使能GPIOE组控制器,通过RCC_AHB4ENSETR寄存器设置第[5:4]位写1---->0x50000A28[4]=1
	ldr r0,=0x50000A28
	ldr r1,[r0]
	orr r1,#(0x3 << 4) @使能GPIOE和GPIOF组
	str r1,[r0]

LED1_INIT:
	@1.设署PE10引脚为输出模式,通过CPTOE MODR寄在器设詈第[21:20]位写01 ==>0x50006000[21:20]= 01
	ldr r0,=0x50006000
	ldr r1,[r0]
	bic r1,#(0x3<<20)
	orr r1,#(0x1<<20)   
	str r1,[r0]
	@2.设置GPIO引脚为推挽输出类型,通过GPIOE_OTYPER寄存器设置第[10]位写О--->0x50006004[10]=0
	ldr r0,=0x50006004
	ldr r1,[r0]
	bic r1,#(0x1<<10) 
	str r1,[r0]
	@3.设置PE10引脚为低速输出,通过GPIOE_OSPEEDRE寄存器第[21:20]位写00--->0x50006008[21:20]=00
	ldr r0,=0x50006008
	ldr r1,[r0]
	bic r1,#(0x3<<20)
	str r1,[r0]
	@4.设置PE10引脚禁止上下拉电阻,通过cPIOE_PUPDR寄存器设置第[21:20]位写00--->0x5000600c[21:20]=00
	ldr r0,=0x5000600c
	ldr r1,[r0]
	bic r1,#(0x3<<20)
	str r1,[r0]

LED2_INIT:
	@1.设署PF10引脚为输出模式,通过CPTOF MODR寄在器设詈第[21:201位写01 ==>0x50007000[21:20]= 01
	ldr r0,=0x50007000
	ldr r1,[r0]
	bic r1,#(0x3<<20)
	orr r1,#(0x1<<20)   
	str r1,[r0]
	@2.设置PF10引脚为推挽输出类型,通过GPIOF_OTYPER寄存器设置第[10]位写О--->0x50007004[10]=0
	ldr r0,=0x50007004
	ldr r1,[r0]
	bic r1,#(0x1<<10) 
	str r1,[r0]
	@3.设置PF10引脚为低速输出,通过GPIOF_OSPEEDRE寄存器第[21:20]位写00--->0x50007008[21:20]=00
	ldr r0,=0x50007008
	ldr r1,[r0]
	bic r1,#(0x3<<20)
	str r1,[r0]
	@4.设置PF10引脚禁止上下拉电阻,通GPIOF_PUPDR寄存器设置第[21:20]位写00--->0x5000700c[21:20]=00
	ldr r0,=0x5000700c
	ldr r1,[r0]
	bic r1,#(0x3<<20)
	str r1,[r0]

LED3_INIT:
	@1.设署PE8引脚为输出模式,通过GPTOE MODR寄在器设詈第[17:16]位写01 ==>0x50006000[21:20]= 01
	ldr r0,=0x50006000
	ldr r1,[r0]
	bic r1,#(0x3<<16)
	orr r1,#(0x1<<16)   
	str r1,[r0]
	@2.设置GPIO引脚为推挽输出类型,通过GPIOE_OTYPER寄存器设置第[10]位写О--->0x50006004[8]=0
	ldr r0,=0x50006004
	ldr r1,[r0]
	bic r1,#(0x1<<8) 
	str r1,[r0]
	@3.设置PE8引脚为低速输出,通过GPIOE_OSPEEDRE寄存器第[17:16]位写00--->0x50006008[17:16]=00
	ldr r0,=0x50006008
	ldr r1,[r0]
	bic r1,#(0x3<<16)
	str r1,[r0]
	@4.设置PE8引脚禁止上下拉电阻,通过GPIOE_PUPDR寄存器设置第[17:16]位写00--->0x5000600c[17:16]=00
	ldr r0,=0x5000600c
	ldr r1,[r0]
	bic r1,#(0x3<<16)
	str r1,[r0]

loop:
	bl LED1_ON
	bl delay_1s
	bl LED1_OFF
	bl delay_1s

	bl LED2_ON
	bl delay_1s
	bl LED2_OFF
	bl delay_1s

	bl LED3_ON
	bl delay_1s
	bl LED3_OFF
	bl delay_1s

	b loop

LED1_ON:
	@1.设置PE10引脚输出高电平,通过GPIoE_ODR寄存器设置第〔10]位写1--->	0x50006014[10]=1
	ldr r0,=0x50006014
	ldr r1,[r0]
	orr r1,#(0x1<<10)
	str r1,[r0]
	mov pc,lr
LED1_OFF:
	@1.设置PE10引脚输出低电平--->	0x50006014[10]=0
	ldr r0,=0x50006014
	ldr r1,[r0]
	bic r1,#(0x1<<10)
	str r1,[r0]
	mov pc,lr
LED2_ON:
	@1.设置PE10引脚输出高电平,通过GPIoE_ODR寄存器设置第〔10]位写1--->	0x50006014[10]=1
	ldr r0,=0x50007014
	ldr r1,[r0]
	orr r1,#(0x1<<10)
	str r1,[r0]
	mov pc,lr
LED2_OFF:
	@1.设置PE10引脚输出低电平--->	0x50006014[10]=0
	ldr r0,=0x50007014
	ldr r1,[r0]
	bic r1,#(0x1<<10)
	str r1,[r0]
	mov pc,lr
LED3_ON:
	@1.设置PF10引脚输出高电平,通过GPIOF_ODR寄存器设置第〔10]位写1--->	0x50006014[10]=1
	ldr r0,=0x50006014
	ldr r1,[r0]
	orr r1,#(0x1<<8)
	str r1,[r0]
	mov pc,lr
LED3_OFF:
	@1.设置PE8引脚输出低电平--->	0x50006014[8]=0
	ldr r0,=0x50006014
	ldr r1,[r0]
	bic r1,#(0x1<<8)
	str r1,[r0]
	mov pc,lr
 

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

.end

 

你可能感兴趣的:(arm开发,单片机,stm32)