main.c 文件 带注释
#include<reg52.h>
#include<intrins.h>
#include"buzz.h"
#include"key.h"
#include"uart.h"
#include"delay.h"
#include"FPM10A.h"
#include"lcd_1602.h"
#include <stdio.h>
sbit key1 = P1^0;
sbit key2 = P1^1;
sbit key_c = P1^5;
sbit relay = P1^6;
unsigned char intFlag = 0; //进入模式
xdata unsigned char dis0[16];
unsigned char relayFlag = 0; //继电器状态标志
void intoZhiWen(void); //函数声明
void MY_FPM10A_Find_Fingerprint(void);
void main()
{
relay = 0;//继电器上电控制下 方便测试
DelayMs(200);
relay = 1;
relayFlag = 0 ;
LCD1602_Init(); //初始化液晶屏
LCD1602_Display(0x80,"Fingerprint Test",0,16); //液晶开机显示界面
Uart_Init(); //初始化串口
Key_Init(); //初始化按键
DelayMs(200);DelayMs(200);DelayMs(200); //延时500ms,等待指纹模块复位
Device_Check(); //校正指纹模块是否接入正确,液晶做出相应的提示
DelayMs(200);DelayMs(200);DelayMs(200); //对接成功界面停留一定时间
LCD1602_Display(0x80,"key1:int zhi wen",0,16); //显示
LCD1602_Display(0xc0,"key2:int jdq ctr",0,16);
do
{
DelayMs(10);
if(key1 == 0) intFlag = 1; //按键显示
if(key2 == 0) intFlag = 2;
}while((key1==1)&&(key2==1));
while(1)
{
if(intFlag == 1) //按键K1
{intoZhiWen();} //指纹管理模式
else if(intFlag == 2)
{
if(relayFlag == 1) //显示继电器状态
{
LCD1602_Display(0xc0,"Relay State: C ",0,16); //显示状态
}
else
{
LCD1602_Display(0xc0,"Relay State: O ",0,16); //显示状态
}
if(key_c == 0 ) //按键按下 关闭继电器
{
relay = 1; //继电器断开
relayFlag = 0 ;
}
MY_FPM10A_Find_Fingerprint(); //搜索指纹
DelayMs(50);
}
}
}
void OpenRelay (void) //打开继电器
{
relay = 0;
relayFlag = 1 ;
}
void intoZhiWen(void)
{
/**************进入主功能界面****************/
LCD1602_Display(0x80," search finger ",0,16); //第一排显示搜索指纹
LCD1602_Display(0xc0," Add delete",0,16); //添加和删除指纹
if(local_date==0)
{
LCD1602_Display(0x80, " *",0,2);
LCD1602_Display(0xc0, " ",0,2);
LCD1602_Display(0xc0+8," ",0,2);
}
else if(local_date==1)
{
LCD1602_Display(0x80, " ",0,2);
LCD1602_Display(0xc0, " *",0,2);
LCD1602_Display(0xc0+8," ",0,2);
}
else if(local_date==2)
{
LCD1602_Display(0x80, " ",0,2);
LCD1602_Display(0xc0, " ",0,2);
LCD1602_Display(0xc0+8," *",0,2);
}
//确认键
if(KEY_OK == 0)
{
while(KEY_OK == 0);//等待松开按键
switch(local_date)
{
case 0: //搜索指纹
FPM10A_Find_Fingerprint();
break;
case 1: //添加指纹
FPM10A_Add_Fingerprint();
break;
case 2: //清空指纹
FPM10A_Delete_All_Fingerprint();
break;
}
}
//切换键
if(KEY_DOWN == 0)
{
while(KEY_DOWN == 0); //等待松开按键
if(local_date<=2)
{
local_date++;
if(local_date==3)
local_date=0;
}
}
DelayMs(20); //延时判断100ms检测一次
}
此为主程序,要想获取工程文档可以直接点击链接百度网盘下载
- 链接:点击 这儿 提取码:x4jx
相关原理图
图片:
基于51单片机指纹管理门禁系统设计-模块框图:
基于51单片机指纹管理门禁系统设计-流程图
希望可以帮到大家