include "modedefs.bas"
define OSC 4
ADCON1 = %00001111
TRISA = %00001111
TRISB = %00011111
TRISC = %10000000
TRISD = %00000011
TRISE = %00000000
;*************** DISPLAY LCD ****************
DEFINE LCD_DREG PORTD
DEFINE LCD_BITS 4
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTD
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTD
DEFINE LCD_EBIT 3
DEFINE LCD_LINES 2
POS1 var Byte
POS2 var Byte
POS3 var Byte
POS4 var Byte
POS1 = $C0
POS2 = $C1
POS3 = $C2
POS4 = $C3
LCDOUT $FE,$40,$00,$00,$10,$0F,$0F,$0D,$18,$10
LCDOUT $FE,$48,$04,$0E,$1F,$1C,$1C,$1C,$06,$05
LCDOUT $FE,$50,$00,$00,$10,$0F,$0F,$0D,$04,$06
LCDOUT $FE,$58,$04,$0E,$1F,$1C,$1C,$1C,$08,$18
LCDOUT $FE,$60,$04,$0E,$1F,$07,$07,$07,$02,$03
LCDOUT $FE,$68,$00,$00,$01,$1E,$1E,$16,$04,$0C
LCDOUT $FE,$70,$04,$0E,$1F,$07,$07,$07,$0C,$14
LCDOUT $FE,$78,$00,$00,$01,$1E,$1E,$16,$03,$01
;**************** TECLADO ******************
UNO VAR PORTB.1
DOS VAR PORTB.2
TRES VAR PORTB.3
CUATRO VAR PORTB.4
A VAR PORTB.5
B VAR PORTB.6
C VAR PORTB.7
D VAR PORTC.0
;*************** SALIDAS ********************
LEDROJO VAR PORTE.0
LEDVERDE VAR PORTE.1
SIRENA VAR PORTE.2
SONIDO VAR PORTA.5
;*************** VARIABLES ******************
bData Var Byte
BANDERA VAR BYTE
BANDERA1 VAR BYTE
BANDERA2 VAR BYTE
NUMERO VAR BYTE
R VAR BYTE
SET1 VAR BYTE
SET2 VAR BYTE
SET3 VAR BYTE
SET4 VAR BYTE
dato VAR WORD
seguridad_ON var byte
On Interrupt GoTo ZONA
INTCON = %10010000
LCDOUT $FE,1
LCDOUT "INICIO SISTEMA"
LCDOUT $FE,$C2,"DE SEGURIDAD"
PAUSE 1000
GOSUB perroGUARDIAN
LCDOUT $FE,1
BANDERA = 0
INICIANDO:
FOR R=1 TO 2
HIGH LEDROJO:HIGH LEDVERDE:HIGH SONIDO
PAUSE 200
LOW LEDROJO:LOW LEDVERDE:LOW SONIDO
PAUSE 100
NEXT
LCDOUT $FE,$C0, 0
;******************GUARDAR LA CLAVE EN LA MEMORIA EEPROM************************
EEPROM 0,[1,2,3,4]
;*******************************************************************************
ARRANQUE:
PAUSE 500
LCDOUT $FE,1
LCDOUT "(*)S/N (#)Config"
LCDOUT $FE,$C0,"(0) PRUEBA GSM"
BANDERA = 0
;*******************************************************************************
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 mensajeACTIVADO
IF DOS=0 THEN MODEM
IF TRES=0 THEN GRABAUNO
HIGH D
PAUSE 25
GOTO ARRANQUE
mensajeACTIVADO:
GOSUB perroGUARDIAN
LCDOUT $FE,1
LCDOUT $FE,2," SISTEMA ALARMA "
LCDOUT $FE,$C0," ACTIVADA "
PAUSE 2000
LCDOUT $FE,1
BANDERA = 1
GOTO RESETEO
RESETEO:
;LOW PUERTA
LCDOUT $FE,1
FOR R=1 TO 2
HIGH LEDROJO:HIGH SONIDO
PAUSE 200
LOW LEDROJO:LOW SONIDO
PAUSE 100
IF D=0 AND UNO=0 THEN RESETEO
NEXT
READ 0,SET1
READ 1,SET2
READ 2,SET3
READ 3,SET4
GOSUB TECLAUNO
GRABAUNO:
lcDout $FE,1
LCDOUT $FE,3,"INGRESE SU CLAVE":LCDOUT $FE,$C3,"ANTERIOR"
PAUSE 1000
GOSUB TCLAUNO
RETURN
TCLAUNO:
LCDOUT $FE,1
LCDOUT $FE,2,"CLAVE ANTERIOR:"
GOSUB BARRIDO
GOSUB PTECLA
IF NUMERO=SET1 THEN GOSUB TCLADOS
GOTO FALSO
TCLADOS:
GOSUB BARRIDO
GOSUB PTECLA
IF NUMERO=SET2 THEN GOSUB TCLATRES
GOTO FALSO1
TCLATRES:
GOSUB BARRIDO
GOSUB PTECLA
IF NUMERO=SET3 THEN GOSUB TCLACUATRO
GOTO FALSO2
TCLACUATRO:
GOSUB BARRIDO
GOSUB PTECLA
IF NUMERO=SET4 THEN GOSUB GRABA_1
GOTO FALSO3
GRABA_1:
LCDOUT $FE,1
LCDOUT $FE,2,"INGRESE SU NUEVA":LCDOUT $FE,$C3,"CLAVE:"
LCDOUT $FE,$C5
GOSUB PTECLA:HIGH LEDROJO
GOSUB BARRIDO:GOSUB PTECLA
HIGH LEDROJO
WRITE 0,NUMERO
GRABADOS:
GOSUB BARRIDO:GOSUB PTECLA
GOSUB PTECLA:HIGH LEDROJO
HIGH LEDROJO
WRITE 1,NUMERO
GRABATRES:
GOSUB BARRIDO:GOSUB PTECLA
GOSUB PTECLA:HIGH LEDROJO
HIGH LEDROJO
WRITE 2,NUMERO
GRABACUATRO:
GOSUB BARRIDO:GOSUB PTECLA
GOSUB PTECLA:HIGH LEDROJO
HIGH LEDROJO
WRITE 3,NUMERO
LOW D
IF D=0 AND UNO=0 THEN RESETEO
HIGH D
PAUSE 500
LCDOUT $FE,1
LCDOUT $FE,2,"NUEVA CLAVE HA"
LCDOUT $FE,$C0,"SIDO CONFIGURADA"
PAUSE 2000
GOTO ARRANQUE
BARRIDO:
;*******************************************************************************
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 GOSUB BORRAR
IF DOS=0 THEN NUMERO=0:RETURN
IF TRES=0 THEN GOSUB GRABAUNO
HIGH D
PAUSE 25
GOTO BARRIDO
;*******************************************************************************
PTECLA:
HIGH LEDROJO:HIGH SONIDO
PAUSE 100
LOW LEDROJO:LOW SONIDO
ESPACIO:
IF UNO=0 THEN ESPACIO
IF DOS=0 THEN ESPACIO
IF TRES=0 THEN ESPACIO
PAUSE 25
RETURN
TECLAUNO:
LCDOUT $FE,2,"INTRODUCIR CLAVE"
GOSUB BARRIDO
LCDOUT $FE,$C5, "*"
GOSUB PTECLA
IF NUMERO=SET1 THEN TECLADOS
GOTO FALSO
TECLADOS:
GOSUB BARRIDO
LCDOUT "*"
GOSUB PTECLA
IF NUMERO=SET2 THEN TECLATRES
GOTO FALSO1
TECLATRES:
GOSUB BARRIDO
LCDOUT "*"
GOSUB PTECLA
IF NUMERO=SET3 THEN TECLACUATRO
GOTO FALSO2
TECLACUATRO:
GOSUB BARRIDO
LCDOUT "*"
GOSUB PTECLA
IF NUMERO=SET4 THEN ABRIR
GOTO FALSO3
ABRIR:
LCDOUT $FE,1
LCDOUT $FE,2," CLAVE CORRECTA"
;HIGH PUERTA
FOR R=1 TO 4
HIGH LEDVERDE:HIGH SONIDO
PAUSE 200
LOW LEDVERDE:LOW SONIDO
NEXT
PAUSE 500
LOW D
IF D=0 AND UNO=0 THEN BORRAR
HIGH D
PAUSE 25
GOTO mensajeDESACTIVADO
FALSO:
GOSUB BARRIDO:GOSUB PTECLA:LCDOUT $FE,$C5, "*"
FALSO1:
GOSUB BARRIDO:GOSUB PTECLA:LCDOUT "*"
FALSO2:
GOSUB BARRIDO:GOSUB PTECLA:LCDOUT "*"
FALSO3:
LCDOUT $FE,1
FOR R=1 TO 10
HIGH LEDROJO:HIGH SONIDO
PAUSE 200
LOW LEDROJO:LOW SONIDO
NEXT
IF D=0 AND UNO=0 THEN BORRAR
ALERTA:
LCDOUT $FE,2,"CLAVE INCORRECTA"
HIGH LEDROJO:HIGH SONIDO
PAUSE 200
LOW LEDROJO:LOW SONIDO
LOW D
IF D=0 AND UNO=0 THEN BORRAR
HIGH D
GOTO ALERTA
BORRAR:
LCDOUT $FE,1
GOSUB RESETEO
RETURN
mensajeDESACTIVADO:
PAUSE 1500
LOW SIRENA
BANDERA = 0
LCDOUT $FE,1
LCDOUT $FE,2," SISTEMA ALARMA "
LCDOUT $FE,$C0," DESACTIVADA "
PAUSE 2000
GOTO ARRANQUE
MODEM:
LCDOUT $FE,1
LCDOUT $FE,2,"PRUEBA MODEM GSM"
LCDOUT $FE,$C0," ACTIVADA "
PRUEBA1:
PAUSE 1000
LCDOUT $FE,1
LCDOUT $FE,2,"AT+CMGR=1"
serout PORTC.6,T9600,["AT+CMGR=1",10,13]
;serin PORTC.7,T9600,[],dato
serin PORTC.7,T9600,900,PRUEBA2,[],dato
LCDOUT $FE,$C0,DEC DATO
PRUEBA2:
PAUSE 1000
LCDOUT $FE,1
LCDOUT $FE,2,"AT+CMGD=1"
SEROUT PORTC.6,T9600,["AT+CMGD=1",10,13]
;serin PORTC.7,T9600,[],dato
serin PORTC.7,T9600,900,PRUEBA3,[],dato
LCDOUT $FE,$C0,DEC DATO
PRUEBA3:
pause 1000
LCDOUT $FE,1
LCDOUT $FE,2,"AT+CMGD=2"
SEROUT PORTC.6,T9600,["AT+CMGD=2",10,13]
;serin PORTC.7,T9600,[],dato
serin PORTC.7,T9600,900,PRUEBA4,[],dato
;SERIN PORTC.7,T9600,DATO
LCDOUT $FE,$C0,DEC DATO
PRUEBA4:
pause 1000
LCDOUT $FE,1
LCDOUT $FE,2,"AT+CMGF=1"
SEROUT PORTC.6,T9600,["AT+CMGF=1",10,13]
;serin PORTC.7,T9600,[],dato
serin PORTC.7,T9600,900,PRUEBA5,[],dato
;SERIN PORTC.7,T9600,DATO
LCDOUT $FE,$C0,DEC DATO
PRUEBA5:
pause 1000
LCDOUT $FE,1
LCDOUT $FE,2,"2976256173"
SEROUT PORTC.6,T9600,["AT+CMGS=",34,"2976256173",34,10,13]
;serin PORTC.7,T9600,[],dato
serin PORTC.7,T9600,900,PRUEBA6,[],dato
;SERIN PORTC.7,T9600,DATO
LCDOUT $FE,$C0,DEC DATO
PRUEBA6:
pause 1000
LCDOUT $FE,1
LCDOUT $FE,2,"SMS: PRUEBA TEL"
SEROUT PORTC.6,T9600,["PRUEBA TEL",26,10,13]
;serin PORTC.7,T9600,[],dato
serin PORTC.7,T9600,900,PRUEBA7,[],dato
;SERIN PORTC.7,T9600,DATO
LCDOUT $FE,$C0,# DATO
pause 1000
PRUEBA7:
PAUSE 1500
LCDOUT $FE,1
LCDOUT $FE,2,"PRUEBA TERMINADA"
LCDOUT $FE,$C0," REINICIANDO "
;SEROUT PORTC.6,T9600,["ATS10=254",10,13]
;serin PORTC.7,T9600,[],dato
;serin PORTC.7,T9600,2000,arranque,[],dato
PAUSE 2000
GOTO ARRANQUE
perroGUARDIAN:
LCDOUT $FE,POS1, 0
LCDOUT $FE,POS2, 1
Pause 300
LCDOUT $fe, 1
LCDOUT $FE,POS3, 2
LCDOUT $FE,POS4, 3
Pause 300
POS1 = POS1 + 3
POS2 = POS2 + 3
POS3 = POS3 + 3
POS4 = POS4 + 3
If POS4 > $CF Then RETRO
goto perroguardian
RETRO:
POS1 = $CF
POS2 = $CE
POS3 = $CD
POS4 = $CC
RETROCEDE:
LCDOUT $fe, 1
LCDOUT $FE,POS1, 7
LCDOUT $FE,POS2, 6
Pause 300
LCDOUT $fe, 1
LCDOUT $FE,POS3, 5
LCDOUT $FE,POS4, 4
Pause 300
POS1 = POS1 - 3
POS2 = POS2 - 3
POS3 = POS3 - 3
POS4 = POS4 - 3
If POS4 < $C0 Then REINICIA
GoTo RETROCEDE
REINICIA:
POS1 = $C0
POS2 = $C1
POS3 = $C2
POS4 = $C3
return
DISABLE
ZONA:
IF BANDERA = 1 THEN
HIGH SIRENA
BANDERA1 = BANDERA1 + 1
ELSE
LOW SIRENA
ENDIF
BANDERA1 = BANDERA1 + 1
IF BANDERA1 > 6 THEN BANDERA1 = 0
IF BANDERA = 1 AND BANDERA1 < 3 THEN
PAUSE 100
serout PORTC.6,T9600,["AT+CMGR=1",10,13]
PAUSE 500
SEROUT PORTC.6,T9600,["AT+CMGD=1",10,13]
pause 500
SEROUT PORTC.6,T9600,["AT+CMGD=2",10,13]
pause 500
SEROUT PORTC.6,T9600,["AT+CMGF=1",10,13]
pause 1000
SEROUT PORTC.6,T9600,["AT+CMGS=",34,"2976256173",34,10,13]
pause 1000
SEROUT PORTC.6,T9600,["DISPARO ALARMA",26,10,13]
PAUSE 100
ENDIF
INTCON = %10010000
Resume
Enable
END