新手上路
- 积分
- 36
- 金钱
- 36
- 注册时间
- 2014-12-31
- 在线时间
- 0 小时
|
5金钱
最近在学习开发板,先从按键试验开始。程序看到LED_Init() 里面的代码
//LED IO初始化
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD, ENABLE); //
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //LED0--> A.8 配置端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //
GPIO_Init(GPIOA, &GPIO_InitStructure); //
GPIO_SetBits(GPIOA,GPIO_Pin_8); //
.....................................
对于程序中的GPIO_InitStructure.GPIO_Pin我有点不解。先看一下 GPIO_InitTypeDef
typedef struct
{
uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */
GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIOSpeed_TypeDef */
GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIOMode_TypeDef */
}GPIO_InitTypeDef;
再看GPIO_InitStructure.GPIO_Pin代表的是结构体变量中的一个成员,我想知道地址在哪里?怎么能确认对它的赋值就是对寄存器的赋值?哪里表示他就是对应的寄存器?
同样 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP GPIO_Mode只是一个枚举变量,没有地址。怎么确定它是对相应寄存器赋值?哪里表示他就是对应的寄存器?
同程序中的 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD, ENABLE)里面可以找到
RCC->APB2ENR;它是有地址的!
兄弟初学者,请多多指教!找了论坛没有相关解答。
|
最佳答案
查看完整内容[请看2#楼]
关键在GPIO_Init(GPIOA, &GPIO_InitStructure);
你找到 GPIOA的定义 然后打开初始化函数GPIO_Init(GPIOA, &GPIO_InitStructure);
你会明白的
|