Está en la página 1de 5

;***************************AULA_INTELIGENTE**********************************

; ZONA DE DATOS ****************************************************************


******************
LIST P=16F874A
INCLUDE <P16F874A.INC>
__CONFIG _XT_OSC & _PWRTE_ON & _BODEN_OFF & _LVP_OFF & _DEBUG_OFF & _WDT
_OFF
#DEFINE Motor_abre PORTA,2 ;lineas definida
s para el motor
#DEFINE Motor_cierra PORTA,1
#DEFINE Sensor_IN PORTB,0
#DEFINE Sensor_OUT PORTB,1
#DEFINE Sensor_Alarma PORTB,4
#DEFINE Alarma PORTB,5
#DEFINE Foco_Ventilacion PORTB,7
#DEFINE Foco_Noche PORTB,6
#DEFINE Celda PORTD,2
#DEFINE S_Alarma PORTD,3
#DEFINE S_Puerta PORTD,4
CBLOCK 0x20
Contador_Personas
Tempo_Personas
Permiso
ENDC
; ****************************************ZONA DE CÓDIGOS ************************
*********************
ORG 0
Inicio
call LCD_Inicializa
bsf STATUS,5
movlw b'00001110'
movwf ADCON1
bcf Motor_abre
bcf Motor_cierra
bsf Sensor_IN
bsf Sensor_OUT
bsf Sensor_Alarma
bcf Alarma
bcf Foco_Ventilacion
bcf Foco_Noche
bsf Celda
bsf S_Alarma
bcf STATUS,RP0
clrf Contador_Personas
clrf Tempo_Personas
clrf Permiso
bcf Foco_Ventilacion
bcf Foco_Noche
bcf Alarma
call LCD_Linea4
movlw Mensaje1
call LCD_Mensaje
call LCD_Linea2
movlw Mensaje2
call LCD_Mensaje
;call Sensa_Dia_Noche
;call Imprime_Personas
;bsf Motor_abre
;bcf Motor_cierra
;call Retardo_2s
bcf Motor_abre
bcf Motor_cierra
Pregunta_1
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .2
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto Pregunta_2
call Proceso
goto Pregunta_12
Pregunta_2
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .0
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto Pregunta_3
call Proceso
goto Pregunta_2
Pregunta_3
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .1
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto Pregunta_4
call Proceso
goto Pregunta_3
Pregunta_4
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .3
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto DECREMENTA_CONTADOR
call Proceso
goto Pregunta_4
INCREMENTA_CONTADOR
incf Contador_Personas,f
goto Pregunta_1
Pregunta_12
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .1
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto Pregunta_22
call Proceso
goto Pregunta_1
Pregunta_22
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .0
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto Pregunta_32
call Proceso
goto Pregunta_22
Pregunta_32
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .2
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto Pregunta_42
call Proceso
goto Pregunta_32
Pregunta_42
movf PORTB,0
andlw .3
movwf Tempo_Personas
movlw .3
xorwf Tempo_Personas,w
btfsc STATUS,Z
goto INCREMENTA_CONTADOR
call Proceso
goto Pregunta_42
DECREMENTA_CONTADOR
decf Contador_Personas,f
goto Pregunta_1
Proceso
call Sensa_Dia_Noche
call Rutina_Alarma
call Imprime_Personas
call Luces_Interiores
call RUTINA_PUERTA
return
;***************************Rutina_Dia_Noche***********************************
Sensa_Dia_Noche
call LCD_Linea1
btfss Celda
goto Rutina_Noche
Rutina_Dia
;call LCD_Linea1
movlw Mensaje3
call LCD_Mensaje
bcf Foco_Noche
return
Rutina_Noche
;call LCD_Linea1
movlw Mensaje4
call LCD_Mensaje
bsf Foco_Noche
return
;**********************Rutina_Alarma*********************************
Rutina_Alarma
btfss Sensor_Alarma
goto Apaga_Alarma
Switch_Alarma
btfss S_Alarma
goto Apaga_Alarma
call LCD_Borra
bcf Permiso,1
call CIERRA_PUERTA
Enciende_Alarma
bsf Foco_Noche
bsf Alarma
call Retardo_500ms
bcf Alarma
call Retardo_500ms
bcf Foco_Noche
bsf Alarma
call Retardo_500ms
bcf Alarma
call Retardo_500ms
goto Enciende_Alarma
Apaga_Alarma
bcf Alarma
return
;**********************rutina_conteo de personas********************************
*
RUTINA_PUERTA
btfsc Sensor_IN
goto RUTINA_PUERTA_2
ABRE_PUERTA
btfsc Permiso,0
goto PARA_MOTOR
bsf Motor_abre
bcf Motor_cierra
call Retardo_1s
bsf Permiso,0
bcf Permiso,1
goto PARA_MOTOR
PARA_MOTOR
bcf Motor_abre
bcf Motor_cierra
return
CIERRA_PUERTA
btfsc Permiso,1
goto PARA_MOTOR
bcf Motor_abre
bsf Motor_cierra
call Retardo_1s
bcf Permiso,0
bsf Permiso,1
goto PARA_MOTOR
RUTINA_PUERTA_2
btfsc Sensor_OUT
goto CIERRA_PUERTA
goto ABRE_PUERTA

Imprime_Personas
movlw .17
call LCD_PosicionLinea2
movf Contador_Personas,W
call BIN_a_BCD
call LCD_ByteCompleto
return
Luces_Interiores
movf Contador_Personas,f
btfss STATUS,Z
goto Prende
bcf Foco_Ventilacion
return
Prende
bsf Foco_Ventilacion
return
Mensajes
ADDWF PCL,F
Mensaje1
DT " -Aula Inteligente-", 0x00
Mensaje2
DT "No. de Personas:", 0x00
Mensaje3
DT " Buenos Dias ", 0x00
Mensaje4
DT " Buenas Noches", 0x00
Mensaje5
DT " Atrapen al Ladron!!!", 0x00
FinMensajes
INCLUDE <BIN_BCD.INC>
INCLUDE <LCD_P16F877a.INC>
INCLUDE <RETARDOS.INC>
INCLUDE <LCD_MENS.INC>
END

También podría gustarte