初级会员

- 积分
- 89
- 金钱
- 89
- 注册时间
- 2017-7-9
- 在线时间
- 14 小时
|
3金钱
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE, ENABLE); //使能PB,PE端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化GPIOB.5
GPIO_SetBits(GPIOB,GPIO_Pin_5); //PB.5 输出高
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED1-->PE.5 端口配置, 推挽输出
GPIO_Init(GPIOE, &GPIO_InitStructure); //推挽输出 ,IO口速度为50MHz
GPIO_SetBits(GPIOE,GPIO_Pin_5); //PE.5 输出高
}
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_Init(GPIOB, &GPIO_InitStructure);
原型:void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct); //初始化gpio
GPIO_TypeDef和GPIO_InitTypeDef都是结构体,为什么GPIO就可以直接写GPIOB,而设置模式就要写&GPIO_InitStructure,并在前面加上GPIO_InitTypeDef GPIO_InitStructure;呢??C语言知识有点浅薄,望大神指教,谢谢!!!
|
最佳答案
查看完整内容[请看2#楼]
GPIOB是一个宏定义,就是一个地址,
#define PERIPH_BASE ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */
#define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)
#define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
|