STM32F10x 按键初始化代码详解
这段代码是针对 STM32F10x 系列芯片的按键初始化函数。具体实现的功能是将 GPIOC 的 13、14、15 三个引脚设置为输入模式,并开启上拉电阻。
其中,GPIO_InitTypeDef 是 GPIO 初始化结构体类型,包含了 GPIO 的各种配置参数,例如引脚编号、模式、速率、上下拉电阻等等。而 RCC_APB2PeriphClockCmd 函数则是开启 GPIOC 的时钟,使其能够正常工作。最后,通过 GPIO_Init 函数将 GPIOC 的配置参数应用到 GPIOC 上。
#include 'stm32f10x.h'
#include 'key.h'
#include 'sys.h'
#include 'delay.h'
void KEY_Init(void) //IO初始化
{
 	GPIO_InitTypeDef GPIO_InitStructure;
 	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
	
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
 	GPIO_Init(GPIOC, &GPIO_InitStructure);		 
}
原文地址: https://www.cveoy.top/t/topic/judI 著作权归作者所有。请勿转载和采集!