'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : Luis Perez *
'* Notice : Copyright (c) 2010 IB-electronic *
'* : All Rights Reserved *
'* Date : 06/10/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
@ device pic16f877a, wdt_off, lvp_off,xt_osc,xt_osc
define osc 4
DEFINE LCD_DREG PORTD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 0
DEFINE LCD_RWREG PORTD
DEFINE LCD_RWBIT 1
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 2
cmcon=7
TRISA=0:porta=0
trisb=%11111000:portb=0
trisc=%11111100
trisd=0:portb=0
trise=0:porte=0
Numero var byte
nu1 var byte
nu2 var byte
nu3 var byte
nu4 var byte
R var byte
x var byte
x=0
PARLAN VAR PORTC.0
LED VAR PORTC.1
PUERTA VAR PORTC.2
PC var portc.3
PA var portc.7
F1 VAR PORTB.0
F2 VAR PORTB.1
F3 VAR PORTB.2
F4 VAR PORTB.3
C1 VAR PORTB.4
C2 VAR PORTB.5
C3 VAR PORTB.6
C4 VAR PORTB.7
Car1 var byte
Car2 var byte
Car3 var byte
Car4 var byte
dato var byte
Pre:
lcdout $FE,1:LCDout $FE,$80,"Llave electronic"
pause 500
lcdout $Fe,$C0,"ib-electronic"
INICIO:
HIGH LED : SOUND parlan,[100,50]:high parlan
LOW LED : LOW parlan
'*********************************************
'Claves por defecto=1234:
'*********************************************
eeprom 0,[1,2,3,4]
RESET:
read 0,car1
read 1,car2
read 2,car3
read 3,car4
goto TEcla1
TEcla1:
lcdout $fe,1
lcdout $FE,$80,"Clave:"
gosub teclado: lcdout $fe,$c0,"X" :gosub pid
gosub espacio
nu1=numero
if numero=car1 then TEcla2
goto false
TEcla2:
gosub teclado : lcdout $fe,$c0,"XX" : gosub pid
gosub espacio
nu2=numero
if numero=car2 then TEcla3
goto false1
Tecla3:
Gosub Teclado : lcdout $fe,$c0,"XXX" : gosub pid
gosub espacio
nu3=numero
if numero=car3 then Tecla4
goto false2
TEcla4:
gosub teclado : lcdout $fe,$c0,"XXXX" : gosub pid
gosub espacio
nu4=numero
if numero=car4 then compara
goto false3
Compara:
if (nu1=car1) and (nu2=car2) and (nu3=car3) and (nu4=car4) then open
goto false3
PID:
SOUND parlan,[100,10] : high led
pause 300
low parlan :low led
return
Espacio:
pause 300
return
False:
goto tecla2
False1:
goto tecla3
False2:
goto tecla4
False3:
lcdout $fe,1
lcdout $FE,$80,"Clave:"
lcdout $FE,$C0,"incorrecta"
for r= 1 to 20
high led : SOUND parlan,[100,10] : high pc
pause 50
low led : SOUND parlan,[50,10] : low pc
pause 50
next
high pc
pause 2000
low pc
goto tecla1
OPen:
lcdout $fe,1
lcdout $FE,$80,"Clave:"
lcdout $FE,$C0,"Correcta"
for r=0 to 2
high led:SOUND parlan,[100,10];high parlan
pause 100
low led :SOUND parlan,[50,10];low parlan
pause 100
next
Menu:
lcdout $fe,1
lcdout $fe,$80,"Bienvenido"
lcdout $fe,$C0,"Luis Perez"
pause 1000
lcdout $fe,1
lcdout $fe,$80,"Menu"
lcdout $fe,$c0,"1-Open 2-Clave"
Op:
gosub teclado
if numero=1 then door
if numero=2 then graba1
goto op
Door:
lcdout $fe,1
lcdout $fe,$80,"Puerta"
lcdout $fe,$C5,"Abierta"
high puerta :high pa
pause 5000
low pa :low puerta
goto tecla1
Graba1:
lcdout $fe,1
lcdout $fe,$80,"Cambiar Clave"
lcdout $fe,$c0,"----"
high led : SOUND parlan,[100,300] : pause 1000 : low led : low parlan
gosub teclado:gosub PID
lcdout $fe,$c0,"X--"
write 0,numero
pause 300
Graba2:
gosub teclado:gosub PID
lcdout $fe,$c0,"XX--"
write 1,numero
pause 300
Graba3:
gosub teclado:gosub pid
lcdout $fe,$c0,"XXX-"
Write 2,numero
pause 300
Graba4:
gosub teclado:gosub pid
lcdout $fe,$c0,"XXXX"
write 3,numero
pause 300
lcdout $fe,1
lcdout $fe,$80,"Clave guardada"
lcdout $fe,$c0,"xxxx"
for r = 0 to 5
SOUND parlan,[100,10] : high led
pause 100
SOUND parlan,[50,10] : low led
pause 100
next
goto RESET
Teclado:
low f1
if c1=0 then numero=7:return
if c2=0 then numero=8:return
if c3=0 then numero=9:return
high f1
low f2
if c1=0 then numero=4:return
if c2=0 then numero=5:return
if c3=0 then numero=6:return
high f2
low f3
if c1=0 then numero=1:return
if c2=0 then numero=2:return
if c3=0 then numero=3:return
high f3
low f4
if c1=0 then numero=10:return
if c2=0 then numero=0:return
if c3=0 then numero=11:return
high f4
pause 10
GOTO teclado
end