本帖最后由 立夏匆匆 于 2020-5-4 10:36 編輯
我的程序.zip
(94 KB, 下載次數(shù): 18)
2020-5-4 10:36 上傳
點擊文件名下載附件
完整程序
這個問題已經(jīng)折磨我快一周了,怎么查程序的問題都查不出來,增加指紋這個函數(shù)只要一運行,就只能顯示“請按指紋”這四個字,然后即便按指紋也不會運行下面的程序,確認碼也能返回,就是不往下運行。附程序:#include <reg52.h>
#include <intrins.h>
sbit TCH = P3^7;//按指紋識別
uchar data querenma=11;//用于緩存確認碼
uchar sum[2],sum1[2];//sum存放應答包的校驗和,sum1存放指令包的校驗和
int sum_ans,sum_ins;//定義整形變量用來存放2字節(jié)大小的校驗和
uint page_ID;//存放注冊函數(shù)中的頁碼
/**************************************************
函數(shù)名稱:端口初始化
單片機:晶振11.0592MHz 波特率為9600bps
指紋模塊:波特率為9600bps
***************************************************/
void UART_init()
{
SCON = 0x50;//串行寄存器設(shè)為串行口工作方式1(01010000)
PCON = 0x00;//一般默認為0
TMOD = 0x20;//定時器1,工作方式2
TH1 = 0xfd;//T1定時器裝初值(波特率9600bps)
TL1 = 0xfd;//T1定時器裝初值
TR1 = 1;//啟動定時器1
EA = 1;//開總中斷
}
/**************************************************
函數(shù)作用:串口發(fā)送1幀數(shù)據(jù)
***************************************************/
void UART_sent_byte(uchar c)
{
SBUF = c;//將要發(fā)送的數(shù)據(jù)放在SBUF中,單片機會自動發(fā)送
while (!TI);//判斷一下TI有沒有置1,如果TI等于0,說明沒有
//發(fā)完,那么會一直等待。如果發(fā)送完了,那么TI
//等于1,1取反為0,那么會跳出這句話。
TI = 0;//發(fā)送完了,要把發(fā)送標志位清零
}
/**************************************************
函數(shù)作用:串口接收1幀數(shù)據(jù)
和發(fā)送函數(shù)原理一樣,只是把發(fā)送標志位改為接收標志位。
***************************************************/
uchar UART_receive_byte()
{
uchar dat;
while (!RI);
RI = 0;
dat = SBUF;
return (dat);
}
/**************************************************
函數(shù)作用:錄入指紋圖像
***************************************************/
void getimage()
{
uchar i;
UART_sent_byte(0xef);
UART_sent_byte(0x01);//協(xié)議包頭為0xef01
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);//芯片地址為0xffffffff
UART_sent_byte(0x01);//包標識
UART_sent_byte(0x00);
UART_sent_byte(0x03);//包長度是2字節(jié)的03H
UART_sent_byte(0x01);//錄入圖像指令碼
UART_sent_byte(0x00);
UART_sent_byte(0x05);//校驗和是2字節(jié)的05H
for (i=0;i<9;i++)//接收應答包前9字節(jié)為包頭,芯片地址,包識別,包長度
{
while (!RI);
RI = 0;
}
querenma = UART_receive_byte();
sum[1] = UART_receive_byte();
sum[0] = UART_receive_byte();
sum_ans = (sum[1]<<8)+sum[0];//存放16位校驗和
}
/**************************************************
函數(shù)作用:生成指紋特征,并存入bufferID中
***************************************************/
void genchar(uchar bufferID)
{
uchar i;
UART_sent_byte(0xef);
UART_sent_byte(0x01);//協(xié)議包頭為0xef01
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);//芯片地址為0xffffffff
UART_sent_byte(0x01);//包標識
UART_sent_byte(0x00);
UART_sent_byte(0x04);//包長度是2字節(jié)的04H
UART_sent_byte(0x02);//生成特征指令碼
UART_sent_byte(bufferID);//輸入特征緩沖區(qū)號
sum_ins = 0x07+bufferID;
sum1[0] = sum_ins;
sum1[1] = sum_ins>>8;
UART_sent_byte(sum1[1]);
UART_sent_byte(sum1[0]);
for (i=0;i<9;i++)//接收應答包前9字節(jié)為包頭,芯片地址,包識別,包長度
{
while (!RI);
RI = 0;
}
querenma = UART_receive_byte();
sum[1] = UART_receive_byte();
sum[0] = UART_receive_byte();
sum_ans = (sum[1]<<8)+sum[0];//存放16位校驗和
}
/**************************************************
函數(shù)作用:自動注冊模板。
采集一次指紋注冊模板,在指紋庫中搜索空位并存儲,返回
儲存ID。
***************************************************/
void enroll()
{
uchar i,ID1,ID2;
UART_sent_byte(0xef);
UART_sent_byte(0x01);//協(xié)議包頭為0xef01
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);//芯片地址為0xffffffff
UART_sent_byte(0x01);//包標識
UART_sent_byte(0x00);
UART_sent_byte(0x03);//包長度是2字節(jié)的03H
UART_sent_byte(0x10);//指令碼
UART_sent_byte(0x00);
UART_sent_byte(0x14);//校驗和
for (i=0;i<9;i++)////接收應答包前9字節(jié)為包頭,芯片地址,包識別,包長度
{
while (!RI);
RI = 0;
}
querenma = UART_receive_byte();
ID1 = UART_receive_byte();
ID2 = UART_receive_byte();//存放頁碼
sum[1] = UART_receive_byte();
sum[0] = UART_receive_byte();
page_ID = (ID1<<8)+ID2;//存放16位頁碼
sum_ans = (sum[1]<<8)+sum[0];//存放16位校驗和
}
/**************************************************
函數(shù)作用:高速搜索。
1.以charbuffer1或charbuffer2中的特征文件高速搜索整個或
部分指紋庫。若搜索到就返回頁碼。
2.該指令對于的確存在于指紋庫中,且登錄時質(zhì)量很好的指紋,
會很快給出搜索結(jié)果。
***************************************************/
void fastsearch(uchar BufferID)
{
uchar i,ID1,ID2;
UART_sent_byte(0xef);
UART_sent_byte(0x01);//協(xié)議包頭為0xef01
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);
UART_sent_byte(0xff);//芯片地址為0xffffffff
UART_sent_byte(0x01);//包標識
UART_sent_byte(0x00);
UART_sent_byte(0x08);//包長度
UART_sent_byte(0x1b);//指令碼
UART_sent_byte(BufferID);//緩沖區(qū)號
UART_sent_byte(0x00);
UART_sent_byte(0x00);//起始頁碼
UART_sent_byte(0x00);
UART_sent_byte(0xb4);//頁碼數(shù)量180
sum_ins = 9+0x1b+BufferID+0xb4;//校驗和
sum1[0] = sum_ins;
sum1[1] = sum_ins>>8;
UART_sent_byte(sum[1]);
UART_sent_byte(sum[0]);
for (i=0;i<9;i++)////接收應答包前9字節(jié)為包頭,芯片地址,包識別,包長度
{
while (!RI);
RI = 0;
}
querenma = UART_receive_byte();
ID1 = UART_receive_byte();
ID2 = UART_receive_byte();//存放頁碼
while(!RI);
RI = 0;
while(!RI);
RI = 0; //2字節(jié)的得分
sum[1] = UART_receive_byte();
sum[0] = UART_receive_byte();
page_ID = (ID1<<8)+ID2;//存放16位頁碼
sum_ans = (sum[1]<<8)+sum[0];//存放16位校驗和
}
/**************************************************
增加指紋函數(shù)
***************************************************/
void addfinger()
{
uchar IDa,IDb,IDc;//存儲返回的指紋序號
PutStr(1,2,"請按手指");
getimage();
while (querenma != 0)
getimage();
genchar(bufferID1);
UART_init();
fastsearch(bufferID1);
while (querenma == 1)
fastsearch(bufferID1);
if (querenma == 0)
{
lcdclear();
PutStr(1,1,"指紋已被錄入");
PutStr(2,1,"請按任意鍵繼續(xù)");
while(keycheck()==0);
}
else if (querenma == 9)
{
lcdclear();
PutStr(1,1,"請再按手指");
enroll();
while (querenma == 2)
enroll();
lcdclear();
if (querenma == 0)
{
IDa = page_ID /100;//取百位
IDb = (page_ID-IDa*100)/10;//取十位
IDc = page_ID%10;//取個位
PutStr(1,1,"指紋錄入成功");
PutStr(2,1,"編號為:");
lcd_wcmd(0x8d);
lcd_wdat(0x30+IDa);lcd_wdat(0x30+IDb);lcd_wdat(0x30+IDc);//通過ASC碼值進行輸出
}
else if(querenma != 0)
{
PutStr(1,1,"指紋錄入失敗");
PutStr(2,1,"請重新操作");
}
PutStr(3,0,"請按任意鍵繼續(xù)");
while (keycheck() == 0);
}
}
|