写在前面
1.应项目要求,要迅速熟悉stm32的GPIO、串口以及TIM高级定时器(输出PWM)
2.初步了解stm32学习方法以及编程要领(疯狂地赋值粘贴库函数,学会看库函数的函数介绍以及参数选择,注意现在h文件里看函数声明,再goto到相应的函数处)
正文
(一)GPIO的初始化过程
//主要用来点亮LED
void LED_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*使能时钟,去库函数的rcc源文件里找*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
/*配置引脚,工作模式,速度(决定功耗),去库函数的gpio源文件里找*/
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
//主要用来控制键盘
void Key_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
//该函数的形参的定义是由GPIO_ReadInputDataBit(gpio库函数)决定的
uint8_t Key_Scan(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin)
{
if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==1)
{
return 1;
}
else
return 0;
}
(二)注意事项
#include ".\led\bsp_led.h"
增加头文件的检索路径,或者用上述方法实现头文件的检索