STM32F4(KEY)
GitHub仓库:https://github.com/XinLiGitHub/STM32F4xx_KEY_Example
PS:博文不再更新,后续更新会在GitHub仓库进行。
在实际的项目开发过程中,常常会遇到硬件电路的修改,然后修改的部分就需要修改驱动程序。想这样需求该来该去是程序员们最烦闷的事情(重复劳动痛不欲生啊~)。为了避免或减少重复劳动,就需要在程序的架构上下功夫。接下来以最常见的KEY驱动程序为例,进行程序结构设计。
1,开发环境
1,固件库:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0
2,编译器:ARMCC V5.06
3,IDE:Keil uVision5
4,操作系统:Windows 10 专业版
2,程序源码
KEY.h文件
/**
******************************************************************************
* @file KEY.h
* @author XinLi
* @version v1.0
* @date 24-October-2017
* @brief Header file for KEY.c module.
******************************************************************************
* @attention
*
* <h2><center>Copyright © 2017 XinLi</center></h2>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
******************************************************************************
*/
#ifndef __KEY_H
#define __KEY_H
#ifdef __cplusplus
extern "C" {
#endif
/* Header includes -----------------------------------------------------------*/
#include "stm32f4xx.h"
/* Macro definitions ---------------------------------------------------------*/
#define KEYn (3)
#define KEY1_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOC
#define KEY1_GPIO GPIOC
#define KEY1_GPIO_Pin GPIO_Pin_2
#define KEY2_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOC
#define KEY2_GPIO GPIOC
#define KEY2_GPIO_Pin GPIO_Pin_3
#define KEY3_RCC_AHB1Periph_GPIO RCC_AHB1Periph_GPIOC
#define KEY3_GPIO GPIOC
#define KEY3_GPIO_Pin GPIO_Pin_4
#define KEY_RCC_APB1Periph_TIM RCC_APB1Periph_TIM2
#d