#include <htc.h>
#include <stdio.h>
#include "Includes.h"
//------------------------------------------------------------FUSE CONFIGURATION ----------------------------------------
__CONFIG(1, HSPLL);
__CONFIG(2, BORDIS & PWRTDIS & WDTDIS & PBADDIS);
__CONFIG(3, CCP2RC1 & MCLREN);
__CONFIG(4, DEBUGEN & LVPDIS & STVREN);
__CONFIG(5, UNPROTECT);
//------------------------------------------------------------FUNCTION DECLARATION FREQUENCY ----------------------------------------
void interrupt ISR(void);
void PORTs_init(void);
//------------------------------------------------------------XTAL FREQUENCY ----------------------------------------
#define _XTAL_FREQ 32000000 //this is 4x8Mhz because of the PLL Enable
//------------------------------------------------------------GLOBAL VARIABLE DECLARATION----------------------------------------
char Reply[20]="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
int Finger_Detect;
char temp;
char a[5]="\0\0\0\0\0";
char buf[10]="";
void PORTs_init(void)
{
TRISC =0x81;
PORTC =0x7E;
}
//------------------------------------------------------------BIO-INPUT RELATED FUNCTION----------------------------------------
unsigned int Finger_PROESS()
{
for(int i=1;i<=12;i++){ //this loop to fill the buffer with null values precaution
Reply[i]=33;
}
check:
FingerDetectR305();
for(int i=1;i<=12;i++){
Reply[i]=ReceiveByteSerially();
}
switch(Reply[10]){
case 0x00:
for(int i=1;i<=12;i++){
Reply[i]=33;
}
break;
default:
for(int i=1;i<=12;i++){
Reply[i]=33;
}
goto check;
break;
}
FingerStore1R305();
for(int i=1;i<=12;i++){
Reply[i]=ReceiveByteSerially();
}
switch(Reply[10]){
case 0x00:
break;
default:
for(int i=1;i<=12;i++){
Reply[i]=ReceiveByteSerially();
}
goto check;
break;
}
SearchLibR305();
for(int i=1;i<=12;i++){
Reply[i]=ReceiveByteSerially();
}
switch(Reply[10]){
case 0x00:
switch(Reply[12]){
case 0x00:
for(int i=1;i<=12;i++){
Reply[i]=33;
}
return 1;
break;
case 0x01:
for(int i=1;i<=12;i++){
Reply[i]=33;
}
return 2;
break;
case 0x02:
for(int i=1;i<=12;i++){
Reply[i]=3;
}
return 3;
break;
break;
default:
for(int i=1;i<=12;i++){
Reply[i]=3;
}
return 9;
goto check;
break;
}
}
}
//------------------------------------------------------------MAIN PROGRAM RELATED FUNCTION----------------------------------------
main(void)
{
unsigned int USER_DETECT;
PORTs_init();
InitUART();
while(1)
{
USER_DETECT=Finger_PROESS(); //this return the ID of the matched user
for(int i=1;i<=12;i++){
Reply[i]=0;
}
switch(USER_DETECT){
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
}