135 lines
4.8 KiB
C
135 lines
4.8 KiB
C
#include "../../init/inc/gpio.h"
|
||
|
||
/*
|
||
* LED初始化
|
||
*/
|
||
static void LED_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOC, ENABLE); //使能与LED相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOC, &GPIO_InitStructure); //调用库函数,初始化GPIOC
|
||
|
||
GPIO_SetBits(GPIOC,GPIO_Pin_13); //设置引脚输出高电平
|
||
}
|
||
|
||
/*
|
||
* WDI初始化
|
||
*/
|
||
static void WDI_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); //使能与LED相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用库函数,初始化GPIOC
|
||
|
||
GPIO_SetBits(GPIOB,GPIO_Pin_9); //设置引脚输出高电平
|
||
}
|
||
|
||
/*
|
||
* 从机电源控制引脚初始化
|
||
*/
|
||
static void CC_PWR_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE); //使能与从机电源控制相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_15; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOA, &GPIO_InitStructure); //调用库函数,初始化GPIOC
|
||
|
||
GPIO_SetBits(GPIOA, GPIO_Pin_8|GPIO_Pin_15); //设置引脚输出高电平
|
||
}
|
||
|
||
/*
|
||
* 电源控制引脚初始化
|
||
*/
|
||
static void PWR_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); //使能与从机电源控制相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用库函数,初始化GPIOC
|
||
|
||
GPIO_SetBits(GPIOB, GPIO_Pin_11); //设置引脚输出高电平
|
||
}
|
||
|
||
/*
|
||
* 蜂鸣器控制引脚初始化
|
||
*/
|
||
static void beep_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); //使能与从机电源控制相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为推挽输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用库函数,初始化GPIOC
|
||
|
||
GPIO_SetBits(GPIOB, GPIO_Pin_2); //设置引脚输出高电平
|
||
}
|
||
|
||
/*
|
||
* 电源状态引脚初始化
|
||
*/
|
||
static void pow_sta_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); //使能与从机电源控制相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //设置GPIO模式为输入
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用库函数,初始化GPIOC
|
||
|
||
GPIO_SetBits(GPIOB, GPIO_Pin_3); //设置引脚输出高电平
|
||
}
|
||
|
||
/*
|
||
* 充放电控制引脚初始化
|
||
*/
|
||
static void CHG_DCHG_CON_Init(void)
|
||
{
|
||
GPIO_InitTypeDef GPIO_InitStructure; //定义一个GPIO_InitTypeDef类型的结构体
|
||
|
||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); //使能与从机电源控制相关的GPIO端口时钟
|
||
|
||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_6; //配置GPIO引脚
|
||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //设置GPIO模式为输出
|
||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //设置GPIO口输出速度
|
||
GPIO_Init(GPIOB, &GPIO_InitStructure); //调用库函数,初始化GPIOB
|
||
|
||
GPIO_ResetBits(GPIOB, GPIO_Pin_7|GPIO_Pin_6); //设置引脚输出低电平,默认关充放电
|
||
}
|
||
|
||
/*
|
||
* 初始化所有GPIO
|
||
*/
|
||
void all_gpio_Init(void)
|
||
{
|
||
LED_Init();
|
||
WDI_Init();
|
||
CC_PWR_Init();
|
||
PWR_Init();
|
||
beep_Init();
|
||
pow_sta_Init();
|
||
CHG_DCHG_CON_Init();
|
||
}
|