IO.h文件
#ifndef __IO_H
#define __IO_H
#include "stm32f10x.h"
void IO_Init(void);
void SetBite_1_0(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, char a);
#endif
IO.c文件
#include "IO.h"
/*************************************************************************/
/**
* @brief IO初始化配置
* @retval None
*/
void IO_Init()
{
//定义结构体,名字自定义
GPIO_InitTypeDef GPIO_InitStruct;
//打开管脚时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
//管脚配置
//管脚位
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8; //GPIO_Pin_0 ~ GPIO_Pin_15
//管脚模式
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出管脚(组)配置
// = GPIO_Mode_IN_FLOATING; //浮空输入管脚(组)配置
// = GPIO_Mode_IPU; //上拉输入管脚(组)配置
// = GPIO_Mode_IPD; //下拉输入管脚(组)配置
// = GPIO_Mode_Out_OD; //开漏输出管脚(组)配置
// = GPIO_Mode_AIN; //模拟输入管脚(组)配置
// = GPIO_Mode_AF_OD; //复用开漏输出管脚(组)配置
// = GPIO_Mode_AF_PP; //复用推挽输出管脚(组)配置
//管脚速度
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; //高速50MHz
// = GPIO_Speed_10MHz; //中速10MHz
// = GPIO_Speed_2MHz; //低速2MHz
//初始化管脚
GPIO_Init(GPIOB, &GPIO_InitStruct);
}
main.c
#include "stm32f10x.h"
#include "IO.h"
int main()
{
//调用初始化函数
IO_Init();
SetBite_1_0(GPIOB, GPIO_Pin_8, 1); //B组第8管脚输出高电平
SetBite_1_0(GPIOB, GPIO_Pin_8, 0); //B组第8管脚输出低电平
while(1)
{
}
}