1.声明一个结构 PPP_InitTypeDe
PPP_InitTypeDef PPP_InitStructure;
//XX类型定义初始化,XX结构体初始化
//先确定使用什么类型,再去初始化相应的结构体
Init --------初始化
Type --------类型
Def --------定义(define的缩写)
Structure --------结构体
2.在设置一个外设前,必须调用以下一个函数来使能它的时钟
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_PPPx, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_PPPx, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PPPx, ENABLE);
3.为变量 PPP_InitStructure 的各个结构成员填入允许的值
4. 调用函数 PPP_Init(..)来初始化外设 PPP
5.LED灯的初始化举例
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
}