stc11f02e 單片機
fm70指紋模塊 jdy-31藍牙模塊
藍牙發送命令 增加 刪除 查詢
沒有加入密碼 連接藍牙后可以直接發送命令
輸出pwm控制舵機動作
由于ad不太會用 畫了一個比較low的板子
買的貼片 又轉成DIP的
Altium Designer畫的原理圖和PCB圖如下:(51hei附件中可下載工程文件)
123.jpg (86.08 KB, 下載次數: 41)
下載附件
2020-11-20 17:45 上傳
大佬勿噴 新手入門
部分單片機代碼如下:
- #include<fm70.h>
- u8 AutoLogin[11]={0x01,0x00,0x08,0x54,0x55,0x02,0x00,0x00,0x01,0x00,0x00}; //5.5s 2次 序號*2 可重復 校驗和
- u8 DeleteChar[10]={0x01,0x00,0x07,0x0c,0x00,0x00,0x00,0x01,0x00,0x00};//刪除
- u8 ValidN;//模板個數
- u16 MathScore;//得分
- u16 IDs_temp;
- u8 recive_num;//確認碼
- bit Recive_Error;//校驗和錯誤
- bit Open_Flag;//開門標志
- void Delay500us() //@11.0592MHz
- {
- unsigned char i, j;
- i = 6;
- j = 93;
- do
- {
- while (--j);
- } while (--i);
- }
- void Uart_Send(u8 sta) //發送
- {
- SBUF=sta;
- while(!TI);
- TI=0;
- }
- u8 Uart_Recevie()//接收
- {
- u8 sta;
- while(!RI);
- RI=0;
- sta=SBUF;
- return (sta);
- }
- void SendCmd(u8 *cmd,u8 len)//發送命令
- {
- u8 i;
- for(i=0;i<6;i++)
- Uart_Send(PackHead[i]);//發送包頭
- for(i=0;i<len;i++)
- Uart_Send(cmd[i]);
- }
- void Send_Char(u8 *str)//發送信息
- {
- u8 *s;
- s=str;
- AUXR1=0x80;//=1 ->P1 =0 ->P3
- Delay500us();
- while(*s!='\0')
- {
- Uart_Send(*s);
- s++;
- }
- AUXR1=0x00;//=1 ->P1 =0 ->P3
- }
- void StoreChar_SetNum()//設置指紋存儲數組
- {
- u8 i;
- u16 sum_temp=0x00; //校驗和臨時變量
- AutoLogin[7]=ValidN; //低位
- for(i=0;i<9;i++) //校驗和計數
- sum_temp+=AutoLogin[i];
- AutoLogin[9]=(u8)(sum_temp>>8);
- AutoLogin[10]=(u8)sum_temp;
- }
- void Delete_Finger(u8 delete_id)//刪除指紋數據
- {
- u8 i;
- u16 sum_temp=0x00;
- //DeleteChar[4]=(u8)(delete_id>>8);//PageID 高位
- DeleteChar[5]=delete_id;//低位
- for(i=0;i<8;i++) //校驗和計算
- sum_temp+=DeleteChar[i];
- DeleteChar[8]=(u8)(sum_temp>>8);
- DeleteChar[9]=(u8)sum_temp;
- SendCmd(DeleteChar,10);
- ReviceCmd(6);
- if(Recive_Error)//校驗和錯誤
- return;
- if(recive_num==0x10)
- Send_Char("刪除成功!!!\r\n");
- else if(recive_num==0x00)
- Send_Char("刪除失敗!!!\r\n");
- }
- void ReviceCmd(u8 len)//接收包處理
- {
- u8 i;
- u16 check_num=0x00;//校驗和
- u16 sum_temp=0x00;//數據和
- u8 recive_temp[10];//接收數據緩存
- Recive_Error=0;//校驗和標志清零
- for(i=0;i<6;i++)
- Uart_Recevie();//丟棄前6個數據
- for(i=0;i<len;i++)
- recive_temp[i]=Uart_Recevie();
- check_num=recive_temp[len-2];
- check_num=(check_num<<8)|recive_temp[len-1];//校驗和合并
- for(i=0;i<len-2;i++)
- sum_temp+=recive_temp[i]; //數據和計算
- if(sum_temp==check_num)
- {
- if(len==10)//接收的是搜索指紋返回包
- {
- IDs_temp=(recive_temp[4]<<8)|recive_temp[5];//搜索到的指紋號
- MathScore=(recive_temp[6]<<8)|recive_temp[7];//得分
- }
- if(len==8)//讀取模板個數返回包
- {
- //ValidN=recive_temp[4];
- //ValidN=(ValidN<<8)|recive_temp[5];//模板個數合并
- ValidN=recive_temp[5];//0xff 直接省略高位數據
- }
- recive_num=recive_temp[3];//確認碼
- }
- else
- {
- Recive_Error=1;
- Send_Char("校驗和錯誤\r\n");//發送信息
- }
- }
- void Add_finger()//添加指紋
- {
- u8 str[5];
- if(ValidN>=100)
- {
- Send_Char("指紋庫滿!!!\r\n");
- while(wake);
- return;
- }
- StoreChar_SetNum();//設置指紋存儲數組
- ValidN=ValidN+1;//指紋加一
- SendCmd(AutoLogin,11);
- ReviceCmd(6);
- if(Recive_Error)//校驗和錯誤
- return;
- if(recive_num!=0x56)
- {
- Send_Char("第一次采集失敗!!!\r\n");
- while(wake);
- return;
- }
- ReviceCmd(6);
- if(recive_num!=0x00)
- {
- Send_Char("添加失敗!!!\r\n");
- while(wake);
- return;
- }
- Send_Char("添加成功\r\n");
- Send_Char("當前編號:");
- str[0]=AutoLogin[7]/10+0x30;
- str[1]=AutoLogin[7]%10+0x30;
- str[2]='\0';
- Send_Char(str);
- Send_Char("\r\n");
- }
- void Search_Finger()//搜索指紋
- {
- SendCmd(AutoSearch,11);
- ReviceCmd(10); //OK_Char
- if(Recive_Error)//校驗和錯誤
- return;
- if(recive_num==0x09)
- {
- Send_Char("你是黑戶!!!!!!!!\r\n");
- return;
- }
- else if(recive_num==0x00)
- {
- Send_Char("歡迎回家!\r\n");
- Open_Door();//開門
- }
- }
- void Init_FM70()//初始化模塊
- {
- SendCmd(GetEcho,6);
- ReviceCmd(6);//接受包處理
- if(Recive_Error)//校驗和錯誤
- return;
- if(recive_num!=0x55)
- {
- Send_Char("設備異常。。r\n");
- Send_Char("即將重啟。!\r\n");
- Delay400ms();Delay400ms();Delay400ms();
- IAP_CONTR=0x40;//重啟
- }
- Send_Char("\r\n系統加載成功!\r\n");
- }
復制代碼
51hei.png (6.59 KB, 下載次數: 45)
下載附件
2020-11-20 17:55 上傳
51hei.png (4.63 KB, 下載次數: 49)
下載附件
2020-11-20 17:56 上傳
全部資料51hei下載地址:
fm70.rar
(18 MB, 下載次數: 31)
2020-11-20 17:47 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|