- #include<reg52.h>
- #include <intrins.h>
- #include <string.h>
- //#include<SHIJIAN.H>
- typedef unsigned char u8; // 重命名类型u8简化代码编写
- typedef unsigned int u16;
- #define LCD1602_DATA_PORT P0
- #define KEY_PORT P1 // 矩阵按键接在P1端口
- //#define DDD P2
- sbit DSIO = P3^4; // DS1302的SPI接口IO线,输入输出都走这里
- sbit CE = P3^5; // chip enable,读写ds1302前要使能,读写完要禁止
- sbit SCLK = P3^6; // serial clock,串行时钟线
- sbit gLcd1602_E=P2^7;
- sbit gLcd1602_RS=P2^6;
- sbit gLcd1602_RW=P2^5;
- sbit buzz=P1^5;
- sbit KEY_DOWN=P3^2;
- sbit KEY_OK=P3^3;
- sbit KEY_CANCEL=P3^1;
- sbit KEY_QIE=P3^0;
- sbit KEY_JIA=P1^1;
- sbit KEY_TIAO=P1^0;
- char local_date=0,base_date=0;
- u8 hour=0,minute=0,second=0,count=0;
- u8 slnum=0,cishu=0;
- code u8 SHIJIAN[60]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
- 0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,
- 0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59};
- code unsigned char FPM10A_Get_Device[10] ={0x01,0x00,0x07,0x13,0x00,0x00,0x00,0x00,0x00,0x1b};//口令验证
- code unsigned char FPM10A_Pack_Head[6] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF}; //协议包头
- code unsigned char FPM10A_Get_Img[6] = {0x01,0x00,0x03,0x01,0x00,0x05}; //获得指纹图像
- code unsigned char FPM10A_Get_Templete_Count[6] ={0x01,0x00,0x03,0x1D,0x00,0x21 }; //获得模版总数
- code unsigned char FPM10A_Search[11]={0x01,0x00,0x08,0x04,0x01,0x00,0x00,0x03,0xE7,0x00,0xF8}; //搜索指纹搜索范围0 - 999,使用BUFFER1中的特征码搜索
- code unsigned char FPM10A_Search_0_9[11]={0x01,0x00,0x08,0x04,0x01,0x00,0x00,0x00,0x13,0x00,0x21}; //搜索0-9号指纹
- code unsigned char FPM10A_Img_To_Buffer1[7]={0x01,0x00,0x04,0x02,0x01,0x00,0x08}; //将图像放入到BUFFER1
- code unsigned char FPM10A_Img_To_Buffer2[7]={0x01,0x00,0x04,0x02,0x02,0x00,0x09}; //将图像放入到BUFFER2
- code unsigned char FPM10A_Reg_Model[6]={0x01,0x00,0x03,0x05,0x00,0x09}; //将BUFFER1跟BUFFER2合成特征模版
- code unsigned char FPM10A_Delete_All_Model[6]={0x01,0x00,0x03,0x0d,0x00,0x11};//删除指纹模块里所有的模版
- volatile unsigned char FPM10A_Save_Finger[9]={0x01,0x00,0x06,0x06,0x01,0x00,0x0B,0x00,0x19};//将BUFFER1中的特征码存放到指定的位置
- code u8 DS1302_READ_ADDR[7] = {0x81, 0x83, 0x85, 0x87, 0x89, 0x8b, 0x8d};
- code u8 DS1302_WRITE_ADDR[7] = {0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c};
- xdata u8 gTime[7]; // 用来存储DS1302中7个时间的BCD码值
- xdata u8 gDispBuf0[17]; // LCD1602上面一排的显示buf
- xdata u8 gDispBuf1[17];
- volatile unsigned char FPM10A_RECEICE_BUFFER[32];
- void Buzz_Times(unsigned char times);
- void zhishideng(u8 val);
- u8 KeyScan(void);
- void Uart_Init(void);
- void Uart_Send_Byte(unsigned char c);
- unsigned char Uart_Receive_Byte();
- void FPM10A_Cmd_Send_Pack_Head(void);
- void FPM10A_Cmd_Check(void);
- void FPM10A_Receive_Data(unsigned char ucLength);
- void FPM10A_Cmd_Get_Img(void);
- void FINGERPRINT_Cmd_Img_To_Buffer1(void);
- void FINGERPRINT_Cmd_Img_To_Buffer2(void);
- void FPM10A_Cmd_Search_Finger(void);
- void FPM10A_Cmd_Reg_Model(void);
- void FINGERPRINT_Cmd_Delete_All_Model(void);
- void FPM10A_Cmd_Save_Finger( unsigned int storeID );
- void FPM10A_Add_Fingerprint();
- void FPM10A_Find_Fingerprint();
- void FPM10A_Delete_All_Fingerprint();
- void Device_Check(void);
- static void fun1();
- static void fun2();
- void delay(u16 z)
- {
- u16 x,y,a;
- for(x=z;x>0;x--)
- for(y=142;y>0;y--);
- for(a=2;a>0;a--);
-
- }
- //static void delay5ms(void);
- static void Lcd1602WaitNoBusy(void) //忙检测函数,判断bit7是0,允许执行;1禁止
- {
- u8 sta = 0; //
- LCD1602_DATA_PORT = 0xff;
- gLcd1602_RS = 0;
- gLcd1602_RW = 1;
- do
- {
- gLcd1602_E = 1;
- sta = LCD1602_DATA_PORT;
- gLcd1602_E = 0; //使能,用完就拉低,释放总线
- }while(sta & 0x80);
- }
- static void Lcd1602WriteCmd(u8 cmd)
- {
- Lcd1602WaitNoBusy(); // 先等待LCD1602处于不忙状态
- gLcd1602_E = 0; // 禁止LCD
- gLcd1602_RS = 0; // 选择发送命令模式
- gLcd1602_RW = 0; // 选择写入模式
- LCD1602_DATA_PORT = cmd; // 将1字节命令字放入8位并行数据端口
- gLcd1602_E = 1; // 使能LED
- gLcd1602_E = 0; // 禁止LCD
- }
- static void Lcd1602WriteData(u8 dat)
- {
- Lcd1602WaitNoBusy(); // 先等待LCD1602处于不忙状态
- gLcd1602_E = 0; // 禁止LCD
- gLcd1602_RS = 1; // 选择发送数据模式
- gLcd1602_RW = 0; // 选择写入模式
- LCD1602_DATA_PORT = dat; // 将1字节命令字放入8位并行数据端口
- gLcd1602_E = 1; // 使能LED
- gLcd1602_E = 0; // 禁止LCD
- }
- void Lcd1602Init(void)
- {
- Lcd1602WriteCmd(0x38); // 按照数据手册的初始化时序,先发送38H
- delay(5); // 延时5ms
- Lcd1602WriteCmd(0x38); // 按照数据手册的初始化时序,先发送38H
- delay(5); // 延时5ms
- Lcd1602WriteCmd(0x38); // 按照数据手册的初始化时序,先发送38H
- delay(5); // 延时5ms
- Lcd1602WriteCmd(0x38); // 显示模式设置
- Lcd1602WriteCmd(0x08); // 关闭显示
- Lcd1602WriteCmd(0x01); // 清屏(同时清数据指针)
- Lcd1602WriteCmd(0x06); // 读写后指针自动加1,写1个字符后整屏显示不移动
- Lcd1602WriteCmd(0x0c); // 开显示,不显示光标
- }
- void Lcd1602SetCursor(u8 x, u8 y) // 坐标显示
- {
- u8 addr = 0;
- switch (y)
- {
- case 0: // 上面一行
- addr = 0x00 + x; break;
- case 1: // 下面一行
- addr = 0x40 + x; break;
- default:
- break;
- }
- Lcd1602WriteCmd(addr | 0x80);
- }
- void Lcd1602ShowStr(u8 x, u8 y, u8 *pStr) //显示字符串
- {
- Lcd1602SetCursor(x, y); //当前字符的坐标
- while (*pStr != '\0')
- {
- Lcd1602WriteData(*pStr++);
- }
- }
- void Lcd1602DispBufInit(void)
- {
- strcpy(gDispBuf0,"00:00:00 ");
- //gDispBuf0[14] = 0xdf; // 显示摄氏度的小圆圈
- //gDispBuf0[15] = 'C'; // 显示摄氏度的大写C
- //gDispBuf0[16] = '\0'; // 字符串结尾
- //strcpy(gDispBuf1, "00 00 00EEOK-00H");
- }
- void Lcd1602UpdateDisplay(void)
- {
- Lcd1602ShowStr(0, 0,"menjingxitong ");
- Lcd1602ShowStr(0, 1, gDispBuf0);
- }
- /*void write_hms(u8 add,u8 dat) //时分秒写函数,add:输入位置设置变量 dat:输入时分秒数据
- {
- u8 sw,gw; //定义十位个位变量
- sw=dat/10;
- gw=dat%10;
- Lcd1602WriteCmd(0x80+0x40+add);//从第二行(add)位开始写数据
- Lcd1602WriteData(0x30+sw); //写入十位
- Lcd1602WriteData(0x30+gw); //写入个位
- } */
- static void Ds1302WriteReg(u8 addr, u8 dat)
- {
- u8 i = 0;
- CE = 0;
- _nop_(); // 空指令,延时
- SCLK = 0; // 先将SCLK置低电平
- _nop_();
- CE = 1; // CE拉高以使能对DS1302的读写权限
- _nop_();
- for (i=0; i<8; i++) // 循环逐位发送addr的8个bit,注意低位在前
- {
- DSIO = addr & 0x01; // 数据从LSB低位开始传送
- addr >>= 1; // 发完后addr右移一位原来的次低位变成新的低位
- SCLK = 1; // 拉高SCLK制造一个上升沿,通知DS1302读取数据
- _nop_(); // 延时等待DS1302读取DSIO线上的1位数据
- SCLK = 0; // 读完后,拉低SCLK为下一个位的传输做准备
- _nop_();
- }
- // 循环结束后1字节的寄存器地址传给DS1302
- for (i=0; i<8; i++) // 循环写入8位数据,注意低位在前
- {
- DSIO = dat & 0x01;
- dat >>= 1;
- SCLK = 1; //制造上升沿通知DS1302读取数据
- _nop_();
- SCLK = 0;
- _nop_();
- } // 循环结束后1字节值成功传给DS1302
-
- CE = 0; // 写入完毕拉低CE以禁止对DS1302的读写,防止意外改写事故
- _nop_();
- }
- /*********************************************************************
- * 函 数 名 : Ds1302ReadReg
- * 函数功能 : 向DS1302中地址为addr的寄存器写入数值dat
- * 参数列表 : addr - 待读出的寄存器的地址
- * 函数输出 : 读出的寄存器addr的数值
- *********************************************************************/
- static u8 Ds1302ReadReg(u8 addr)
- {
- u8 i = 0, dat = 0, dat1 = 0;
- CE = 0; // CE设置为初始状态
- _nop_();
- SCLK = 0; // SCLK设置为初始状态
- _nop_();
- CE = 1; // 拉高CE使能对DS1302的寄存器读写权限
- _nop_();
- for (i=0; i<8; i++) // 循环发送8bit寄存器地址值
- {
- DSIO = addr & 0x01; // DS1302的SPI接口从LSB开始发送
- addr >>= 1;
- SCLK = 1; // 制造上升沿,DS1302在上升沿完成读取动作
- _nop_();
- SCLK = 0; // 拉低SCLK为下个bit发送做准备
- _nop_();
- }
-
- for (i=0; i<8; i++) // 循环读取8bit寄存器值数据
- {
- dat1 = DSIO;//从最低位开始接收
- dat = (dat>>1) | (dat1<<7);
- SCLK = 1;
- _nop_();
- SCLK = 0;//DS1302下降沿时,放置数据
- _nop_();
- }
- CE = 0;
- _nop_(); //以下为DS1302复位的稳定时间,必须的。
- SCLK = 1;
- _nop_();
- DSIO = 0;
- _nop_();
- DSIO = 1;
- _nop_();
- return dat;
- }
- /*********************************************************************
- * 函 数 名 : Ds1302WriteTime
- * 函数功能 : 将全局变量gTime中的时间写入DS1302中以重置DS1302时间
- * 参数列表 : 无
- * 函数输出 : 无
- *********************************************************************/
- static void Ds1302WriteTime(void)
- {
- u8 i = 0;
- Ds1302WriteReg(0x8E, 0x00); // 禁用WP以获取写时间寄存器的权限
- for (i=0; i<7; i++) // 依次写入7个时间,顺序依次:秒分时日月周年
- {
- Ds1302WriteReg(DS1302_WRITE_ADDR[i], gTime[i]);
- }
- Ds1302WriteReg(0x8E, 0x80); // 使能WP以禁止对时间寄存器的读写,防止意外改写事故
- }
- /*********************************************************************
- * 函 数 名 : Ds1302InitTime
- * 函数功能 : 以给定的初始时间来重置DS1302时间值
- * 参数列表 : 无
- * 函数输出 : 无
- *********************************************************************/
- void Ds1302InitTime(void)
- {
- // 先给个初始化时间
- gTime[0] = 0x50; // 初始化时间,秒,注意是BCD码不是10进制也不是16进制
- gTime[1] = 0x59; // 初始化时间,分,注意是BCD码不是10进制也不是16进制
- gTime[2] = 0x23; // 初始化时间,时,注意是BCD码不是10进制也不是16进制
-
-
- //gTime[3] = 0x23; // 初始化时间,日,注意是BCD码不是10进制也不是16进制
- //gTime[4] = 0x10; // 初始化时间,月,注意是BCD码不是10进制也不是16进制
- //gTime[5] = 0x01; // 初始化时间,周,注意是BCD码不是10进制也不是16进制
- //gTime[6] = 0x17; // 初始化时间,年,注意是BCD码不是10进制也不是16进制,以2000为基数
- // 将给定时间写入DS1302内部时间寄存器以完成初始化
- Ds1302WriteTime();
- }
- /*********************************************************************
- * 函 数 名 : Ds1302ReadTime
- * 函数功能 : 读出DS1302内部时间放入全局变量gTime中
- * 参数列表 : 无
- * 函数输出 : 无
- *********************************************************************/
- void Ds1302ReadTime(void)
- {
- u8 i = 0;
- for (i=0; i<7; i++)//读取7个字节的时钟信号:秒分时日月周年
- {
- gTime[i] = Ds1302ReadReg(DS1302_READ_ADDR[i]);
- // gTime[i] = 0x23;
- }
- }
- /*********************************************************************
- * 函 数 名 : Ds1302ReadTime
- * 函数功能 : 读出DS1302内部时间放入全局变量gTime中
- * 参数列表 : 无
- * 函数输出 : 无
- *********************************************************************/
- void Ds1302WorkTest(void)
- {
- // 第1步:从DS1302读取时间存入gTime中
- Ds1302ReadTime();
- // 第2步:将gTime中的时间值格式化为字符串存入gTimeStr中
- gDispBuf0[0] = ((gTime[2] >> 4) & 0x0f) + '0'; // Hour的高4位
- gDispBuf0[1] = ((gTime[2] >> 0) & 0x0f) + '0'; // Hour的低4位
- // gDispBuf0[2] = ':'; // 分隔符
-
- gDispBuf0[3] = ((gTime[1] >> 4) & 0x0f) + '0'; // Minute的高4位
- gDispBuf0[4] = ((gTime[1] >> 0) & 0x0f) + '0'; // Minute的低4位
- // gDispBuf0[5] = ':'; // 分隔符
- gDispBuf0[6] = ((gTime[0] >> 4) & 0x0f) + '0'; // Second的高4位
- gDispBuf0[7] = ((gTime[0] >> 0) & 0x0f) + '0'; // Second的低4位
- // gDispBuf0[8] = '-';
-
- }
- void main(void)
- {
- Lcd1602Init();
- // 上面1行给17个字符,超出的最后一个'g'没有被显示
- Lcd1602ShowStr(0, 0, "men jin xi tong ");
- // 下面1行给16个字符,刚好完美显示
- Lcd1602ShowStr(0, 1, "welcome ");
- // 最后别忘了打结,不然程序会反复执行,反复刷屏,看到的现象是
- // 屏幕显示抖动。
- //Lcd1602WriteCmd(0x01);
- Uart_Init();
- delay(200);
- Ds1302InitTime();
- Lcd1602DispBufInit();
- gLcd1602_RW=0;
- Device_Check(); //校对指纹模块是否接入正确,液晶做出相应的提示
- delay(2000);
- while(1)
- {
- if(KEY_QIE==0)
- {
- while(KEY_QIE==0);
- //shijian=1;
- //cishu+=1;
- if(cishu<2)
- {
- cishu+=1;
- if(cishu==2)
- cishu=0;
- }
-
- }
- switch(cishu)
- {
- case 0: //指纹
- fun1();
- break;
-
- case 1: // 时间
- fun2();
- break;
- }
- }
- }
- static void fun1()
- {
- //FPM10A_Cmd_Send_Pack_Head();
- //FPM10A_Cmd_Check();
- //FPM10A_Receive_Data(12);
- //delay(2000);
- Device_Check();
- do
- {
- Lcd1602WriteCmd(0x01);
- Lcd1602ShowStr(0, 0, " search finger ");
- Lcd1602ShowStr(0, 1, " Add delete");
- if(local_date==0)
- {
-
- Lcd1602ShowStr(1, 0, "*");
- Lcd1602ShowStr(1, 1, " ");
- Lcd1602ShowStr(9, 1, " ");
- }
- else if(local_date==1)
- {
-
- Lcd1602ShowStr(1, 0, " ");
- Lcd1602ShowStr(1, 1, "*");
- Lcd1602ShowStr(9, 1, " ");
- }
- else if(local_date==2)
- {
-
- Lcd1602ShowStr(1, 0, " ");
- Lcd1602ShowStr(1, 1, " ");
- Lcd1602ShowStr(9, 1, "*");
- }
- //确认键
- 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;
- }
- }
- delay(100); //延时判断100MS检测一次
- }while(KEY_QIE!=0);
- }
-
- static void fun2()
- {
- u8 i = 0;
- Lcd1602WriteCmd(0x01);
- Ds1302WorkTest();
- Lcd1602UpdateDisplay();
- if(KEY_TIAO==0)
- {
- while(KEY_TIAO==0);
- Ds1302WriteReg(0x8E, 0x00); // 禁用WP以获取写时间寄存器的权限
- slnum++;
- switch(slnum)
- {
- case 1:Lcd1602WriteCmd(0x80+0x40+7);
- break;
- case 2:Lcd1602WriteCmd(0x80+0x40+4);
- break;
- case 3:Lcd1602WriteCmd(0x80+0x40+1);
- break;
- }
- Lcd1602WriteCmd(0x0f);
- if(slnum==4)
- {
- slnum=0;
- Lcd1602WriteCmd(0x0c);
- }
- //Ds1302WriteReg(0x8E, 0x80); // 禁用WP以获取写时间寄存器的权限
- }
- if(KEY_JIA==0)
- {
- while(KEY_JIA==0);
- switch(slnum)
- {
- case 1: second++;
- if(second==60) second=0;
- Ds1302WriteReg(DS1302_WRITE_ADDR[0], SHIJIAN[second]);
- break;
- case 2: minute++;
- if(minute==60) minute=0;
- Ds1302WriteReg(DS1302_WRITE_ADDR[1], SHIJIAN[minute]);
- break;
- case 3: hour++;
- if(hour==24) hour=0;
- Ds1302WriteReg(DS1302_WRITE_ADDR[2], SHIJIAN[hour]);
- break;
-
- }
- } delay(100);
- }
- void Uart_Init(void)
- {
- SCON=0x50; //UART方式1:8位UART; REN=1:允许接收
- PCON=0x00; //SMOD=0:波特率不加倍
- TMOD=0x20; //T1方式2,用于UART波特率
- TH1=0xFD;
- TL1=0xFD; //UART波特率设置:FDFD,9600;FFFF,57600
- TR1=1; //允许T1计数
- EA=1;
- }
- void Uart_Send_Byte(unsigned char c)//UART Send a byte
- {
- SBUF = c;
- while(!TI); //发送完为1
- TI = 0;
- }
- unsigned char Uart_Receive_Byte()//UART Receive a byteg
- {
- unsigned char dat;
- while(!RI); //接收完为1
- RI = 0;
- dat = SBUF;
- return (dat);
- }
- void FPM10A_Cmd_Send_Pack_Head(void)
- {
- int i;
- for(i=0;i<6;i++) //包头
- {
- Uart_Send_Byte(FPM10A_Pack_Head[i]);
- }
- }
- //发送指令
- void FPM10A_Cmd_Check(void)
- {
- int i=0;
- FPM10A_Cmd_Send_Pack_Head(); //发送通信协议包头
- for(i=0;i<10;i++)
- {
- Uart_Send_Byte(FPM10A_Get_Device[i]);
- }
- }
- //接收反馈数据缓冲
- void FPM10A_Receive_Data(unsigned char ucLength)
- {
- unsigned char i;
- for (i=0;i<ucLength;i++)
- FPM10A_RECEICE_BUFFER[i] = Uart_Receive_Byte();
- }
- //FINGERPRINT_获得指纹图像命令
- void FPM10A_Cmd_Get_Img(void)
- {
- unsigned char i;
- FPM10A_Cmd_Send_Pack_Head(); //发送通信协议包头
- for(i=0;i<6;i++) //发送命令 0x1d
- {
- Uart_Send_Byte(FPM10A_Get_Img[i]);
- }
- }
- //讲图像转换成特征码存放在Buffer1中
- void FINGERPRINT_Cmd_Img_To_Buffer1(void)
- {
- unsigned char i;
- FPM10A_Cmd_Send_Pack_Head(); //发送通信协议包头
- for(i=0;i<7;i++) //发送命令 将图像转换成 特征码 存放在 CHAR_buffer1
- {
- Uart_Send_Byte(FPM10A_Img_To_Buffer1[i]);
- }
- }
- //将图像转换成特征码存放在Buffer2中
- void FINGERPRINT_Cmd_Img_To_Buffer2(void)
- {
- unsigned char i;
- for(i=0;i<6;i++) //发送包头
- {
- Uart_Send_Byte(FPM10A_Pack_Head[i]);
- }
- for(i=0;i<7;i++) //发送命令 将图像转换成 特征码 存放在 CHAR_buffer2
- {
- Uart_Send_Byte(FPM10A_Img_To_Buffer2[i]);
- }
- }
- //搜索全部用户999枚
- void FPM10A_Cmd_Search_Finger(void)
- {
- unsigned char i;
- FPM10A_Cmd_Send_Pack_Head(); //发送通信协议包头
- for(i=0;i<11;i++)
- {
- Uart_Send_Byte(FPM10A_Search[i]);
- }
- }
- //将BUFFER1跟BUFFER2合成特征模版
- void FPM10A_Cmd_Reg_Model(void)
- {
- unsigned char i;
-
- FPM10A_Cmd_Send_Pack_Head(); //发送通信协议包头
- for(i=0;i<6;i++)
- {
- Uart_Send_Byte(FPM10A_Reg_Model[i]);
- }
- }
- //删除指纹模块里的所有指纹模版
- void FINGERPRINT_Cmd_Delete_All_Model(void)
- {
- unsigned char i;
- for(i=0;i<6;i++) //包头
- Uart_Send_Byte(FPM10A_Pack_Head[i]);
- for(i=0;i<6;i++) //命令合并指纹模版
- {
- Uart_Send_Byte(FPM10A_Delete_All_Model[i]);
- }
- }
- //保存指纹
- void FPM10A_Cmd_Save_Finger( unsigned int storeID )
- {
- unsigned long temp = 0;
- unsigned char i;
- FPM10A_Save_Finger[5] =(storeID&0xFF00)>>8; //0x00,0x0B,0x00,0x19.
- FPM10A_Save_Finger[6] = (storeID&0x00FF);
- for(i=0;i<7;i++) //计算校验和
- temp = temp + FPM10A_Save_Finger[i];
- FPM10A_Save_Finger[7]=(temp & 0x00FF00) >> 8; //存放校验数据
- FPM10A_Save_Finger[8]= temp & 0x0000FF;
- FPM10A_Cmd_Send_Pack_Head(); //发送通信协议包头
- for(i=0;i<9;i++)
- Uart_Send_Byte(FPM10A_Save_Finger[i]); //发送命令 将图像转换成 特征码 存放在 CHAR_buffer1
- }
- //添加指纹
- void FPM10A_Add_Fingerprint()
- {
- unsigned char id_show[]={0,0,0};
- u16 finger_id;
- Lcd1602WriteCmd(0x01); //清屏
- finger_id=0;
- while(1)
- {
- Lcd1602ShowStr(0,0," Add finger ");
- Lcd1602ShowStr(0,1," ID: ");
-
- //按返回键直接回到主菜单
- if(KEY_CANCEL == 0)
- {
- while(KEY_CANCEL==0);
- break;
- }
- //按切换键指纹iD值加1
- if(KEY_DOWN == 0)
- {
- while(KEY_DOWN==0);
- if(finger_id == 1000)
- {
- finger_id = 0;
- }
- else
- finger_id = finger_id + 1;
- }
- //指纹iD值显示处理
- Lcd1602WriteCmd(0xc0+10);
- Lcd1602WriteData(finger_id/100+48);
- Lcd1602WriteData(finger_id%100/10+48);
- Lcd1602WriteData(finger_id%100%10+48);
- //按确认键开始录入指纹信息
- if(KEY_OK == 0)
- {
- while(KEY_OK==0);
- Lcd1602ShowStr(0,0," Please finger ");
- //LCD1602_Display(0x80," Please finger ",0,16);
- //LCD1602_Display(0xc0," ",0,16);
- Lcd1602ShowStr(0,1," ");
- //while(KEY_CANCEL == 1)
- while(KEY_CANCEL == 1)
- {
- //按下返回键退出录入返回fingerID调整状态
- if(KEY_CANCEL == 0)
- {
- while(KEY_CANCEL==0);
- break;
- }
- FPM10A_Cmd_Get_Img(); //获得指纹图像
- FPM10A_Receive_Data(12);
- //判断接收到的确认码,等于0指纹获取成功
- if(FPM10A_RECEICE_BUFFER[9]==0)
- {
- //Delay_Ms(100);
- delay(100);
- FINGERPRINT_Cmd_Img_To_Buffer1();
- FPM10A_Receive_Data(12);
- Lcd1602ShowStr(0,0,"Successful entry");
- //LCD1602_Display(0x80,"Successful entry",0,16);
- Buzz_Times(1);
- delay(1000);
- Lcd1602ShowStr(0,0," Please finger ");
- Lcd1602ShowStr(0,1," ");
- //LCD1602_Display(0x80," Please finger ",0,16);
- //LCD1602_Display(0xc0," ",0,16);
- while(1)
- {
- if(KEY_CANCEL == 0)
- {
- while(KEY_CANCEL==0);
- break;
- }
- FPM10A_Cmd_Get_Img(); //获得指纹图像
- FPM10A_Receive_Data(12);
- //判断接收到的确认码,等于0指纹获取成功
- if(FPM10A_RECEICE_BUFFER[9]==0)
- {
- delay(200);
- Lcd1602ShowStr(0,0,"Successful entry");
- Lcd1602ShowStr(0,1," ID is ");
- //LCD1602_Display(0x80,"Successful entry",0,16);
- //LCD1602_Display(0xc0," ID is ",0,16);
- //指纹iD值显示处理
- Lcd1602WriteCmd(0xc0+10);
- Lcd1602WriteData(finger_id/100+48);
- Lcd1602WriteData(finger_id%100/10+48);
- Lcd1602WriteData(finger_id%100%10+48);
- FINGERPRINT_Cmd_Img_To_Buffer2();
- FPM10A_Receive_Data(12);
- FPM10A_Cmd_Reg_Model();//转换成特征码
- FPM10A_Receive_Data(12);
- FPM10A_Cmd_Save_Finger(finger_id);
- FPM10A_Receive_Data(12);
- Buzz_Times(1);
- delay(1000);
- finger_id=finger_id+1;
- break;
- }
- }
-
- break;
- }
- }
- // ClrScreen(); //清空显示屏
- }
- // Delay_Ms(500);
- }
- }
- //搜索指纹
- void FPM10A_Find_Fingerprint()
- {
- unsigned int find_fingerid = 0;
- unsigned char id_show[]={0,0,0};
- do
- {
- Lcd1602ShowStr(0,0," Please finger ");
- Lcd1602ShowStr(0,1," ");
- //LCD1602_Display(0x80," Please finger ",0,16);
- //LCD1602_Display(0xc0," ",0,16);
- FPM10A_Cmd_Get_Img(); //获得指纹图像
- FPM10A_Receive_Data(12);
- //判断接收到的确认码,等于0指纹获取成功
- if(FPM10A_RECEICE_BUFFER[9]==0)
- {
- delay(100);
- FINGERPRINT_Cmd_Img_To_Buffer1();
- FPM10A_Receive_Data(12);
- FPM10A_Cmd_Search_Finger();
- FPM10A_Receive_Data(16);
- if(FPM10A_RECEICE_BUFFER[9] == 0) //搜索到
- {
- Lcd1602ShowStr(0,0," Search success ");
- Lcd1602ShowStr(0,1," ID is ");
- //LCD1602_Display(0x80," Search success ",0,16);
- //LCD1602_Display(0xc0," ID is ",0,16);
- Buzz_Times(1);
- //拼接指纹ID数
- find_fingerid = FPM10A_RECEICE_BUFFER[10]*256 + FPM10A_RECEICE_BUFFER[11];
- //指纹iD值显示处理
- Lcd1602WriteCmd(0xc0+10);
- Lcd1602WriteData(find_fingerid/100+48);
- Lcd1602WriteData(find_fingerid%100/10+48);
- Lcd1602WriteData(find_fingerid%100%10+48);
- //LCD1602_WriteCMD(0xc0+10);
- //LCD1602_WriteDAT(find_fingerid/100+48);
- //LCD1602_WriteDAT(find_fingerid%100/10+48);
- //LCD1602_WriteDAT(find_fingerid%100%10+48);
- delay(2000);
- }
- else //没有找到
- {
- //LCD1602_Display(0x80," Search failed ",0,16);
- //LCD1602_Display(0xc0," ",0,16);
- Lcd1602ShowStr(0,0," Search failed ");
- Lcd1602ShowStr(0,1," ");
- Buzz_Times(3);
- }
- }
- }while(KEY_CANCEL == 1);
- }
- //删除所有存贮的指纹库
- void FPM10A_Delete_All_Fingerprint()
- {
- unsigned char i=0;
- //LCD1602_Display(0x80," empty all ",0,16);
- //LCD1602_Display(0xc0," Yes or no ? ",0,16);
- Lcd1602ShowStr(0,0," empty all ");
- Lcd1602ShowStr(0,1," Yes or no ? ");
- do
- {if(KEY_OK==0)
- {
- while(KEY_OK==0);
- //LCD1602_Display(0x80," emptying ",0,16);
- //LCD1602_Display(0xc0," ",0,16);
- Lcd1602ShowStr(0,0," emptying ");
- Lcd1602ShowStr(0,1," ");
- delay(300);
- Lcd1602WriteCmd(0xc0);
- for(i=0;i<16;i++)
- {
- Lcd1602WriteData(42);
- delay(100);
- }
- FINGERPRINT_Cmd_Delete_All_Model();
- FPM10A_Receive_Data(12);
- // LCD1602_Display(0x80," All empty ",0,16);
- // LCD1602_Display(0xc0," ",0,16);
- Lcd1602ShowStr(0,0," All empty ");
- Lcd1602ShowStr(0,1," ");
- Buzz_Times(3);
- break;
- }
- }while(KEY_CANCEL==1);
- }
- void Device_Check(void)
- {
- unsigned char i=0;
- FPM10A_RECEICE_BUFFER[9]=1; //串口数组第九位可判断是否通信正常
- Lcd1602ShowStr(0,1,"Loading "); //LCD1602_Display(0xc0,"Loading",0,7); //设备加载中界面
- for(i=0;i<8;i++) //进度条式更新,看起来美观
- {
- Lcd1602WriteData(42); //42对应ASIC码的 *
- delay(200); //控制进度条速度
- }
- Lcd1602ShowStr(0,1,"failure "); //LCD1602_Display(0xc0,"Docking failure",0,16); //液晶先显示对接失败,如果指纹模块插对的话会将其覆盖
- FPM10A_Cmd_Check(); //单片机向指纹模块发送校对命令
- FPM10A_Receive_Data(12); //将串口接收到的数据转存
- if(FPM10A_RECEICE_BUFFER[9]==0) //判断数据低第9位是否接收到0
- {
- Lcd1602ShowStr(0,1,"success "); //LCD1602_Display(0xc0,"Docking success",0,16); //符合成功条件则显示对接成功
- }
- }
- void Buzz_Times(unsigned char times)
- {
- unsigned char i=0;
- for(i=0;i<times;i++)
- {
- buzz=0;
- delay(1);
- buzz=1;
- delay(1);
- }
- }
复制代码 |