循环点灯
- RCC寄存器使能GPIOE、GPIOF组寄存器
- 修改GPIOx组寄存器下的值
- 通过GPIOx_MODER寄存器设置为输出模式
- 通过GPIOx_OTYOER寄存器设置为推挽输出类型
- 通过GPIOx_OSPEEDR寄存器设置为低速输出
- 通过GPIOx_PUPDR寄存器设置为禁止上下拉电阻
- 点灯 通过GPIOx_ODR寄存器设置为高电平
- 灭灯 通过GPIOx_ODR寄存器设置为低电平
.text
.global _start
_start:
/**********LED1点灯**************/
@用RCC寄存器使能GPIOE、GPIOF寄存器
RCC_INIT:
@使能GPIOE组控制器
ldr r0,=0x50000A28
ldr r1,[r0]
orr r1,r1,#(0x1<<4)
str r1,[r0]
@使能GPIOF组控制器
ldr r0,=0x50000A28
ldr r1,[r0]
orr r1,r1,#(0x1<<5)
str r1,[r0]
LED1_INIT:
@修改GPIOE_MODER寄存器
ldr r2,=0x50006000
ldr r3,[r2]
bic r3,r3,#(0x1<<21)
orr r3,r3,#(0x1<<20)
str r3,[r2]
ldr r2,=0x50007000
ldr r3,[r2]
bic r3,r3,#(0x1<<21)
orr r3,r3,#(0x1<<20)
str r3,[r2]
ldr r2,=0x50006000
ldr r3,[r2]
bic r3,r3,#(0x1<<17)
orr r3,r3,#(0x1<<16)
str r3,[r2]
@修改GPIOE_OTYPER寄存器
ldr r4,=0x50006004
ldr r5,[r4]
bic r5,r5,#(0x1<<10)
str r5,[r4]
ldr r4,=0x50007004
ldr r5,[r4]
bic r5,r5,#(0x1<<10)
str r5,[r4]
ldr r4,=0x50006004
ldr r5,[r4]
bic r5,r5,#(0x1<<8)
str r5,[r4]
@修改GPIOE_OSPEEDR寄存器
ldr r6,=0x50006008
ldr r7,[r6]
bic r7,r7,#(0x1<<21)
bic r7,r7,#(0x1<<20)
str r7,[r6]
ldr r6,=0x50007008
ldr r7,[r6]
bic r7,r7,#(0x1<<21)
bic r7,r7,#(0x1<<20)
str r7,[r6]
ldr r6,=0x50006008
ldr r7,[r6]
bic r7,r7,#(0x1<<17)
bic r7,r7,#(0x1<<16)
str r7,[r6]
@修改GPIOE_PUPDR寄存器
ldr r8,=0x5000600C
ldr r9,[r8]
bic r9,r9,#(0x1<<21)
bic r9,r9,#(0x1<<20)
str r9,[r8]
ldr r8,=0x5000700C
ldr r9,[r8]
bic r9,r9,#(0x1<<21)
bic r9,r9,#(0x1<<20)
str r9,[r8]
ldr r8,=0x5000600C
ldr r9,[r8]
bic r9,r9,#(0x1<<17)
bic r9,r9,#(0x1<<16)
str r9,[r8]
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:
ldr r10,=0x50006014
ldr r11,[r10]
orr r11,r11,#(0x1<<10)
str r11,[r10]
mov pc,lr
LED2_ON:
ldr r10,=0x50007014
ldr r11,[r10]
orr r11,r11,#(0x1<<10)
str r11,[r10]
mov pc,lr
LED3_ON:
ldr r10,=0x50006014
ldr r11,[r10]
orr r11,r11,#(0x1<<8)
str r11,[r10]
mov pc,lr
@ 大概1s的延时函数
delay_1s:
mov r3, #0x10000000
mm:
cmp r3, #0
subne r3, r3, #1
bne mm
mov pc,lr
LED1_OFF:
ldr r10,=0x50006014
ldr r11,[r10]
bic r11,r11,#(0x1<<10)
str r11,[r10]
mov pc,lr
LED2_OFF:
ldr r10,=0x50007014
ldr r11,[r10]
bic r11,r11,#(0x1<<10)
str r11,[r10]
mov pc,lr
LED3_OFF:
ldr r10,=0x50006014
ldr r11,[r10]
bic r11,r11,#(0x1<<8)
str r11,[r10]
mov pc,lr
.end
效果图
思维导图