STM32入门学习------快速组织代码

快速组织代码

步骤

          (1)使能IO口时钟调用函数为 RCC_APB2PeriphClockCmd()
          (2)初始化IO参数  调用函数 GPIO_Init();
          (3)操作IO口,输出高低电平{GPIO_SetBits()或GPIO_ResetBits()}
使能IO口时钟函数

1)使能 GPIOB 时钟:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
2)使能串口 1 时钟:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
3)使能 AFIO 时钟:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
4)开启重映射:
GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
初始化某个GPIO端口

void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);

//GPIOx:  GPIOA---GPIOG
定义一个结构变量

GPIO_InitTypeDef GPIO_InitStructure;
typedef struct
{ uint16_t GPIO_Pin; 
 GPIOSpeed_TypeDef GPIO_Speed; 
 GPIOMode_TypeDef GPIO_Mode; GPIOMode_TypeDef 
}GPIO_InitTypeDef;

头文件中,为避免头文件内容重复定义


#ifdef 标识符
程序段 1 
#else 
程序段 2 
#endif 
发布了42 篇原创文章 · 获赞 85 · 访问量 2301

猜你喜欢

转载自blog.csdn.net/weixin_44955712/article/details/103218723