Beruflich Dokumente
Kultur Dokumente
h>
#device adc=10
#use delay (clock=4000000)
#fuses HS,XT,NOWDT,NOLVP,PUT
#use standard_io(a)
#use standard_io(b)
#use standard_io(d)
#define use_portb_kbd true
#define use_portd_lcd true
#include<lcd.c>
#include <kbd.c>
#include <stdlib.h>
void main(void)
{
int menu=0, i, n;
char k;
char data[4], clave[4]; //Espacio de memoria
float temper,medicion;
lcd_init();
kbd_init();
port_b_pullups(TRUE); //habilita resistencias de pullups
while(true)
{
setup_adc (adc_clock_internal);
setup_adc_ports (an0);
set_adc_channel (0); // Elige canal a medir RA0
delay_us (20);
medicion=read_adc (); // Hace conversi�n AD
temper=medicion*(0.48875); // Pasa binario a �C (5v/(1024))
output_high(PIN_A2);
if(temper<=35)
{
if(input(PIN_C0)==0) //Pulsador opciones
{
menu++;
delay_ms(300);
}
switch(menu)
{
case 0:
lcd_gotoxy(1,1);
lcd_putc("<--- MENU ");
lcd_gotoxy(1,2);
lcd_putc("TEMPERATURA ");
lcd_gotoxy(13,2);
printf(lcd_putc,"%02.1f",temper);
break;
case 1:
lcd_gotoxy(1,1);
lcd_putc("1 INGRESAR ");
lcd_gotoxy(1,2);
lcd_putc(" CONTRASENA --->");
}
if
((data[0]==clave[0])&&(data[1]==clave[1])&&(data[2]==clave[2])&&(data[3]==clave[3])
)
{
printf(lcd_putc,"\f PUERTA ABIERTA");
output_high(PIN_A1); //led azul
output_high(PIN_A5); //relay
output_low(PIN_A2); //apaga led rojo
delay_ms(2000);
output_low(PIN_A1);
output_low(PIN_A5);
}
else printf(lcd_putc,"\f INCORRECTO");
delay_ms(1000);
menu=0;
break;
}
break;
case 2:
lcd_gotoxy(1,1);
lcd_putc("2 CAMBIAR "); //Imprime este mensaje
lcd_gotoxy(1,2);
lcd_putc(" CONTRASENA --->"); //Imprime este mensaje
if(input(PIN_C1)==0) //Si en el Pin A1 hay un cero logico debido a que se
pulse el boton enter
{
lcd_putc("\f"); //Limpia pantalla lcd
i=0; //Se iguala i a cer
lcd_putc(" INGRESAR CLAVE "); //Imprime este mensaje
while(i<=3) //Condicion de que siempre que i sea menor o igual a 3
{
k=kbd_getc(); //Se obtiene el valor de la tecla pulsada
if (k!=0) //si k esta vacio
{
data[i]=k; //Guarda el valor de la tecla pulsada en la variable
data
i++; //se incrementa item
lcd_gotoxy(i+5,2);
lcd_putc('*'); //se imprime * en representacion de un caracter
output_high(PIN_A3);
delay_ms(80);
output_low(PIN_A3);
}
}
for (i=0;i<=3;i++)
{
clave[i]=read_eeprom(i);//Lee la clave guardada en memoria y la guarda en
una nueva variable
//Para luego compararla con la clave ingresada
por el usuario
}
if
((data[0]==clave[0])&&(data[1]==clave[1])&&(data[2]==clave[2])&&(data[3]==clave[3])
)//comparacion de la clave ingresada
lcd_gotoxy(1,2);
lcd_putc("TEMP ALTA"); // Imprime este mensaje
lcd_gotoxy(12,2);
printf(lcd_putc,"%02.1fC",temper);
delay_ms(200);
}
}
}