系列文章目录
1.STM32门禁系统:整体及简易模块的简介
2.STM32门禁系统:0.96寸显示模块的简介
3.STM32门禁系统:舵机模块的简介
4.等待开发中~~~~
文章目录
目录
前言
本文章是我在学习STM32后做的第一个小项目,自我感觉文章通俗易懂,因为都是自己遇到过的问题。本文按照模块一章一章发布。
一、门禁系统简介
门禁系统采用STM32F103C6T6作为主控,有矩阵键盘模块,OLED显示模块,舵机模块,指纹模块,刷卡模块,蜂鸣器模块,WIFI模块。
二、模块的介绍
1.矩阵键盘的介绍:
直接看代码吧,没啥可讲的,就是多个按键检测
代码如下(示例):

#include "Matrix.h" /* 定义列端口 从列开始检测行 */ #define COLUMN1(x) GPIO_WriteBit(GPIOA,GPIO_Pin_0, (BitAction)(x)) #define COLUMN2(x) GPIO_WriteBit(GPIOC,GPIO_Pin_15, (BitAction)(x)) #define COLUMN3(x) GPIO_WriteBit(GPIOC,GPIO_Pin_14, (BitAction)(x)) #define COLUMN4(x) GPIO_WriteBit(GPIOC,GPIO_Pin_13, (BitAction)(x)) // 初始化所有IO口 void Matrix_Init() { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOC,&GPIO_InitStruct); GPIO_SetBits(GPIOC,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);//拉低引脚 GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0; GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStruct); GPIO_SetBits(GPIOA,GPIO_Pin_0); GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU; GPIO_InitStruct.GPIO_Pin=GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStruct); GPIO_SetBits(GPIOB,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); } uint8_t Matrix_Detect() { uint8_t num=0; COLUMN1(0);COLUMN2(1);COLUMN3(1);COLUMN4(1); if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0); Delay_ms(20); num =16; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0); Delay_ms(20); num =12; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0); Delay_ms(20); num =8; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0); Delay_ms(20); num =4; } COLUMN1(1);COLUMN2(0);COLUMN3(1);COLUMN4(1); if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0); Delay_ms(20); num =15; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0); Delay_ms(20); num =11; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0); Delay_ms(20); num =7; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0); Delay_ms(20); num =3; } COLUMN1(1);COLUMN2(1);COLUMN3(0);COLUMN4(1); if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0); Delay_ms(20); num =14; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0); Delay_ms(20); num =10; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0); Delay_ms(20); num =6; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0); Delay_ms(20); num =2; } COLUMN1(1);COLUMN2(0);COLUMN3(1);COLUMN4(0); if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_12) == 0); Delay_ms(20); num =13; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13) == 0); Delay_ms(20); num =9; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == 0); Delay_ms(20); num =5; } if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0) { Delay_ms(20); while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == 0); Delay_ms(20); num =1; } return num; }
1万+

被折叠的 条评论
为什么被折叠?



