打印
[51单片机]

请教弄过指纹模块的高手或前辈,下面程序哪里出错使指纹模块无应答,与电脑通信正常

[复制链接]
1965|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gan_elec|  楼主 | 2015-3-30 01:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.h>
#include <string.h>

typedef unsigned char uchar;
typedef unsigned int uint;
//#define MAXSIZE 50

sbit LED1 = P1^0;
sbit LED8 = P1^1;
sbit LED2 = P1^2;
sbit K1 = P2^7;
uchar a = 0;
uint summas;
uchar sum[2];
uchar confcode;           //指纹模块应答确认码
//uchar  arr_mem[MAXSIZE];
//uchar head, tail;

//FINGERPRINT通信协议定义

unsigned char  FP_Pack_Head[6] = {0xEF,0x01,0xFF,0xFF,0xFF,0xFF}; //协议包头

unsigned char  PF_Verify_Pwd[10] = {0x01, 0x00, 0x07, 0x13, 0X00, 0X00, 0X00, 0X00, 0x00, 0x1b};  // 验证口令, 模块才正常工作

unsigned char  FP_Get_Img[6] = {0x01,0x00,0x03,0x01,0x00,0x05};         //获得指纹图像

unsigned char  FP_Change_Com[8] = {0x01,0x0,0x05,0x0e,0x04,0x01,0x0,0x19}; //修改波特率 9600   
   
unsigned char  FP_Templete_Num[6] ={0x01,0x00,0x03,0x1D,0x00,0x21 };  //获得模版总数

unsigned char  FP_Search[11]={0x01,0x0,0x08,0x04,0x01,0x0,0x0,0x03,0xA1,0x0,0xB2}; //搜索指纹搜索范围0 - 929

unsigned char  FP_Search_0_9[11]={0x01,0x00,0x08,0x04,0x01,0x00,0x00,0x00,0x13,0x00,0x21};  //搜索0-9号指纹

unsigned char  FP_Img_To_Buffer1[7]={0x01,0x00,0x04,0x02,0x01,0x00,0x08};        //将图像放入到BUFFER1

unsigned char  FP_Img_To_Buffer2[7]={0x01,0x00,0x04,0x02,0x02,0x00,0x09};        //将图像放入到BUFFER2

unsigned char  FP_Reg_Model[6]={0x01,0x0,0x03,0x05,0x0,0x09};         //将BUFFER1跟BUFFER2合成特征模版

unsigned char code FP_Delet_All_Model[6]={0x01,0x0,0x03,0x0d,0x00,0x11}; //删除指纹模块里所有的模版

volatile unsigned char xdata FP_Save_Finger[9]={0x01,0x00,0x06,0x06,0x01,0x00,0x0B,0x00,0x19}; //将BUFFER1中的特征码存放到指定的位置

volatile unsigned char xdata FP_Delete_Model[10]={0x01,0x00,0x07,0x0C,0x0,0x0,0x0,0x1,0x0,0x0}; //删除指定的模版


void UART_Init()  // 通信波特率9600
{
TMOD = 0x20;
//        PCON = 0x80;
TH1  = 0xfd;
TL1  = 0xfd;
TR1  = 1;
SM0  = 0;
SM1  = 1;
REN  = 1;
ES   = 1;
EA   = 1;
}
void UART_Send_Byte(uchar c) // 发送一个字节的数据
{
//        TI = 0;
SBUF = c;
while(!TI);
TI = 0;
}

void Delay_1ms(uint z)
{
uchar x, y;
for (x = z; x > 0; x--)
for (y = 110; y > 0; y--);       
}

uchar Verify_Pwd()    // 与指纹模块实现握手, 握手成功方能实行下一步动作
{
uchar i;
Delay_1ms(20);
for (i = 0; i < 6; i++)
{
UART_Send_Byte(FP_Pack_Head[i]);   //发送指令包头
Delay_1ms(20);
}
Delay_1ms(20);
for (i = 0; i < 10; i++)
{
UART_Send_Byte(PF_Verify_Pwd[i]);  //发送指令数据
Delay_1ms(20);
}
for (i = 0; i < 9; i++)        //  指纹应答数据前9个字节
{
while (!RI);
RI = 0;
Delay_1ms(20);
}
Delay_1ms(20);
while (!RI);
RI = 0;
confcode = SBUF;         // 将应答数据第10个字节也就是确认码读出
Delay_1ms(20);
while (!RI);
RI = 0;
sum[1] = SBUF;
Delay_1ms(20);
while (!RI);
RI = 0;
sum[0] = SBUF;
Delay_1ms(20);
summas = (sum[1] << 8) + sum[0];
if (confcode == 0x00)        // 确认码正确就返回1 , 错误就返回0
return 1;
else
return 0;
}


main()
{

UART_Init();
while (1)
{

//        UART_Send_Byte(0xEF);
//        if (a = 1)
//        LED1 = 0;

if (Verify_Pwd())
{
LED8 = 0;
Delay_1ms(2000);
break;
}
else
LED2 = 0;
}
}

相关帖子

沙发
gan_elec|  楼主 | 2015-4-1 15:15 | 只看该作者
   会不会有可能外围电路多导致单片机的TXD,RXD和其他模块的TXD,RXD连接异常。   因为从现象看好像模块收不到单片机发送的数据, 用串口中断判断RI没有置1

使用特权

评论回复
板凳
690420334| | 2015-4-1 15:30 | 只看该作者
gan_elec 发表于 2015-4-1 15:15
会不会有可能外围电路多导致单片机的TXD,RXD和其他模块的TXD,RXD连接异常。   因为从现象看好像模块收 ...

指纹模块卖么?qq690420334

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

7

主题

14

帖子

0

粉丝