Autor Tema: Cerradura con Alarma  (Leído 1648 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado alvarozrs

  • PIC10
  • *
  • Mensajes: 1
Cerradura con Alarma
« en: 22 de Diciembre de 2021, 18:50:18 »
Hola buenas realice este ciercuito y tengo el codigo pero no me funciona la idea es que se prenda la luz verde con la clave correcta y la luz roja con la incorrecta y que el buzzer suene

List p=16f84a
#include <p16f84a.inc>

cblock 0x0c
   TECLA;
   contador
   num1,num2,num3,num4
   PDe10,PDe11,PDe12

endc
org 0x00

contador EQU 0X03

;------------------------------Definicion de las puertas

  bsf      STATUS,RP0
 clrf      TRISA
  bsf      TRISA,4
movlw      b'11110000'
movwf      TRISB
  bcf      OPTION_REG,NOT_RBPU

  bcf      STATUS,RP0
 clrf      PORTA

;------------------------------COMIENZO DEL PROGRAMA

COMIENZO
 call      TECLADO
movwf      num1
 call      BIP

 call      TECLADO
movwf      num2
 call      BIP

 call      TECLADO
movwf      num3
 call      BIP

 call      TECLADO
movwf      num4
 call      BIP

 call      comparar_clave
 Call      clave_bien

;------------------------------COMPARACION DE LA CLAVE

movlw      d'0'
 call      CLAVE
subwf      num1
btfss      STATUS,Z
 goto      clave_mal

movlw      d'1'
 call      CLAVE
subwf      num3
btfss      STATUS,Z
 goto      clave_mal

movlw      d'3'
 call      CLAVE
subwf      num3
btfss      STATUS,Z
 goto      clave_mal

movlw      d'4'
 call      CLAVE
subwf      num4
btfss      STATUS,Z
 goto      clave_mal
 call       clave_bien

return

;------------------------------CLAVE DEL PROGRAMA

CLAVE
addwf      PCL,F
retlw      d'1'
retlw      d'2'
retlw      d'1'
retlw      d'3'

goto      COMIENZO

;------------------------------CLAVE MALA

clave_mal
  call   BIP2
  call   BIP2
  call   BIP2
  call   BIP2
decfsz  contador
 btfss   STATUS,Z
  goto  COMIENZO

;------------------------------CLAVE BIEN

clave_bien
  call BIP
  call BIP
   bsf PORTA,0
   bcf PORTA,1
   bcf PORTA,1
  goto BIP2
return

;------------------------------ALARMA ACTIVADA

alarma_activada
  call BIP2
  call BIP2
  call BIP2
  call BIP2
 movlw b'100'

;------------------------------TECLADO

TECLADO
 clrf      TECLA
Movlw      b'00001110'
movwf      PORTB

;------------------------------BOTON DE LA COLUMNA

BOTON_columna
 
btfss      PORTB,4
 goto      ESPERA
 incf      TECL,F

btfss      PORTB,5
 goto      ESPERA
incf      TECL,F

btfss      PORTB,6
 goto      ESPERA
incf      TECL,F

btfss      PORTB,7
 goto      ESPERA
incf      TECL,F

movlw      STATUS,Z
 goto      TECLADO
  bsf      STATUS,C
  rlf      PORTB,F
 goto      BOTON_columna

;------------------------------RUTINA ESPERA
ESPERA

BIT_4
btfss      PORTB,4
 goto      BIT_4

BIT_5
btfss      PORTB,5
 goto      BIT_5

BIT_6
btfss      PORTB,6
 goto      BIT_6

BIT_7
btfss      PORTB,7
 goto      BIT_7

movf      TECLA,W
call      NUMERO_tecla

;------------------------------NUMERO DE LAS TECLAS

NUMERO_tecla

   addwf   PCL,F
   retlw   h'0'   ;caracter 0
   retlw   h'1'   ;caracter 1
   retlw   h'2'   ;caracter 2
   retlw   h'3'   ;caracter 3
   retlw   h'4'   ;caracter 4
   retlw   h'5'   ;caracter 5
   retlw   h'6'   ;caracter 6
   retlw   h'7'   ;caracter 7
   retlw   h'8'   ;caracter 8
   retlw   h'9'   ;caracter 9
   retlw   h'A'   ;caracter A
   retlw   h'B'   ;caracter B
   retlw   h'C'   ;caracter C
   retlw   h'D'   ;caracter D
   retlw   h'E'   ;caracter E
   retlw   h'F'   ;caracter F

;------------------------------BIP SONIDO

BIP
    bsf   PORTA,3
   call   DEMORA
    bcf   PORTA,3
  return
;------------------------------BIP2 SONIDO

BIP2
    bsf       PORTA,3
   call   TIEMPO
    bcf   PORTA,3
  return

;------------------------------RUTINA DEMORA 250 (S)

DEMORA
  movlw     .197                  
  movwf     PDel0                 
 PLoop1      movlw        .253                  
           movwf        PDel1                 
 PLoop2     clrwdt                             
           clrwdt                             
           decfsz       PDel1, 1              
           goto         PLoop2                
           decfsz       PDel0,  1             
           goto         PLoop1                
 PDelL1     goto        PDelL2                  
 PDelL2 
           return 

;------------------------------ TIEMPO RUTINA DE 1 (S)

TIEMPO

  movlw      .14                       
  movwf      PDel0                     
 PLoop0      movlw      .72                       
             movwf      PDel1                   
PLoop122     movlw     .247                     
             movwf      PDel2                     
PLoop222     clrwdt                                 
             decfsz     PDel2, 1                 
             goto       PLoop2                   
             decfsz     PDel1,  1                 
             goto       PLoop1                   
             decfsz     PDel0,  1                 
             goto       PLoop0                   
PDelL12      goto        PDelL2                   
PDelL22      clrwdt                                 
             return



Desconectado Eduardo2

  • PIC24H
  • ******
  • Mensajes: 1004
Re:Cerradura con Alarma
« Respuesta #1 en: 23 de Diciembre de 2021, 09:18:25 »
Hola buenas realice este ciercuito
¿Cual circuito?

Citar
y tengo el codigo pero no me funciona la idea es que se prenda la luz verde con la clave correcta y la luz roja con la incorrecta y que el buzzer suene

Ese código está mal copiado, algunos de los errores:

- contador declarado dos veces.

- call comparar_clave    falta la etiqueta comparar_clave

- movlw STATUS,Z     debió ser btfsx

- movwf PDel0  y las siguientes.   Las variables son PDe10,PDe11 y PDe12, no PDel0,PDel1 y PDel2

- Despues de   Call clave_bien te estás metiendo dentro de una subrutina  WTF !
  Lo mismo despues de   call NUMERO_tecla , te metés dentro de Numero_tecla.

-  Falta la  directiva END

- No está definida TECL

- En la subrutina clave_mal, en lugar de un return saltás a COMIENZO  ?????
Es demasiado... no puedo seguir leyendo. 

« Última modificación: 23 de Diciembre de 2021, 09:42:27 por Eduardo2 »


 

anything