程序设计
由于代码过长只展示部分代码:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "sram.h"
#include "malloc.h"
#include "sdio_sdcard.h"
#include "malloc.h"
#include "w25qxx.h"
#include "ff.h"
#include "exfuns.h"
#include "fontupd.h"
#include "text.h"
#include "oled.h"
#include "beep.h"
#include "button4_4.h"
#include "AS608.h"
#include "walkmotor.h"
#include "usart2.h"
#include "rtc.h"
#include "MFRC522.h"
#include "usart3.h"
#include "stmflash.h"
#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);
u8 Pwd[7]=" "; //解锁密码1
u8 Pwd2[7]=" "; //解锁密码2
u8 cardid[6]={0,0,0,0,0,0}; //卡号1
int Error; //密码验证信息
//数字的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 * setup[7]={"1、录入指纹","2、删除指纹","3、修改密码","4、修改时间","5、录入卡片","6、查看信息"};
int main(void)
{
u16 set=0;
int key_num;
int time1;
int time2; //锁屏时间
char arrow=0; //箭头位子
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
My_RTC_Init(); //初始化RTC
RTC_Set_WakeUp(RTC_WakeUpClock_CK_SPRE_16bits,0); //配置WAKE UP中断,1秒钟中断一次
delay_init(168); //初始化延时函数
uart_init(115200); //初始化串口1波特率为115200,用于支持USMART
uart3_init(9600);// 蓝牙初始化
usart2_init(usart2_baund);//初始化串口2,用于与指纹模块通讯
PS_StaGPIO_Init(); //初始化FR读状态引脚
LED_Init(); //初始化LED
// BEEP_Init(); //beep初始化
Button4_4_Init();//矩阵按键初始化
OLED_Init(); //oled初始化
W25QXX_Init(); //初始化W25Q128
Walkmotor_Init(); //步进电机初始化
my_mem_init(SRAMIN); //初始化内部内存池
my_mem_init(SRAMCCM); //初始化CCM内存池
exfuns_init(); //为fatfs相关变量申请内存
f_mount(fs[0],"0:",1); //挂载SD卡
f_mount(fs[1],"1:",1); //挂载FLASH.
starting();//开机信息 **
STMFLASH_Read(0X08020004,(u32*)Pwd,2); //读取密码1
STMFLASH_Read(0X08090004,(u32*)Pwd2,2); //读取密码2
STMFLASH_Read(0X080f0004,(u32*)cardid,1); //读取卡号1
while(1)
{
//锁屏界面
MAIN:
OLED_Show_Font(56,48,0);//显示锁图标
while(1)
{
time1++;
if((time1%200)==0)//时间显示:每50ms更新一次显示数据
{
Display_Data();
}
if((time1%1000)==0)//每200ms检测一次卡片,蓝牙数据
{
//MFRC522解锁
MFRC522_Initializtion();
Error=MFRC522_lock();
if(Error==0)goto MENU;
else
OLED_Show_Font(56,48,0);//锁
//手机蓝牙解锁密码1
Error=usart3_cherk((char*)Pwd);
if(Error==0){
OLED_Clear();
Show_Str(20,10,128,24,"解锁中...",24,0);
Walkmotor_ON();
Show_Str(20,10,128,24,"已解锁!",24,0);
goto MENU;
}
else
OLED_Show_Font(56,48,0);//锁
//手机蓝牙解锁密码2
Error=usart3_cherk((char*)Pwd2);
if(Error==0){
OLED_Clear();
Show_Str(20,10,128,24,"解锁中...",24,0);
Walkmotor_ON();
Show_Str(20,10,128,24,"已解锁!",24,0);
goto MENU;
}
else
OLED_Show_Font(56,48,0);//锁
}
//指纹解锁
if(PS_Sta) //检测PS_Sta状态,如果有手指按下
{
while(PS_Sta){
Error=press_FR();//刷指纹
if(Error==0)goto MENU;
else
OLED_Show_Font(56,48,0);//锁
}
}
//密码锁
key_num=Button4_4_Scan(); //按键扫描
if(key_num!=-1)
{
Error=password();
if(Error==0)goto MENU;
else
OLED_Show_Font(56,48,0);//锁
}
}
|