实验目的:实现LED1 / LED2 / LED3三盏灯工作
1,思路
分析电路图可知:
网络编号 == 引脚编号
LED1 == PE10
LED2 ===> PF10
LED3 ===> PE8
2,工作原理:
写1:LED灯亮,写0:LED灯灭
1,A7核和GPIO控制器:通过内部总线通讯,查看芯片手册可知总线为AHB4总线
2,(核外特殊功能寄存器):芯片厂家出厂时,固化到芯片内部的一端寻址空间,地址固定
3,A7核通过汇编指令 LDR / STR控制特殊功能器
4,根据框图需要分析:
RCC章节 == 使能GPIOE和GPIOF组控制器
GPIO章节 == 1)初始化GPIO引脚,2)引脚输出高低电平
查看芯片手册:GPIO通过AHB4总线和RCC连接
GPIOF:0x50007000
GPIOE:0x50006000
RCC: 0x50000000
作用:使能GPIO组寄存器
地址:0x50000000 + 0xA28 = 0x50000A28
伪代码:RCC_MP_AHB4ENSETR [4] = 1 === GPIOE
RCC_MP_AHB4ENSETR [5] = 1 === GPIOF
1,概述
2,框图
作用:设置GPIO引脚模式(输入,输出,复用,模拟)本实验输出高低电平,选用输出
地址:0x50006000 + 0x00 = 0x50006000
0x50007000 + 0x00 = 0x50007000
伪代码:GPIOE_MODER [21:20] = 01 ==== LED1
GPIOF_MODER [21:20] = 01 ==== LED2
GPIOE_MODER [17:16] = 01 ==== LED3
推挽输出类型:PMOS管和NMOS管都可以进行工作
开漏输出类型:只有NMOS管可以进行工作
作用:设置GPIO引脚输出类型为推挽输出
地址:0x50006000 + 0x04 = 0x50006004
0x50007000 + 0x04 = 0x50007004
伪代码:GPIOE_OTYPER [10] = 0 ==== LED1
GPIOF_OTYPER [10] = 0 ==== LED2
GPIOE_OTYPER [8] = 01 ==== LED3
作用:设置GPIO引脚输出速率(低速、中速、高速、快速)
地址:0x50006000 + 0x08 = 0x50006008
0x50007000 + 0x08 = 0x50007008
伪代码:GPIOE_OSPEEDR [21:20] = 01 ==== LED1
GPIOF_OSPEEDR [21:20] = 01 ==== LED2
GPIOE_OSPEEDR [17:16] = 01 ==== LED3
作用:设置GPIO引脚是否需要上下拉电阻(禁止上下拉电阻、上拉、下拉、保留)本实验通过引脚控制灯的亮灭,需要禁止上下拉电阻
地址:0x50006000 + 0x0C = 0x5000600C
0x50007000 + 0x0C = 0x5000700C
伪代码:GPIOE_PUPDR [21:20] = 00 ====LED1
GPIOF_PUPDR [21:20] = 00 ====LED2
GPIOE_PUPDR [17:16] = 00 ====LED3
作用:设置引脚输出高 / 低电平写1:输出高电平,LED灯点亮 写0:输出低电平,LED灯熄灭
地址:0x50006000 + 0x14 = 0x50006014
0x50007000 + 0x14 = 0x50007014
伪代码:GPIOE_ODR [10] = 1 / 0 ====LED1
GPIOF_ODR [10] = 1 / 0 ====LED2
GPIOE_ODR [8] = 1 / 0 ====LED3
1、在汇编语言中0x50000A28代表一块地址空间,但是在C语言中表示十六进制数,在C语言中,如何将0x50000A28表示一块地址空间的
(volatile unsigned int*)0x50000A28 ====> ldr r0,=0x50000A28
2、如何取出0x50000A28这块地址空间中的内容
(*(volatile unsigned int*)0x50000A28) ====> ldr r1,[r0]
3、将0x50000A28这块地址空间中的第4位进行置1,保证其他位不变
(*(volatile unsigned int*)0x50000A28) = (*(volatile unsigned int*)0x50000A28) | (0x1 << 4); ====> orr r1,r1,#(0x1 << 4) str r1,[r0]
4、用宏定义如何对寄存器进行封装
#define RCC_MP_AHB4_ENSETR (*(volatile unsigned int*)0x50000A28)
RCC_MP_AHB4_ENSETR = RCC_MP_AHB4_ENSETR | (0x1 << 4);
RCC_MP_AHB4_ENSETR |= (0x1 << 4);
5、将GPIOE/GPIOF寄存器进行封装
#define GPIOE_MODER (*(volatile unsigned int*)0x50006000)
#define GPIOE_OTYPER (*(volatile unsigned int*)0x50006004)
#define GPIOE_OSPEEDR (*(volatile unsigned int*)0x50006008)
#define GPIOE_PUPDR (*(volatile unsigned int*)0x5000600C)
#define GPIOE_ODR (*(volatile unsigned int*)0x50006014)
typedef struct{
volatile unsigned int MODER; //MODER
volatile unsigned int OTYPER; //OTYPER
volatile unsigned int OOSPEEDR; //OSPEEDR
volatile unsigned int PUPDR; //PUPDR
volatile unsigned int IDR; //IDR
volatile unsigned int ODR; //ODR
}gpio_t;
#define GPIOE ((gpio_t*)0x50006000) 注释:GPIOE ===> 0x50006000
#define GPIOF ((gpio_t*)0x50007000) 注释:GPIOF ===> 0x50007000
访问结构体成员:GPIOE->MODER