#include "D:\BIOMETRICO\main.h"
#include "D:\BIOMETRICO\24512_B.c"
#include "D:\BIOMETRICO\KEY_B.c"
#include "D:\BIOMETRICO\LCD_B.c"
#include "D:\BIOMETRICO\DS1302_B.c"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlibm.h>
#include "input.c"
/*#use fast_io (C)
#use fast_io (A)
#use fast_io (G)*/
#priority RDA,RDA2
char buffer[822];
char cadena[819];
char buffer2[7];
char c,d;
unsigned long cont=0;
int8 cont_GPRS=0;
char cadena2[7];
int1 flg_mensaje=0,flg_GPRS=0;
char Codigo[5]=" ";
int1 flg_mensaje2=0;
char *digito;
char hora[2];
char minuto[2];
char dia[2];
char mes[2];
char a_o[2];
char a_o1[2];
char opcion;
int1 Flag=0; // Flag que cambia cada NInts interrupciones
unsigned long i,j,length;
int8 m,len;
int iresult=1;
int iresult1=1;
int x;
char HS[5] = {"2101"};
char HM[5] = {"2102"};
char HE[5] = {"2103"};
char HR[5] = {"2199"};
byte day,mth,year,dow,hour,min,sec;
#int_RDA
void RDA_isr(void)
{
disable_interrupts(INT_RDA2);
c=0;
c=getc();
buffer[cont++]=c;
if(c==0xf2){
cont=0x00;
flg_mensaje=1;
clear_interrupt(INT_RDA);
clear_interrupt(INT_RDA2);
enable_interrupts(INT_RDA2);
}
}
#int_RDA2
void RDA2_isr(void)
{
disable_interrupts(INT_RDA);
d=0;
d=fgetc(GPRS);
buffer2[cont_GPRS++]=d;
if(d=='C'){
cont_GPRS=0x00;
flg_GPRS=1;
clear_interrupt(INT_RDA2);
clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
}
}
void main()
{
disable_interrupts(Global);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
disable_interrupts(INT_RDA);
disable_interrupts(INT_RDA2);
disable_interrupts(GLOBAL);
set_tris_b(0x00);
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_a(0b00100000);
set_tris_c(0b10000000);
set_tris_g(0b00000100);
lcd_init();
rtc_init();
teclado_init();
dow=1;
digito=malloc(819);
while (TRUE) {
Menu:
lcd_putc('\f');
printf(lcd_putc," IDENTIFIQUESE: ");
rtc_get_date( day, mth, year, dow);
rtc_get_time( hour, min, sec );
lcd_putc('\n');
printf(lcd_putc,"%02u:%02u %02u-%02u-20%02u",hour,min,day,mth,year);
InitBuffer();
output_high(pin_d0);
output_high(pin_d1);
output_high(pin_d2);
output_low(pin_d3);
printf("ñ021DD7ò");
//enable_interrupts(GLOBAL);
//enable_interrupts(INT_RDA);
//enable_interrupts(INT_RDA2);
delay_ms(2000);
do{
if(flg_mensaje){
disable_interrupts(INT_RDA);
length=strlen(buffer);
if(length==822){
Alarma();
digito=InitBuffer1(819,digito);
j=0;
for(i=11;i<(819);i++){
digito[j]=buffer;
j++;
}
fprintf(GPRS,"%S-20%02u%02u%02u %02u:%02u:%02u\r\n",digito,year,mth,day,hour,min,sec);
fprintf(PC,"%S-20%02u%02u%02u %02u:%02u:%02u\r\n",digito,year,mth,day,hour,min,sec);
lcd_putc('\f');
lcd_putc(" HUELLA ENVIADA ");
lcd_putc('\n');
printf(lcd_putc,"%02u:%02u %02u-%02u-20%02u",hour,min,day,mth,year);
delay_ms(500);
do{
if(flg_GPRS){
disable_interrupts(INT_RDA2);
len=strlen(buffer2);
InitBufferRX2();
for(m=0;m<len;m++){
cadena2[m]=buffer2[m];
}
lcd_putc('\f');
lcd_putc(" PROCESANDO ");
lcd_putc('\n');
lcd_putc(" DATO ");
delay_ms(800);
iresult = strncmp (cadena2,HS,4);
iresult1 = strncmp (cadena2,HM,4);
if (iresult==0 || iresult1==0 ){
lcd_putc('\f');
lcd_putc(" CODIGO: ");
lcd_putc('\n');
delay_ms(300);
for(m=0;m<len;m++){
if (cadena2[m]=='-'){
for(x=0;x<4;x++){
codigo[x]=cadena2[m];
if (x==0)
printf(lcd_putc," %c ",codigo[x]);
if (x==1)
printf(lcd_putc," %c ",codigo[x]);
if (x==2)
printf(lcd_putc," %c ",codigo[x]);
if (x==3)
printf(lcd_putc," %c ",codigo[x]);
delay_ms(300);
m++;
}
}
}
/*lcd_putc('\f');
lcd_putc(" CODIGO: ");
lcd_putc('\n');
printf(lcd_putc," %S ",codigo);*/
delay_ms(1000);
Alarma();
iresult=1;
iresult1=1;
}else{
iresult = strncmp (cadena2,HE,4);
iresult1 = strncmp (cadena2,HR,4);
if(iresult==0 || iresult1==0){
output_bit (pin_B5, 1);
delay_ms(1500);
lcd_putc('\f');
lcd_putc(" IDENTIFIQUESE: ");
lcd_putc('\n');
lcd_putc(" NUEVAMENTE ");
delay_ms(1000);
}
}
flg_mensaje2=1;
flg_GPRS=0;
enable_interrupts(INT_RDA2);
}else{
flg_mensaje2=0;
}
}while(flg_mensaje2!=1);
}
flag=1;
flg_mensaje=0;
enable_interrupts(INT_RDA);
}else{
flag=0;
}
}while(flag!=1);
flag=0;