Anda di halaman 1dari 45

CONTROL DE ACCESO NEIDY JENNIFER RICARDO GUZMAN GABRIEL SANTACOLOMA MENDEZ Universidad Militar Nueva Granada U1801722@unimilitar.edu.co U1801733@unimilitar.edu.

co

Resumen: Programaremos un microcontrolador para realizar un control de acceso ingresando con contrasea de 4 dgitos que permita almacenar usuarios diferentes, debe contar con dos mdulos: administrador y usuario. Abstract: We will program a microcontroller to perform access control entering 4-digit password that lets you store different users, you must have two modules: administrator and user. 1.

Introduccin

Para llevar a cabo este laboratorio debemos usar el lenguaje de programacin C Sharp para realizar en el la interfaz grafica donde se encontrara el modulo administrados y el perfil de usuario y el lenguaje MPLAB en el cual se realizara el programa para el microcontrolador en el cual se darn las opciones para el modulo administrador y usuario; en el de administrador debern aparecer las opciones de crear usuario, cambiar contrasea, borrar usuario, desbloquear usuario; en el de usuario debe contener la opcin de cambiar contrasea. Si se ingresa la contrasea 3 veces errneamente deber sonar una alarma y aparecer un mensaje de error en la LCD al igual que cuando un usuario ingrese correctamente. Los datos ingresados por teclado sern transmitidos a la interfaz por medio de un cable de transmisin serial RS232. 2.

Objetivo

Desarrollar habilidades en el manejo de puertos de comunicacin por medio del microcontrolador 18F4550.

3.

Desarrollo Programa MPLAB

#include <p18F4550.h> //libreria del microcontrolador #include <adc.h> //libreria usada para hacer la conversin anloga digital, esta tiene las funciones necesarias
para las configuraciones y lectura de dicho mdulo.

#include <delays.h>
//librera de retardos

#include <usart.h>
// Librera necesaria para la comunicacin serial, con esta librera se configura el modo de transmisin y recepcin serie de nuestro microcontrolador.

#include <xlcd.h>
// Librera de la LCD

#pragma config WDT=OFF


//Configuracin de el fuse watchdog timer handling del microcontrolador que debe estar apagado durante el arranque del programa

Void DelayFor18TCY (void) {Delay10TCYx(2);} Void DelayPORXLCD (void) {Delay1KTCYx(15);} Void DelayXLCD (void) {Delay1KTCYx(5);} // Funciones de retardos para la LCD float conversion; int contra; //Barrido Teclado int teclado(void) { while(1) { int j,i=0; for (j=0,i=1;i<=8;i=i*2,j=j+3) { PORTD=i; if(i==8)j=j*0-2; if(PORTDbits.RD4==1){PORTD=0;return (j+1);} else if(PORTDbits.RD5==1){PORTD=0;return (j+2);} else if(PORTDbits.RD6==1){PORTD=0;return (j+3);} else if(PORTDbits.RD7==1){PORTD=0;return (13);}}}}

void desbloq(void)//Funcion Desbloquear { int c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;//Variables para ingresar la cedula del usuario int a=1; OpenUSART(USART_EIGHT_BIT & USART_ASYNCH_MODE USART_CONT_RX & USART_BRGH_HIGH,25); &

// Esta funcin corresponde a la configuracin del mdulo USART, asincrnica o sincrnica, 8 bits o 9 bits, velocidad de comunicacin, etc.

SetDDRamAddr(0x0f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); //Limpia la Pantalla SetDDRamAddr(0x0f); putrsXLCD("Digite la Cedula"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" del usuario a"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" desbloquear"); Delay10KTCYx(90); SetDDRamAddr(0x44); putrsXLCD(":deC"); Delay10KTCYx(90); c1: c1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x45); WriteDataXLCD(0x30+c1); c2: c2=teclado(); PORTD=0; Delay10KTCYx(20); if(c2==13) {goto c1;} SetDDRamAddr(0x46); WriteDataXLCD(0x30+c2);

c3: c3=teclado(); PORTD=0; Delay10KTCYx(20); if(c3==13) {goto c2;} SetDDRamAddr(0x47); WriteDataXLCD(0x30+c3); c4: c4=teclado(); PORTD=0; Delay10KTCYx(20); if(c4==13) {goto c3;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+c4); c5: c5=teclado(); PORTD=0; Delay10KTCYx(20); if(c5==13) {goto c4;} SetDDRamAddr(0x49); WriteDataXLCD(0x30+c5); c6: c6=teclado(); PORTD=0; Delay10KTCYx(20); if(c6==13) {goto c5;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+c6); c7: c7=teclado(); PORTD=0; Delay10KTCYx(20); if(c7==13) {goto c6;} SetDDRamAddr(0x4b); WriteDataXLCD(0x30+c7); c8: c8=teclado(); PORTD=0; Delay10KTCYx(20); if(c8==13) {goto c7;} SetDDRamAddr(0x4c);

WriteDataXLCD(0x30+c8); c9: c9=teclado(); PORTD=0; Delay10KTCYx(20); if(c9==13) {goto c8;} SetDDRamAddr(0x4d); WriteDataXLCD(0x30+c9); c10: c10=teclado(); PORTD=0; Delay10KTCYx(20); if(c10==13) {goto c9;} SetDDRamAddr(0x4e); WriteDataXLCD(0x30+c10); Delay10KTCYx(100); //Transmicion de Cedula WriteUSART(c1);//Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(c2); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c4); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c5); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c6); while(BusyUSART()); Delay100TCYx(18);

WriteUSART(c7); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c8); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c9); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c10); while(BusyUSART()); Delay100TCYx(18); }

void cambiarcontr(void)//Funcion de Cambiar Contrasea { int c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;//Variables para ingresar la cedula int a=1; OpenUSART(USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_CONT_RX & USART_BRGH_HIGH,25);
// Esta funcin corresponde a la configuracin del mdulo USART, asincrnica o sincrnica, 8 bits o 9 bits, velocidad de comunicacin, etc.

SetDDRamAddr(0x0f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x0f); putrsXLCD("Digit el ID"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD("del usuario para"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD("cambiar la clave"); Delay10KTCYx(90);

SetDDRamAddr(0x44); putrsXLCD("Ced:"); Delay10KTCYx(40); c1: c1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x45); WriteDataXLCD(0x30+c1); c2: c2=teclado(); PORTD=0; Delay10KTCYx(20); if(c2==13) {goto c1;} SetDDRamAddr(0x46); WriteDataXLCD(0x30+c2); c3: c3=teclado(); PORTD=0; Delay10KTCYx(20); if(c3==13) {goto c2;} SetDDRamAddr(0x47); WriteDataXLCD(0x30+c3); c4: c4=teclado(); PORTD=0; Delay10KTCYx(20); if(c4==13) {goto c3;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+c4); c5: c5=teclado(); PORTD=0; Delay10KTCYx(20); if(c5==13) {goto c4;} SetDDRamAddr(0x49); WriteDataXLCD(0x30+c5); c6: c6=teclado(); PORTD=0; Delay10KTCYx(20); if(c6==13)

{goto c5;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+c6); c7: c7=teclado(); PORTD=0; Delay10KTCYx(20); if(c7==13) {goto c6;} SetDDRamAddr(0x4b); WriteDataXLCD(0x30+c7); c8: c8=teclado(); PORTD=0; Delay10KTCYx(20); if(c8==13) {goto c7;} SetDDRamAddr(0x4c); WriteDataXLCD(0x30+c8); c9: c9=teclado(); PORTD=0; Delay10KTCYx(20); if(c9==13) {goto c8;} SetDDRamAddr(0x4d); WriteDataXLCD(0x30+c9); c10: c10=teclado(); PORTD=0; Delay10KTCYx(20); if(c10==13) {goto c9;} SetDDRamAddr(0x4e); WriteDataXLCD(0x30+c10); Delay10KTCYx(100); //Transmicion de Cedula WriteUSART(c1); //Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(c2); while(BusyUSART()); Delay100TCYx(18);

WriteUSART(c3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c4); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c5); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c6); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c7); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c8); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c9); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c10); while(BusyUSART()); Delay100TCYx(18);}

void borraru(void) { int c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;//Variables para ingresar la cedula int a=1; OpenUSART(USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_CONT_RX & USART_BRGH_HIGH,25);
// Esta funcin corresponde a la configuracin del mdulo USART, asincrnica o sincrnica, 8 bits o 9 bits, velocidad de comunicacin, etc.

SetDDRamAddr(0x0f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x0f); putrsXLCD("Digite la cedula"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" del usuario que ") Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" quiere eliminar"); Delay10KTCYx(90); SetDDRamAddr(0x44); putrsXLCD("Ced:"); Delay10KTCYx(90); c1: c1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x45); WriteDataXLCD(0x30+c1); c2: c2=teclado(); PORTD=0; Delay10KTCYx(20); if(c2==13) {goto c1;} SetDDRamAddr(0x46); WriteDataXLCD(0x30+c2); c3: c3=teclado(); PORTD=0; Delay10KTCYx(20); if(c3==13) {goto c2;} SetDDRamAddr(0x47); WriteDataXLCD(0x30+c3); c4: c4=teclado(); PORTD=0; Delay10KTCYx(20);

if(c4==13) {goto c3;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+c4); c5: c5=teclado(); PORTD=0; Delay10KTCYx(20); if(c5==13) {goto c4;} SetDDRamAddr(0x49); WriteDataXLCD(0x30+c5); c6: c6=teclado(); PORTD=0; Delay10KTCYx(20); if(c6==13) {goto c5;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+c6); c7: c7=teclado(); PORTD=0; Delay10KTCYx(20); if(c7==13) {goto c6;} SetDDRamAddr(0x4b); WriteDataXLCD(0x30+c7); c8: c8=teclado(); PORTD=0; Delay10KTCYx(20); if(c8==13) {goto c7;} SetDDRamAddr(0x4c); WriteDataXLCD(0x30+c8); c9: c9=teclado(); PORTD=0; Delay10KTCYx(20); if(c9==13) {goto c8;} SetDDRamAddr(0x4d); WriteDataXLCD(0x30+c9); c10: c10=teclado(); PORTD=0;

Delay10KTCYx(20); if(c10==13) {goto c9;} SetDDRamAddr(0x4e); WriteDataXLCD(0x30+c10); Delay10KTCYx(100); //Transmicion de Cedula WriteUSART(c1); //Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(c2); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c4); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c5); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c6); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c7); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c8); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c9); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c10); while(BusyUSART()); Delay100TCYx(18);}

void usuario(void) { int c1,c2,c3,c4,c5,c6,c7,c8,c9,c10;//Variables para ingresar la cedula int a,entrada; int con1,con2,con3,con4,cl1,cl2,cl3,cl4;//variables para ingreso de contrasea int clave,contador,clave2; OpenUSART(USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_CONT_RX & USART_BRGH_HIGH,25);
// Esta funcin corresponde a la configuracin del mdulo USART, asincrnica o sincrnica, 8 bits o 9 bits, velocidad de comunicacin, etc.

SetDDRamAddr(0x0f); putrsXLCD(" MENU USUARIO "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" Ingrese ID "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x44); putrsXLCD("Ced:"); Delay10KTCYx(90); c1: c1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x45); WriteDataXLCD(0x30+c1); c2: c2=teclado(); PORTD=0; Delay10KTCYx(20); if(c2==13) {goto c1;} SetDDRamAddr(0x46); WriteDataXLCD(0x30+c2); c3: c3=teclado(); PORTD=0; Delay10KTCYx(20); if(c3==13)

{goto c2;} SetDDRamAddr(0x47); WriteDataXLCD(0x30+c3); c4: c4=teclado(); PORTD=0; Delay10KTCYx(20); if(c4==13) {goto c3;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+c4); c5: c5=teclado(); PORTD=0; Delay10KTCYx(20); if(c5==13) {goto c4;} SetDDRamAddr(0x49); WriteDataXLCD(0x30+c5); c6: c6=teclado(); PORTD=0; Delay10KTCYx(20); if(c6==13) {goto c5;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+c6); c7: c7=teclado(); PORTD=0; Delay10KTCYx(20); if(c7==13) {goto c6;} SetDDRamAddr(0x4b); WriteDataXLCD(0x30+c7); c8: c8=teclado(); PORTD=0; Delay10KTCYx(20); if(c8==13) {goto c7;} SetDDRamAddr(0x4c); WriteDataXLCD(0x30+c8); c9: c9=teclado(); PORTD=0; Delay10KTCYx(20);

if(c9==13) {goto c8;} SetDDRamAddr(0x4d); WriteDataXLCD(0x30+c9); c10: c10=teclado(); PORTD=0; Delay10KTCYx(20); if(c10==13) {goto c9;} SetDDRamAddr(0x4e); WriteDataXLCD(0x30+c10); Delay10KTCYx(100); //Transmicion de Cedula WriteUSART(c1); //Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(c2); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c4); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c5); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c6); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c7); while(BusyUSART()); Delay100TCYx(18); WriteUSART(c8); while(BusyUSART()); Delay100TCYx(18);

WriteUSART(c9); while(BusyUSART());Delay100TCYx(18); WriteUSART(c10); while(BusyUSART()); Delay100TCYx(18); while(!DataRdyUSART());clave=ReadUSART(); // DataRdyUSART();esta sirve para detectar si hay algun dato en el buffer de recepcin
// ReadUSART(); lee un byte del buffer de recepcin

if(clave == 5) { TRISA=0; SetDDRamAddr(0x0f); putrsXLCD(" Usuario "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" Encontrado "); Delay10KTCYx(90); PORTEbits.RE2=1; Delay10KTCY(20); SetDDRamAddr(0x0f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x0f); putrsXLCD(" MENU USUARIO "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" Ingrese Clave "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(90); SetDDRamAddr(0x46); putrsXLCD("Clave:"); Delay10KTCYx(40); con1: con1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x47);

WriteDataXLCD(0x30+con1); con2: con2=teclado(); PORTD=0; Delay10KTCYx(20); if(con2==13) {goto con1;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+con2); con3: con3=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x49); WriteDataXLCD(0x30+con3); con4: con4=teclado(); PORTD=0; Delay10KTCYx(20); if(con4==13) {goto con3;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+con4); WriteUSART(con1); //Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(con2); while(BusyUSART()); Delay100TCYx(18); WriteUSART(con3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(con4); while(BusyUSART()); Delay100TCYx(18); while(!DataRdyUSART());clave=ReadUSART(); // DataRdyUSART();esta sirve para detectar si hay algun dato en el buffer de recepcin
// ReadUSART(); lee un byte del buffer de recepcin

if(contador== 5)//Este dato se envia para compar con lo que hay en la interfaz

{ SetDDRamAddr(0x0f); putrsXLCD(" Clave Valida "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" Bienv. Usuario"); Delay10KTCYx(90); PORTEbits.RE2=1; Delay10KTCYx(100); PORTEbits.RE2=0; } else { SetDDRamAddr(0x0f); putrsXLCD(" Clave Invalida "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD("Digitela de Nuevo"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" "); Delay1KTCYx(60); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay1KTCYx(60); SetDDRamAddr(0x46); putrsXLCD("Clave:"); Delay10KTCYx(40); cl1: cl1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x47); WriteDataXLCD(0x30+cl1); cl2: cl2=teclado(); PORTD=0; Delay10KTCYx(20); if(cl2==13) {goto cl1;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+cl2); cl3: cl3=teclado(); PORTD=0;

Delay10KTCYx(20); SetDDRamAddr(0x49); WriteDataXLCD(0x30+cl3); cl4: cl4=teclado(); PORTD=0; Delay10KTCYx(20); if(cl4==13) {goto cl3;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+cl4); WriteUSART(cl1); //Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(cl2); while(BusyUSART()); Delay100TCYx(18); WriteUSART(cl3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(cl4); while(BusyUSART()); Delay100TCYx(18); while(!DataRdyUSART());clave=ReadUSART(); // DataRdyUSART();esta sirve para detectar si hay algun dato en el buffer de recepcin
// ReadUSART(); lee un byte del buffer de recepcin

if(clave2== 5) { SetDDRamAddr(0x0f); putrsXLCD(" Clave Valida "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" Bienv. Usuario"); Delay10KTCYx(90); PORTEbits.RE2=1; Delay10KTCYx(100); PORTEbits.RE2=0; } else

{ SetDDRamAddr(0x0f); putrsXLCD(" Clave Invalida "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD("Digitela de Nuevo"); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" "); Delay1KTCYx(60); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay1KTCYx(60); SetDDRamAddr(0x46); putrsXLCD("Clave:"); Delay10KTCYx(40); cl1: cl1=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x47); WriteDataXLCD(0x30+cl1); cl2: cl2=teclado(); PORTD=0; Delay10KTCYx(20); if(cl2==13) {goto cl1;} SetDDRamAddr(0x48); WriteDataXLCD(0x30+cl2); cl3: cl3=teclado(); PORTD=0; Delay10KTCYx(20); SetDDRamAddr(0x49); WriteDataXLCD(0x30+cl3); cl4: cl4=teclado(); PORTD=0; Delay10KTCYx(20); if(cl4==13) {goto cl3;} SetDDRamAddr(0x4a); WriteDataXLCD(0x30+cl4);

WriteUSART(cl1); //Funcin de escritura para enviar a la interfaz while(BusyUSART());//Esta funcion muestra el envio de la pic a la interfaz Delay100TCYx(18); WriteUSART(cl2); while(BusyUSART()); Delay100TCYx(18); WriteUSART(cl3); while(BusyUSART()); Delay100TCYx(18); WriteUSART(cl4); while(BusyUSART()); Delay100TCYx(18); while(!DataRdyUSART());clave=ReadUSART(); // DataRdyUSART();esta sirve para detectar si hay algun dato en el buffer de recepcin
// ReadUSART(); lee un byte del buffer de recepcin

if(clave3== 5 ) { SetDDRamAddr(0x0f); putrsXLCD(" Clave Valida "); Delay10KTCYx(60); SetDDRamAddr(0x4f); putrsXLCD(" Bienv. Usuario"); Delay10KTCYx(90); } else { SetDDRamAddr(0x0f); putrsXLCD("Error,usuario "); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" BLOQUEADO "); Delay10KTCYx(90); TRISE=0; PORTEbits.RE2=1; Delay10KTCYx(50); }}} else { SetDDRamAddr(0x0f);putrsXLCD(" Usuario "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" No Encontrado "); Delay10KTCYx(90);}}

void admin (void)//Funcin para ingresar como administrador { int i,j,k,l,x,y,z,v; SetDDRamAddr(0x0f); putrsXLCD("Bienvenido ADM"); Delay10KTCYx(100); SetDDRamAddr(0x4f); putrsXLCD("Ingrese su clave"); Delay10KTCYx(80); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x47); putrsXLCD("Clave:"); Delay10KTCYx(80); i=teclado(); Delay10KTCYx(20); SetDDRamAddr(0x49); WriteDataXLCD (i+0x30); j=teclado(); Delay10KTCYx(20); SetDDRamAddr(0x4a); WriteDataXLCD (j+0x30); k=teclado(); Delay10KTCYx(20); SetDDRamAddr(0x4b); WriteDataXLCD (k+0x30); l=teclado(); Delay10KTCYx(20); SetDDRamAddr(0x4c); WriteDataXLCD (l+0x30); x=((i*1000)+(j*100)+(k*10)+l); if(x==0612) { SetDDRamAddr(0x0f); putrsXLCD(" Menu ADM "); Delay10KTCYx(90); SetDDRamAddr(0x4f);

putrsXLCD(" 1.Desbloquear"); Delay10KTCYx(120); SetDDRamAddr(0x4f); putrsXLCD("2.Cambiar Clave"); Delay10KTCYx(120); SetDDRamAddr(0x4f); putrsXLCD("3.Borrar Usuario"); Delay10KTCYx(120); y=teclado(); switch(y) { case 1:Delay10KTCYx(20),desbloq(); } switch(y) { case 2:Delay10KTCYx(20),cambiarcontr(); } switch(y) { case 3:Delay10KTCYx(20),borraru(); } } else { SetDDRamAddr(0x0f); putrsXLCD(" Error "); Delay10KTCYx(90); SetDDRamAddr(0x4f); putrsXLCD(" Clave Invalida "); Delay10KTCYx(90); SetDDRamAddr(0x0f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); }

void main() { int a,b,t=0; ADCON1=15; TRISD=0xF0; PORTA=0; TRISA=0x00; TRISE=0x00; OpenUSART(USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_CONT_RX & USART_BRGH_HIGH,25);
// Esta funcin corresponde a la configuracin del mdulo USART, asincrnica o sincrnica, 8 bits o 9 bits, velocidad de comunicacin, etc.

OpenXLCD(FOUR_BIT & LINES_5X7); while(1) { SetDDRamAddr(0x0f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x4f); putrsXLCD(" "); Delay10KTCYx(10); SetDDRamAddr(0x0f); putrsXLCD("Access Control"); Delay10KTCYx(90); SetDDRamAddr(0x4a); putrsXLCD(" Gabriel S."); Delay10KTCYx(120); SetDDRamAddr(0x4a); putrsXLCD("Jennifer R."); Delay10KTCYx(120);

SetDDRamAddr(0x4a); putrsXLCD(" 1.Admin "); Delay10KTCYx(120); SetDDRamAddr(0x4a); putrsXLCD("2.Usuario"); Delay10KTCYx(120);

t=teclado(); if (t==1) { admin(); } else if (t==2) { usuario(); } else; } }

4.

Desarrollo Cdigo C#:

using using using using using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Drawing.Imaging; Libreras Necesarias para el desarrollo de las funciones System.Linq; System.Text; empleadas a continuacin System.Windows.Forms; System.Threading; System.Collections; System.IO;

using AForge.Video; using AForge.Video.DirectShow;

Libreras de la cmara

namespace ACCESO { public partial class Form1 : Form { private bool ExistenDispositivos = false; private FilterInfoCollection DispositivosDeVideo; private VideoCaptureDevice FuenteDeVideo = null;

//Funciones De Cmara

string n, a, c, contra, est, nueva; int cont, contar; int ced, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10; //variables para la adquisicin de cedula y contrasea int contra1, contra2, contra3, contra4,contratotal;

string[] string[] string[] string[]

name = new string[10]; password = new string[10]; ids = new string[10]; last = new string[10];

Variables que permiten guardar los valores ingresados desde

public static byte[] valor = { 0, 0 }; public Form1() { InitializeComponent(); Buscar(); } public void Cargar(FilterInfoCollection Dispositivos) { for (int i = 0; i < Dispositivos.Count; i++) combo.Items.Add(Dispositivos[i].Name.ToString()); combo.Text = combo.Items[0].ToString(); } public void Buscar() { DispositivosDeVideo = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (DispositivosDeVideo.Count == 0) Funcin que escoge el dispositivo ExistenDispositivos = false; else para las fotos de los usuarios { ExistenDispositivos = true; Cargar(DispositivosDeVideo); } } public void TerminarFuenteDeVideo() { if (!(FuenteDeVideo == null)) if (FuenteDeVideo.IsRunning) { FuenteDeVideo.SignalToStop(); FuenteDeVideo = null; } }

Funcin que cierra el dispositivo

private void video_NuevoFrame(object sender, NewFrameEventArgs eventArgs) { Bitmap Imagen = (Bitmap)eventArgs.Frame.Clone(); Pic.Image = Imagen; } private void button20_Click(object sender, EventArgs e) { cont = cont + 1; textBox7.Text = DateTime.Now.ToString("hh:mm:ss tt"); textBox6.Text = DateTime.Now.ToString("dd/MM/yyyy"); n = textBox1.Text; a = textBox2.Text;

c = textBox3.Text; contra = textBox4.Text; est = textBox5.Text;

StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + contra + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox8.Text = (" Registered !! "); textBox5.Text = (" Active User "); name[cont] = n; last[cont] = a; ids[cont] = c; password[cont] = contra; }

Permite Guardar los datos ingresados en la interfaz del usuario y la fecha y hora de su registro

private void button19_Click(object sender, EventArgs e) { textBox1.Text = (" "); textBox2.Text = (" "); textBox3.Text = (" "); textBox4.Text = (" "); Borra los datos anteriores para textBox5.Text = (" "); textBox6.Text = (" "); poder registrar un nuevo usuario textBox7.Text = (" "); textBox8.Text = (" "); } private void button18_Click(object sender, EventArgs e) { this.Close(); Cierra la ventana } private void button2_Click(object sender, EventArgs e) { // guardar cambios en los datos if (textBox13.Text == ids[1]) { contra = textBox11.Text; password[1] = contra; Registra el cambio de contrasea n = textBox15.Text; de un usuario desde teclado y lo c = textBox13.Text; guarda con los datos anteriores a = textBox14.Text; est = textBox10.Text; nueva = password[1]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close();

textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[2]) { contra = textBox11.Text; password[2] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[2]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[3]) { contra = textBox11.Text; password[3] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[3]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[4]) { contra = textBox11.Text; password[4] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[4]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[5]) { contra = textBox11.Text; password[5] = contra; n = textBox15.Text;

c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[5]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[6]) { contra = textBox11.Text; password[6] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[6]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[7]) { contra = textBox11.Text; password[7] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[7]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[8]) { contra = textBox11.Text; password[8] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[8]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt");

writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else if (textBox13.Text == ids[9]) { contra = textBox11.Text; password[9] = contra; n = textBox15.Text; c = textBox13.Text; a = textBox14.Text; est = textBox10.Text; nueva = password[9]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox9.Text = (" Saved!! "); } else { textBox9.Text = ("Unregistered User"); } } private void button3_Click(object sender, EventArgs e) { textBox15.Text = (" "); textBox14.Text = (" "); textBox13.Text = (" "); textBox12.Text = (" "); Inicializa de nuevo todos los valores textBox11.Text = (" "); y el cuadro de la contrasea textBox10.Text = (" "); aparece en 0 para poder recibir un textBox49.Text = ("0"); textBox9.Text = (" "); nuevo ingreso } private void button4_Click(object sender, EventArgs e) { this.Close(); } private void button1_Click(object sender, EventArgs e) { string datostring; serialPort1.Open(); c1 = serialPort1.ReadChar(); Thread.Sleep(20); c2 = serialPort1.ReadChar(); Thread.Sleep(20); c3 = serialPort1.ReadChar(); Thread.Sleep(20); c4 = serialPort1.ReadChar(); Thread.Sleep(20);

Recibe los datos enviados desde el pic para mostrarlos en la interfaz

c5 = serialPort1.ReadChar(); Thread.Sleep(20); c6 = serialPort1.ReadChar(); Thread.Sleep(20); c7 = serialPort1.ReadChar(); Thread.Sleep(20); c8 = serialPort1.ReadChar(); Thread.Sleep(20); c9 = serialPort1.ReadChar(); Thread.Sleep(20); c10 = serialPort1.ReadChar(); Thread.Sleep(20); serialPort1.Close(); ced = (c1 * 1000000000) + (c2 * 100000000) + (c3 * 10000000) + (c4 * 1000000) + (c5 * 100000) + (c6 * 10000) + (c7 * 1000) + (c8 * 100) + (c9 * 10) + c10; datostring = ced.ToString(); textBox49.Text = datostring; serialPort1.Close(); // llenado der casillas textBox13.Text = textBox49.Text;

if (textBox49.Text == ids[1]) { textBox15.Text = name[1]; textBox14.Text = last[1]; textBox12.Text = password[1]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[2]) { textBox15.Text = name[2]; textBox14.Text = last[2]; textBox12.Text = password[2]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[3]) { textBox15.Text = name[3]; textBox14.Text = last[3]; textBox12.Text = password[3]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[4]) { textBox15.Text = name[4]; textBox14.Text = last[4]; textBox12.Text = password[4]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[5]) { textBox15.Text = name[5]; textBox14.Text = last[5]; textBox12.Text = password[5]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[6]) { textBox15.Text = name[6]; textBox14.Text = last[6]; textBox12.Text = password[6]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[7]) { textBox15.Text = name[7]; textBox14.Text = last[7]; textBox12.Text = password[7]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[8]) { textBox15.Text = name[8]; textBox14.Text = last[8]; textBox12.Text = password[8]; textBox10.Text = ("Active User"); } else if (textBox49.Text == ids[9]) { textBox15.Text = name[9]; textBox14.Text = last[9]; textBox12.Text = password[9]; textBox10.Text = ("Active User"); } else { textBox9.Text = ("Unregistered User"); } } private void button7_Click(object sender, EventArgs e) { // guardar

if (textBox20.Text == ids[1]) { contra = textBox19.Text; password[1] = contra; n = textBox22.Text; c = textBox20.Text; a = textBox21.Text; est = textBox18.Text; nueva = password[1]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + c + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime" + textBox7.Text); writer.Close(); textBox17.Text = (" Changed!! "); } } private void button6_Click(object sender, EventArgs e) { textBox22.Text = (" "); textBox21.Text = (" "); textBox20.Text = (" "); textBox19.Text = (" "); textBox18.Text = (" "); textBox16.Text = ("0"); textBox17.Text = (" "); } private void button5_Click(object sender, EventArgs e) { this.Close(); } private void button8_Click(object sender, EventArgs e) { string datostring; serialPort1.Open(); c1 = serialPort1.ReadChar(); Thread.Sleep(20); c2 = serialPort1.ReadChar(); Thread.Sleep(20); c3 = serialPort1.ReadChar(); Thread.Sleep(20); c4 = serialPort1.ReadChar(); Thread.Sleep(20); c5 = serialPort1.ReadChar(); Thread.Sleep(20); c6 = serialPort1.ReadChar(); Thread.Sleep(20); c7 = serialPort1.ReadChar(); Thread.Sleep(20); c8 = serialPort1.ReadChar(); Thread.Sleep(20); c9 = serialPort1.ReadChar(); Thread.Sleep(20);

c10 = serialPort1.ReadChar(); Thread.Sleep(20); serialPort1.Close();

ced = (c1 * 1000000000) + (c2 * 100000000) + (c3 * 10000000) + (c4 * 1000000) + (c5 * 100000) + (c6 * 10000) + (c7 * 1000) + (c8 * 100) + (c9 * 10) + c10; datostring = ced.ToString(); textBox16.Text = datostring; serialPort1.Close(); // llenado der casillas textBox20.Text = textBox16.Text;

if (textBox16.Text == ids[1]) { textBox22.Text = name[1]; textBox21.Text = last[1]; textBox19.Text = password[1]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[2]) { textBox22.Text = name[2]; textBox21.Text = last[2]; textBox19.Text = password[2]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[3]) { textBox22.Text = name[3]; textBox21.Text = last[3]; textBox19.Text = password[3]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[4]) { textBox22.Text = name[4]; textBox21.Text = last[4]; textBox19.Text = password[4]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[5]) { textBox22.Text = name[5]; textBox21.Text = last[5]; textBox19.Text = password[5]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[6]) { textBox22.Text = name[6]; textBox21.Text = last[6]; textBox19.Text = password[6]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[7]) { textBox22.Text = name[7]; textBox21.Text = last[7]; textBox19.Text = password[7]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[8]) { textBox22.Text = name[8]; textBox21.Text = last[8]; textBox19.Text = password[8]; textBox18.Text = ("Active User"); } else if (textBox16.Text == ids[9]) { textBox22.Text = name[9]; textBox21.Text = last[9]; textBox19.Text = password[9]; textBox18.Text = ("Active User"); } else { textBox17.Text = ("Unregistered User"); } } private void button12_Click(object sender, EventArgs e) { // guardar if (textBox27.Text == ids[1]) { textBox26.Text = (" "); password[1] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ;

nueva = password[1]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[2]) { textBox26.Text = (" "); password[2] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[2]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[3]) { textBox26.Text = (" "); password[3] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[3]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[4]) { textBox26.Text = (" "); password[4] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ;

nueva = password[4]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[5]) { textBox26.Text = (" "); password[5] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[5]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[6]) { textBox26.Text = (" "); password[6] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[6]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[7]) { textBox26.Text = (" "); password[7] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[7];

StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[8]) { textBox26.Text = (" "); password[8] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[8]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } else if (textBox27.Text == ids[9]) { textBox26.Text = (" "); password[9] = (" "); textBox29.Text = (" "); ; textBox27.Text = (" "); ; textBox28.Text = (" "); ; textBox25.Text = (" "); ; nueva = password[9]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + (" Deleted ") + "\r\nName:" + (" Deleted ") + "\r\nLast:" + ("Deleted ") + "\r\nUser Status:" + (" Deleted ") + "\r\nPassword:" + (" Deleted") + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox23.Text = (" Deleted!!! "); } } private void button11_Click(object sender, EventArgs e) { textBox29.Text = (" "); textBox28.Text = (" "); textBox27.Text = (" "); textBox26.Text = (" "); textBox25.Text = (" "); textBox50.Text = ("0");

textBox23.Text = (" "); } private void button10_Click(object sender, EventArgs e) { this.Close(); } private void button9_Click(object sender, EventArgs e) { //Se recibe el dato desde el pic string datostring; serialPort1.Open(); c1 = serialPort1.ReadChar(); Thread.Sleep(20); c2 = serialPort1.ReadChar(); Thread.Sleep(20); c3 = serialPort1.ReadChar(); Thread.Sleep(20); c4 = serialPort1.ReadChar(); Thread.Sleep(20); c5 = serialPort1.ReadChar(); Thread.Sleep(20); c6 = serialPort1.ReadChar(); Thread.Sleep(20); c7 = serialPort1.ReadChar(); Thread.Sleep(20); c8 = serialPort1.ReadChar(); Thread.Sleep(20); c9 = serialPort1.ReadChar(); Thread.Sleep(20); c10 = serialPort1.ReadChar(); Thread.Sleep(20); serialPort1.Close(); ced = (c1 * 1000000000) + (c2 * 100000000) + (c3 * 10000000) + (c4 * 1000000) + (c5 * 100000) + (c6 * 10000) + (c7 * 1000) + (c8 * 100) + (c9 * 10) + c10; datostring = ced.ToString(); textBox50.Text = datostring; serialPort1.Close(); // llenado der casillas textBox27.Text = textBox50.Text;

if (textBox50.Text == ids[1]) { textBox29.Text = name[1]; textBox28.Text = last[1]; textBox26.Text = password[1]; textBox25.Text = ("Active User"); } else if (textBox50.Text == ids[2]) { textBox29.Text = name[2]; textBox28.Text = last[2]; textBox26.Text = password[2]; textBox25.Text = ("Active User"); } else if (textBox50.Text == ids[3]) { textBox29.Text = name[3]; textBox28.Text = last[3]; textBox26.Text = password[3]; textBox25.Text = ("Active User"); }

else textBox28.Text = User"); } else textBox28.Text = User"); } else textBox28.Text = User"); } else textBox28.Text = User"); } else textBox28.Text = User"); } else textBox28.Text = User"); }

if (textBox50.Text == ids[4]) { textBox29.Text = name[4]; last[4]; textBox26.Text = password[4]; textBox25.Text = ("Active if (textBox50.Text == ids[5]) { textBox29.Text = name[5]; last[5]; textBox26.Text = password[5]; textBox25.Text = ("Active if (textBox50.Text == ids[6]) { textBox29.Text = name[6]; last[6]; textBox26.Text = password[6]; textBox25.Text = ("Active if (textBox50.Text == ids[7]) { textBox29.Text = name[7]; last[7]; textBox26.Text = password[7]; textBox25.Text = ("Active if (textBox50.Text == ids[8]) { textBox29.Text = name[8]; last[8]; textBox26.Text = password[8]; textBox25.Text = ("Active if (textBox50.Text == ids[9]) { textBox29.Text = name[9]; last[9]; textBox26.Text = password[9]; textBox25.Text = ("Active

else { textBox23.Text = ("Unregistered User"); } } private void button17_Click(object sender, EventArgs e) { if (textBox33.Text == textBox37.Text) { if (textBox36.Text == ids[1]) { contra = textBox37.Text; password[1] = contra; n = textBox36.Text; c = textBox36.Text; a = textBox35.Text; est = textBox31.Text; nueva = password[1]; StreamWriter writer = new StreamWriter(@"C:\Users\Jennifer\database\" + textBox3.Text + ".txt"); writer.WriteLine("\r\nID:" + ced + "\r\nName:" + n + "\r\nLast Name:" + a + "\r\nUser Status:" + est + "\r\nPassword:" + nueva + "\r\nDate:" + textBox6.Text + "\r\nTime:" + textBox7.Text); writer.Close(); textBox17.Text = (" Saved!!! "); } } } private void button15_Click(object sender, EventArgs e) { this.Close(); } private void button16_Click(object sender, EventArgs e) { textBox32.Text = (" "); textBox30.Text = (" "); textBox31.Text = (" "); textBox33.Text = (" "); textBox34.Text = (" ");

textBox35.Text textBox36.Text textBox37.Text textBox38.Text textBox24.Text textBox51.Text

= = = = = =

(" "); (" "); ("0"); (" "); ("0"); (" ");

} private void button13_Click(object sender, EventArgs e) { //recibe los datos enviados desde el pic string datostring; serialPort1.Open(); c1 = serialPort1.ReadChar(); Thread.Sleep(20); c2 = serialPort1.ReadChar(); Thread.Sleep(20); c3 = serialPort1.ReadChar(); Thread.Sleep(20); c4 = serialPort1.ReadChar(); Thread.Sleep(20); c5 = serialPort1.ReadChar(); Thread.Sleep(20); c6 = serialPort1.ReadChar(); Thread.Sleep(20); c7 = serialPort1.ReadChar(); Thread.Sleep(20); c8 = serialPort1.ReadChar(); Thread.Sleep(20); c9 = serialPort1.ReadChar(); Thread.Sleep(20); c10 = serialPort1.ReadChar(); Thread.Sleep(20); serialPort1.Close(); ced = (c1 * 1000000000) + (c2 * 100000000) + (c3* 10000000) + (c4 * 1000000) + (c5 * 100000) + (c6 * 10000) + (c7 * 1000) + (c8 * 100) + (c9 * 10) + c10; datostring = ced.ToString(); textBox24.Text = datostring; serialPort1.Close(); // llenado der casillas textBox34.Text = textBox24.Text;

if (textBox24.Text == ids[1]) { textBox36.Text = name[1]; textBox35.Text = last[1]; textBox33.Text = password[1]; textBox31.Text = ("Active User"); } else if (textBox24.Text == ids[2]) { textBox36.Text = name[2]; textBox35.Text = last[2]; textBox33.Text = password[2]; textBox31.Text = ("Active User"); } else if (textBox24.Text == ids[3]) { textBox36.Text = name[3]; textBox35.Text = last[3]; textBox33.Text = password[3]; textBox31.Text = ("Active User"); }

else textBox35.Text = User"); } else textBox35.Text = User"); } else textBox35.Text = User"); } else textBox35.Text = User"); } else textBox35.Text = User"); } else textBox35.Text = User"); }

if (textBox24.Text == ids[4]) { textBox36.Text = name[4]; last[4]; textBox33.Text = password[4]; textBox31.Text = ("Active if (textBox24.Text == ids[5]) { textBox36.Text = name[5]; last[5]; textBox33.Text = password[5]; textBox31.Text = ("Active if (textBox24.Text == ids[6]) { textBox36.Text = name[6]; last[6]; textBox33.Text = password[6]; textBox31.Text = ("Active if (textBox24.Text == ids[7]) { textBox36.Text = name[7]; last[7]; textBox33.Text = password[7]; textBox31.Text = ("Active if (textBox24.Text == ids[8]) { textBox36.Text = name[8]; last[8]; textBox33.Text = password[8]; textBox31.Text = ("Active if (textBox24.Text == ids[9]) { textBox36.Text = name[9]; last[9]; textBox33.Text = password[9]; textBox31.Text = ("Active

else { textBox51.Text = ("Unregistered User"); } } private void button14_Click(object sender, EventArgs e) { contar = contar + 1; string datostring; serialPort1.Open(); contra1 = serialPort1.ReadChar(); Thread.Sleep(20); contra2 = serialPort1.ReadChar(); Thread.Sleep(20); contra3 = serialPort1.ReadChar(); Thread.Sleep(20); contra4 = serialPort1.ReadChar(); Thread.Sleep(20); serialPort1.Close(); contratotal = (contra1 * 1000) + (contra2 * 100) + (contra3 * 10) + contra4; datostring = contratotal.ToString(); textBox37.Text = datostring; serialPort1.Close(); if (textBox33.Text == textBox37.Text) { textBox51.Text = ("* Welcome-You Can Change your Password "); } else { textBox51.Text = ("Wrong Password- try again !!"); } if (contar == 3) { textBox51.Text = (" User Blocked !!"); } } private void button21_Click(object sender, EventArgs e) { if (button21.Text == "Iniciar")//Enciende la cmara { if (ExistenDispositivos) {

FuenteDeVideo = new VideoCaptureDevice(DispositivosDeVideo[combo.SelectedIndex].MonikerString); FuenteDeVideo.NewFrame += new NewFrameEventHandler(video_NuevoFrame); FuenteDeVideo.Start(); button21.Text = "Detener"; combo.Enabled = false; } } else { if (FuenteDeVideo.IsRunning) { TerminarFuenteDeVideo(); button21.Text = "Iniciar"; combo.Enabled = true; } } } private void button22_Click(object sender, EventArgs e) { Pic.Image.Save(@"C:\Users\Jennifer\database\" + textBox1.Text + ".JPG"); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (button21.Text == "Detener") button21_Click(sender, e); } private void textBox5_TextChanged(object sender, EventArgs e) { } private void button24_Click(object sender, EventArgs e) { if (textBox34.Text == ids[1]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[2]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[3])

{ textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[4]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[5]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[6]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[7]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else if (textBox34.Text == ids[8]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close();

} else if (textBox34.Text == ids[9]) { textBox39.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } else { textBox39.Text = ("8"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); } } private void button25_Click(object sender, EventArgs e) { int con1, con2, con3, con4, contrasea; string datostring; if (textBox33.Text == textBox37.Text) { textBox40.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); textBox51.Text = ("* Welcome- You can Change you Password "); textBox31.Text = (" Active User "); } else { textBox40.Text = ("9"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); textBox51.Text = (" Error, enter your password again "); textBox37.Text = ("0"); textBox40.Text = ("0"); serialPort1.Open(); con1 = serialPort1.ReadChar(); Thread.Sleep(20);

con2 = serialPort1.ReadChar(); Thread.Sleep(20); con3 = serialPort1.ReadChar(); Thread.Sleep(20); con4 = serialPort1.ReadChar(); Thread.Sleep(20); serialPort1.Close(); contrasea = (con1 * 1000) + (con2 * 100) + (con3 * 10) + con4; datostring = contrasea.ToString(); textBox37.Text = datostring; if (textBox33.Text == textBox37.Text) { textBox40.Text = ("5"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); textBox51.Text = ("* Welcome- You can Change you Password "); textBox31.Text = (" Active User "); } else { textBox40.Text = ("9"); serialPort1.Open(); valor[0] = Byte.Parse(textBox39.Text); serialPort1.Write(valor, 0, 1); Thread.Sleep(200); serialPort1.Close(); textBox51.Text textBox37.Text textBox36.Text textBox35.Text textBox34.Text textBox33.Text textBox32.Text textBox31.Text textBox30.Text textBox38.Text } = = = = = = = = = = (" Error, User Blocked "); ("0"); ("0"); ("0"); ("0"); ("0"); ("0"); ("0"); ("0"); ("0");

} } } }

5.

Conclusiones: Este laboratorio nos permiti emplear nuestros conocimientos sobre mplab y desarrollar una interfaz grafica a travs de la cual podemos disear controles de acceso de cualquier tipo. Se presentaron algunos inconvenientes a la hora de manejar los dispositivos de video y captura de fotos y al guardar las fotos capturadas, pero logro resolverse gracias a la ayuda del docente.