Skip to content

Instantly share code, notes, and snippets.

@pepgonzalez
Created April 17, 2012 04:27
Show Gist options
  • Save pepgonzalez/2403443 to your computer and use it in GitHub Desktop.
Save pepgonzalez/2403443 to your computer and use it in GitHub Desktop.
cerradura electronica
include "BS2DEFS.BAS"
@ DEVICE INTRC_OSC_NOCLKOUT
@ DEVICE MCLR_OFF
numero var byte
a var portb.7
b var portb.6
c var portb.5
d var portb.4
uno var portb.3
dos var portb.1
tres var portb.2
trisa = 0
er var byte
er = 0
n1 var byte
n2 var byte
n3 var byte
n4 var byte
nueva var byte
x var byte
x = 0
n1 = 1
n2 = 2
n3 = 3
n4 = 4
nueva = D
inicio:
porta=%1000
pause 500
porta=%1100
pause 500
porta=%1110
pause 500
porta=%1111
pause 1000
porta=%0000
pause 500
goto tecla1
nvo1:
w var byte
for w= 1 to 4
porta=%1111
pause 300
porta=%0000
pause 300
next
porta=%1000
gosub pt
gosub lectura: gosub pt
porta=%1000
n1 = numero
nvo2:
gosub lectura: gosub pt
porta=%1000
n2 = numero
nvo3:
gosub lectura: gosub pt
porta=%1000
n3 = numero
nvo4:
gosub lectura: gosub pt
porta=%1000
n4 = numero
q var byte
for q= 1 to 4
porta=%1111
pause 300
porta=%0000
pause 300
next
goto tecla1
lectura:
low a
if uno = 0 then numero=1: return
if dos = 0 then numero=2: return
if tres = 0 then numero=3: return
high a
low b
if uno = 0 then numero=4: return
if dos = 0 then numero=5: return
if tres = 0 then numero=6: return
high b
low c
if uno = 0 then numero=7: return
if dos = 0 then numero=8: return
if tres = 0 then numero=9: return
high c
low d
if uno = 0 then numero=11: return
if dos = 0 then numero=0: return
if tres = 0 then numero=12: return
high d
pause 10
goto lectura
pt:
porta=%1000
pause 100
porta=%0000
espacio:
if uno = 0 then espacio
if dos = 0 then espacio
if tres = 0 then espacio
pause 25
return
tecla1:
porta=%0100
gosub lectura: gosub pt
if numero = n1 then tecla2
x = 1
goto tecla2
tecla2:
gosub lectura: gosub pt
if numero = n2 then tecla3
x = 1
goto tecla3
tecla3:
gosub lectura: gosub pt
if numero = n3 then tecla4
x = 1
goto tecla4
tecla4:
gosub lectura: gosub pt
if numero = n4 then prueba
x = 1
goto prueba
prueba:
if X = 0 then correcto
goto alerta
correcto:
porta=%1001
goto pass
pass:
gosub lectura: Gosub pt
if numero = 11 then nvo1
if numero = 12 then tecla1
alerta:
f var byte
for f = 1 to 10
porta =%0010
pause 250
porta=%0100
pause 250
next
x = 0
goto tecla1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment