汇编实现三个灯循环点亮
.text
.global _start
_start:
/**********LED1点灯**************/
RCC_TNIT:
ldr r0,=0x50000a28
ldr r1,[r0]
orr r1,r1,#(0x1 << 4)
orr r1,r1,#(0x1 << 5)
str r1,[r0]
LED_TNIT:
ldr r0,=0x50006000
ldr r1,[r0]
and r1,r1,#(~(0x3 << 20))
orr r1,r1,#(0x1 << 20)
str r1,[r0]
and r1,r1,#(~(0x3 << 16))
orr r1,r1,#(0x1 << 16)
str r1,[r0]
ldr r0,=0x50007000
ldr r1,[r0]
and r1,r1,#(~(0x3 << 20))
orr r1,r1,#(0x1 << 20)
str r1,[r0]
@推完
ldr r0,=0x50006004
ldr r1,[r0]
bic r1,r1,#(0x1 << 10)
str r1,[r0]
bic r1,r1,#(0x1 << 8)
str r1,[r0]
ldr r0,=0x50007004
ldr r1,[r0]
bic r1,r1,#(0x1 << 10)
str r1,[r0]
@低速
ldr r0,=0x50006008
ldr r1,[r0]
and r1,r1,#(~(0x3 << 20))
str r1,[r0]
and r1,r1,#(~(0x3 << 16))
str r1,[r0]
ldr r0,=0x50007008
ldr r1,[r0]
and r1,r1,#(~(0x3 << 20))
str r1,[r0]
@禁止电阻
ldr r0,=0x5000600c
ldr r1,[r0]
and r1,r1,#(~(0x3 << 20))
str r1,[r0]
and r1,r1,#(~(0x3 << 16))
str r1,[r0]
ldr r0,=0x5000700c
ldr r1,[r0]
and r1,r1,#(~(0x3 << 20))
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:
ldr r0,=0x50006014
ldr r1,[r0]
orr r1,r1,#(0x1 << 10)
str r1,[r0]
mov pc,lr
LED2_ON:
ldr r0,=0x50007014
ldr r1,[r0]
orr r1,r1,#(0x1 << 10)
str r1,[r0]
mov pc,lr
LED3_ON:
ldr r0,=0x50006014
ldr r1,[r0]
orr r1,r1,#(0x1 << 8)
str r1,[r0]
mov pc,lr
LED1_OFF:
ldr r0,=0x50006014
ldr r1,[r0]
bic r1,r1,#(0x1 << 10)
str r1,[r0]
mov pc,lr
LED2_OFF:
ldr r0,=0x50007014
ldr r1,[r0]
bic r1,r1,#(0x1 << 10)
str r1,[r0]
mov pc,lr
LED3_OFF:
ldr r0,=0x50006014
ldr r1,[r0]
bic r1,r1,#(0x1 << 8)
str r1,[r0]
mov pc,lr
@ 大概1s的延时函数
delay_1s:
mov r3, #0x10000000
mm:
cmp r3, #0
subne r3, r3, #1
bne mm
mov pc, lr
.end
用c语言实现
1:定义一个结构体
2:宏定义一下
typedef struct{
unsigned int MODER; //00
unsigned int OTYPER;//04
unsigned int OSPEEDR; //08
unsigned int PUPDR;//0C
unsigned int IDR;//10
unsigned int ODR;//14
}gpio_t;
#define GPIOE ((volatile gpio_t*)0x50006000)
#define GPIOF ((volatile gpio_t*)0x50007000)
3:调用时用 GPIOE->MODER = GPIOE->MODER |= (0X1 <<20 );
用m4控制
1:main函数写入
2:分步dbug
while (1)
{
HAL_GPIO_WritePin (GPIOE, GPIO_PIN_10, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin (GPIOE, GPIO_PIN_10, GPIO_PIN_RESET);
HAL_Delay(500);
HAL_GPIO_WritePin (GPIOF, GPIO_PIN_10, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin (GPIOF, GPIO_PIN_10, GPIO_PIN_RESET);
HAL_Delay(500);
HAL_GPIO_WritePin (GPIOE, GPIO_PIN_8, GPIO_PIN_SET);
HAL_Delay(500);
HAL_GPIO_WritePin (GPIOE, GPIO_PIN_8, GPIO_PIN_RESET);
HAL_Delay(500);
}
文章来源:https://www.toymoban.com/news/detail-617143.html
文章来源地址https://www.toymoban.com/news/detail-617143.html
到了这里,关于arm-day2的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!