arm-day2

汇编实现三个灯循环点亮

cpp 复制代码
.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:宏定义一下

cpp 复制代码
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

cpp 复制代码
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);
}
相关推荐
熠速4 小时前
PolarBox高性能实时仿真系统
arm开发·fpga开发·嵌入式实时数据库·硬件在环半实物仿真
天下·第二1 天前
如何在【x86】服务器上打包构建【arm】镜像
服务器·arm开发·eureka
止观止1 天前
在 WSL2 上从零搭建 ARM 混合编程环境
汇编·arm开发·嵌入式开发·混合编程
陌上花开缓缓归以2 天前
nand flash bbt和bmt管理
arm开发
小熊officer2 天前
AMD架构与ARM架构
arm开发·架构
_kerneler3 天前
arm虚拟机实时性优化总结
arm开发
口袋里のInit3 天前
基础知识——ARM M核入栈出栈流程
开发语言·arm开发
2035去旅行4 天前
WIFI传输带宽
arm开发·嵌入式硬件
陌上花开缓缓归以4 天前
nand flash 驱动适配
arm开发
振南的单片机世界4 天前
影子寄存器:改ARR下个周期才生效,波形不突变
arm开发·stm32·单片机·嵌入式硬件