使用了指纹模块,STM32 ,屏幕,加Modbus串口通信协议
视频效果地址:
https://v.youku.com/v_show/id_XNjQwMTMwNDU2MA==.html
屏幕使用UART4 ,modbus 通信和STM32
int main(void) { INIT_CPU(); T2_Init(); UART4_Init(); EA=1; // UART4_SendStr("hello",sizeof("hello")); WDT_ON();//打开开门狗
while(1) { WDT_RST();//喂狗 Process(); } }
void MainMachineHandle(void) { if(UartDataHandle) { uartHandle(Uart4_Rx,uart4_rx_count); CLR_UartMp3(); } }
bool uartHandle(u8 *Tdata,u8 len) { u16Wlen=0; u16CRC_1=0,BegAddr=0; u8 xdata RetData[Uart4_Rx_Maxlen+10]; u8 errnum=0;
CRC_1=CalcCrcAll(0xffff,Tdata,len-2); if(CRC_1!= ((Tdata[len-1])<<8 | (Tdata[len-2]))) returnfalse;
//这个为写指令 if(Tdata[0]==0&& Tdata[1]!=0x06) { returnfalse; } elseif(Tdata[0]!=DevAddr) //设备地址 { returnfalse; }
//这个为写指令 if(Tdata[1]!=0x03&& Tdata[1]!=0x06 && Tdata[1]!=0x10 ) { SendModbusAckErr(Tdata,1); returnfalse; }
Wlen=(Tdata[4]<<8|Tdata[5]); //长度 BegAddr=(Tdata[2]<<8|Tdata[3]); //开始地址
if(Tdata[1]==0x06)//写内存 { write_dgusii_vp(BegAddr,&Tdata[4],1); } elseif(Tdata[1]==0x10) { write_dgusii_vp(BegAddr,&Tdata[7],Wlen); }
//读操作响应 //[01][0x03][00][6B][00][02][CRC高][CRC低] if(Tdata[1]==0x03) { RetData[0]=Tdata[0]; RetData[1]=0x03; RetData[2]=Wlen*2; read_dgusii_vp(BegAddr,&RetData[3],Wlen); CRC_1=CalcCrcAll(0xFFFF,RetData,3+Wlen*2); RetData[Wlen*2+3]=CRC_1; RetData[Wlen*2+3+1]=CRC_1>>8; SendModbusAckOK(RetData,3+Wlen*2+2); } elseif(Tdata[1]==0x10) { memcpy(RetData,Tdata,6); CRC_1=CalcCrcAll(0xFFFF,(INT8U*)&RetData,6); RetData[6]=CRC_1; RetData[7]=CRC_1>>8; SendModbusAckOK(RetData,8); } elseif(Tdata[1]==0x06 && Tdata[0]) //当地址码为真,才应答 { memcpy(RetData,Tdata,8); SendModbusAckOK(RetData,8); }
returntrue; }
指纹识别使用了STM32的串口和指纹模块通信,部分代码如下:
void CheckFingerIn(void) { static u8 FingerST=0;
if(!CanFingerEn) { FingerST=0;
if(FingeTouchOn) { LockDMTTipSend("指纹注册状态下,只有用密码"); } return; }
if(FingeTouchOn && !FingerST && DmtDataBuf[MPageid][1]==9) { FingerST=1; FingerEven=FingerIdentify; } else if(!FingeTouchOn && FingerST) { FingerST=0; } }
void Init_Fingerpara(void) { SysPara P; u16 TeNum=0; u8 i=0; u8 FingerOk=0;
ZWPwr=1; ZWPwr_Flag=1; Delay_ms(1000);
FingerEven=FingerNull;
for(i=0;i<5;i++) { if(PS_HandShake(&FppassAddr)!=0) { FingerOk=0; Delay_ms(1000); } else { FingerOk=1; break; } }
if(FingerOk==0) //握手失败 { DevERR_TORecord(Dev_Finger); while(1) { Delay_ms(1000); } }
PS_ReadSysPara(&P); }
void EvenHandle(void) { if(FingerEven==FingerNull) return;
if(!ZWPwr_Flag) { ZWPwr=1; ZWPwr_Flag=1; delay_ms(1500); }
PwrFingerCountTime=0;
switch(FingerEven) { case FingerEnroll: { if(FingerToFlashNUM!=0xffff) { if(PS_AutoEnroll(FingerToFlashNUM)==0) FingerEnroolOK=1; else FingerEnroolOK=2; } } break;
case FingerIdentify: { if(PS_AutoIdentify(0xffff)==0) FingerSecreatOK=1; else FingerSecreatOK=0;
if(FingerSecreatOK) { FingerTipSend(" 指纹识别成功"); } else FingerTipSend(" 非法指纹");
PS_ControlBLN(BreatheLed,CloseAllLed,0,0,0); } break;
default: break; }
FingerEven=FingerNull; }
//0:成功 0xff:等待超时
u8 PS_AutoEnroll(u16 Flash_ID)
{
u8 *data;
u8 ensure=0xff;
u8 Par1=0,Par2=0;
u8 FingerCountTimesOut=0;
AutoEnrollCmd(Flash_ID,0x09,GetFingerTimes);
// AutoEnrollCmd(Flash_ID,0x0029,GetFingerTimes); //不要求离开
data=JudgeStr(3000);
if(data) //发送自动注册成功
{
ensure=data[9];
Par1=data[10];
Par2=0;
if(ensure!=0)
{
printffinger2((u8 *)EnsureMessage(ensure),(u8 *)AutoEnrollPar1(Par1),(u8 *)AutoEnrollPar2(Par2));
return 0xff;
}
}
else
{
return 0xff;
}
// printffinger("请手指按下");
while(1)
{
data=JudgeStr(1500);
if(data)
{
FingerCountTimesOut=0;
ensure=data[9];
Par1=data[10];
Par2=data[11];
printffinger2((u8 *)EnsureMessage(ensure),
(u8 *)AutoEnrollPar1(Par1),(u8 *)AutoEnrollPar2(Par2));
if(Par2<=GetFingerTimes)
{
if(!ensure && Par1==2 && Par2!=GetFingerTimes)
{
printffinger("请手指离开");
}
if(!ensure && Par1==3)
{
printffinger("请手指按下");
}
if(ensure == 0x26)
{
printffinger("超时退出");
return 0x26;
}
}
else
{
if(ensure==0x0a && Par1==0x04 && Par2==0xf0)
{
printffinger("合成失败");
return 0xff;
}
if(ensure)
return 0xff;
if(!ensure && Par1==0x06&&Par2==0xf2)
return 0;
}
}
else
{
FingerCountTimesOut++;
if(FingerCountTimesOut>5)
return 0xff;
}
}
}
u8 PS_AutoIdentify(u16 Flash_ID)
{
u8 *data;
u8 ensure=0xff;
u8 Par1=0;
// u8 FingerTimesOK=0;
AutoIdentifyCmd(Flash_ID,0x02,1);
data=JudgeStr(3000);
if(data) //发送自动识别成功
{
ensure=data[9];
Par1=data[10];
if(ensure!=0)
{
LockDMTTipSend((u8 *)EnsureMessage(ensure));
return 0xff;
}
}
else
{
return 0xff;
}
LockDMTTipSend("正在检测指纹");
while(1)
{
data=JudgeStr(2000);
if(data)
{
ensure=data[9];
Par1=data[10];
if(ensure)
{
LockDMTTipSend((u8 *)EnsureMessage(ensure));
return 0xff;
}
if(!ensure && Par1==05)
{
return 0;
}
}
else
return 0xff;
}
}
|