STM32 project design: based on stm32f103c8t6 intelligent elevator system

Data link: to be updated ~
Bilibili video link: https://www.bilibili.com/video/BV17D4y1V7HG/?vd_source=e5082ef80535e952b2a4301746491be0 (bilibili: turned into dust my)
data link: https://pan.baidu. com/s/1qObK7KBl50RmFrAtoX12kw
extraction code: iih4

1. Overview of project functions

1. OLED displays current floor, target floor and other information
2. You can swipe your card to reach the designated floor
3. You can swipe your fingerprint to reach the designated floor
4. You can enter the password to enter the administrator mode, enter the card and corresponding floor information, and enter the fingerprint and corresponding floor information , and can modify and delete fingerprint and card information
5. Use stepping motor to drive up and down floors
6. Use steering gear to control door opening and closing (this project has not been realized)
7. There is an alarm function. Alarm
8, the appearance is built with wooden boards

2. Selection of project materials

1. Display selection 0.96 inch SPIOLED
insert image description here

2. Select RF522 for card swiping module
insert image description here

3. Select AS608 for the fingerprint module
insert image description here

4. Select the buzzer for the alarm module
insert image description here

5. Enter the password to select the matrix button
insert image description here

6. The power circuit selects the USB interface input, and the AMS1117 step-down chip turns 3.3V to supply power to the microcontroller
insert image description here
insert image description here

7. The main control chip selection STM32F103C8T6
main control chip needs to be able to drive OLED, card swiping module, fingerprint module, and matrix buttons. In theory, 51 single-chip microcomputers can meet the requirements, but the amount of code is large, and the memory will have relatively high requirements, so choose familiar ones stm32f103c8t6, ​​64K FLASH memory is enough to store code and display a large number of Chinese characters.
insert image description here

3. Schematic design

1. Minimum system design of single-chip microcomputer
insert image description here
2. Design of power supply part
insert image description here
3. Design of power supply and download interface of single-chip microcomputer
insert image description here
4. Circuit design of fingerprint, button, RFID, buzzer, stepping motor, etc.
insert image description here

4. PCB board design

insert image description here

Five, the main program design

(1) Program design ideas:
1. Find the fingerprint module code and transplant it for debugging.
2. Obtain RFID driver and OLED driver from merchants or the Internet. 3. Write
matrix button driver and stepper motor driver with relatively simple principles by yourself.
The parameter structure is convenient for management
typedef struct
{ u32 HZCFlag; //turn into dust and save the flag, initialize the parameters when powered on, and then save the parameters to the MCU FLASH u8 passwd1[7]; //Administrator password 1 u8 passwd2[7]; // Administrator password 2 u8 cardid[10][6]; //can store 10 card IDs u8 cardFloor[10];//save array u8 CurrFloor corresponding to the floor of the card;//current floor u8 TgtFloor; //target floor u8 errCnt ;//Error count u8 errTime;//Waiting for error time u8 fingerFloor[100];//Fingerprint ID corresponds to the floor u16 fingNum;//Fingerprint number u16 cardNum;//RFID number } SysTemPat ; Based on the structure operation, it is necessary to ensure that the data is synchronized in real time














#include "main.h"

#include <string.h>

SysTemPat sys;

#define MAXERRTIMES 5
#define usart2_baund  57600//串口2波特率,根据指纹模块波特率更改

//要写入到STM32 FLASH的字符串数组
const u8 TEXT_Buffer[]={
    
    0x17,0x23,0x6f,0x60,0,0};
#define TEXT_LENTH sizeof(TEXT_Buffer)	 		  	//数组长度	
#define SIZE TEXT_LENTH/4+((TEXT_LENTH%4)?1:0)
#define FLASH_SAVE_ADDR  0X0802C124 	//设置FLASH 保存地址(必须为偶数,且所在扇区,要大于本代码所占用到的扇区.
										//否则,写操作的时候,可能会导致擦除整个扇区,从而引起部分程序丢失.引起死机.

SysPara AS608Para;//指纹模块AS608参数
u16 ValidN;//模块内有效指纹个数
u8** kbd_tbl;

void Display_Data(void);//显示时间
void Add_FR(void);	//录指纹
void Del_FR(void);	//删除指纹
int press_FR(void);//刷指纹
void ShowErrMessage(u8 ensure);//显示确认码错误信息
int password(void);//密码锁
void SetPassworld(void);//修改密码
void starting(void);//开机界面信息
u8 MFRC522_lock(void);//刷卡解锁
u8 Add_Rfid(void);		//录入
void Set_Time(void);
void Massige(void);
void SysPartInit(void );   //系统参数初始化 
//u8 Pwd[7]="      ";  //解锁密码1
//u8 Pwd2[7]="      ";  //解锁密码2
//u8 cardid[6]={0,0,0,0,0,0};  //卡号1
int Error;  //密码验证信息


u8 DisFlag = 1,ArrowDisFlag=1;



//数字的ASCII码
uc8 numberascii[]={
    
    '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
//显示缓冲区
u8  dispnumber5buf[6];
u8  dispnumber3buf[4];
u8  dispnumber2buf[3];
//MFRC522数据区
u8  mfrc552pidbuf[18];
u8  card_pydebuf[2];
u8  card_numberbuf[5];
u8  card_key0Abuf[6]={
    
    0xff,0xff,0xff,0xff,0xff,0xff};
u8  card_writebuf[16]={
    
    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
u8  card_readbuf[18];
//SM05-S数据区
u8  sm05cmdbuf[15]={
    
    14,128,0,22,5,0,0,0,4,1,157,16,0,0,21};
//extern声明变量已在外部的C文件里定义,可以在主文件中使用
extern u8  sm05receivebuf[16];	//在中断C文件里定义
extern u8  sm05_OK;							//在中断C文件里定义

//u8 * week[7]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
u8 * week[7]={
    
    "Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
u8 * setup[7]={
    
    "1、录入指纹","2、删除指纹","3、修改密码","4、修改时间","5、录入卡片","6、查看信息"};






 int main(void)
 {
    
    			
//	u16 set=0;
//	 u8 err=0;
//	int key_num;
	int time1;
//	int time2;		//锁屏时间
	char arrow=0;  //箭头位子
	//SysHSI_Init();
	delay_init();	    	 //延时函数初始化	  
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
	uart_init(115200);	 //串口初始化为9600
	printf("串口功能正常\r\n");
	Button4_4_Init();          //初始化与按键连接的硬件接口
	OLED_Init();    			//显示初始化
	Walkmotor_Init();        //步进电机初始化
	BEEP_Init();			//蜂鸣器初始化
	usart2_init(usart2_baund);           //初始化指纹模块
	PS_StaGPIO_Init();
	OLED_Clear(); 
	 
	starting();//开机信息  logo
//	err = RTC_Init();	  			//RTC初始化
//	if(err)
//	{
    
    
//		OLED_Clear(); 
//		Show_Str(12,13,128,20,"RTC CRY ERR!",12,0); 
//		OLED_Refresh_Gram();//更新显示
//		delay_ms(3000);
//	}
	SysPartInit();   //系统参数初始化 
	
	
	while(1)
	{
    
    
		time1++;
		if(DisFlag == 1)
		{
    
    
			OLED_ShowNum(58,20,sys.CurrFloor,1,24);//显示当前楼层
		}
		if(ArrowDisFlag == 1)
		{
    
    
			
		}
		if(sys.TgtFloor != sys.CurrFloor)//需要到达目标楼层
		{
    
    
			if(sys.TgtFloor > sys.CurrFloor)
			for(; sys.CurrFloor<sys.TgtFloor; )//上楼
			{
    
    
				sys.CurrFloor++;
				Walkmotor_ON();
				OLED_ShowNum(58,20,sys.CurrFloor,1,24);//显示当前楼层
			}else if(sys.TgtFloor < sys.CurrFloor)
			for(; sys.CurrFloor>sys.TgtFloor;)//下楼
			{
    
    
				sys.CurrFloor--;
				Walkmotor_OFF();
				OLED_ShowNum(58,20,sys.CurrFloor,1,24);//显示当前楼层
			}
		}
		if(sys.TgtFloor == sys.CurrFloor && sys.CurrFloor!=1)//如果电梯不在1楼停下,返回1楼
		{
    
    
			for(; sys.CurrFloor>1; )//下楼
			{
    
    
				sys.CurrFloor--;
				Walkmotor_OFF();
				OLED_ShowNum(58,20,sys.CurrFloor,1,24);//显示当前楼层
			}
		}
		
		/******************检测刷卡与指纹********************/
		if((time1%100)==1)
				{
    
    
					//MFRC522解锁
					time1=0;
					MFRC522_Initializtion();			
					Error=MFRC522_lock();
					if(Error==0)
					{
    
    
					}


				}
		//指纹解锁
				if(PS_Sta)	 //检测PS_Sta状态,如果有手指按下
				{
    
    
						while(PS_Sta){
    
    
						Error=press_FR();//刷指纹
						if(Error==0)
						{
    
    
							//DisUnLock();
							//跳到解锁界面
						}	
					}
				}		
		
		
	}		
		
		 
 }
 

6. Finished product display

insert image description here

Guess you like

Origin blog.csdn.net/mbs520/article/details/122617736