Cerradura digital

Hola...

Estoy realizando un programa que es algo asi como una cerradura digital con un pic16f84.
El mismo recibe una secuencia de cuatro dígitos y si la secuencia es la correcta me enciende un led (que hace las veces de cerradura). Yo se que ya hay integrados que hacen estas cosas pero yo lo quiero hacer con este pic.
El programa que hice no funciona por alguna razón que desconozco. Nunca se enciende el led aunque la secuencia de números (que en este caso es 2,4,6 y 8) sea la ingresada.
Acá les muestro el código...

include "p16F84A.inc"
;Variables *****************************************
param00_delay_us equ 0x0c
_d_main equ 0x0d
_flag_main equ 0x0e
_cont_main equ 0x0f
ORG 0
goto start__code

ORG 4
_interrupt
bcf INTCON, T0IF ;clear interrupt flag
retfie

start__code
;;;;;;;;void main(void)
_main__code
clrf _d_main
clrf _flag_main
clrf _cont_main
;;;;;;;;{
;;;;;;;; char d=0x00,flag=0x00,cont=0x00;
;;;;;;;;
;;;;;;;; set_bit( STATUS, RP0 );
bsf STATUS, RP0
;;;;;;;; OPTION_REG = 7;
movlw D'7'
movwf OPTION_REG
;;;;;;;; set_tris_b( 0x00 );
clrf TRISB
;;;;;;;; clear_bit( STATUS, RP0 );
bcf STATUS, RP0
;;;;;;;; output_port_b( 0x00 );
clrf PORTB
;;;;;;;;
;;;;;;;; set_bit( STATUS, RP0 );
bsf STATUS, RP0
;;;;;;;; set_tris_a( 0x0f );
movlw D'15'
movwf TRISA
;;;;;;;; clear_bit( STATUS, RP0 );
bcf STATUS, RP0
;;;;;;;;
;;;;;;;; while(1)
label_0000
;;;;;;;; {
;;;;;;;; d=input_port_a();
movf PORTA, W
movwf _d_main
;;;;;;;; delay_us(255);
movlw D'255'
movwf param00_delay_us
call _delay_us
;;;;;;;;
;;;;;;;;if((d==0x02)||(d==0x04)||(d==0x06)||(d==0x08)||(d==0x00))
movf _d_main, W
sublw D'2'
movlw 1
btfss STATUS, Z
clrw
andlw 0xFF
btfss STATUS, Z
goto label_0004
movf _d_main, W
sublw D'4'
movlw 1
btfss STATUS, Z
clrw
andlw 0xFF
btfsc STATUS, Z
goto label_0004+1
label_0004
movlw 1
andlw 0xFF
btfss STATUS, Z
goto label_0005
movf _d_main, W
sublw D'6'
movlw 1
btfss STATUS, Z
clrw
andlw 0xFF
btfsc STATUS, Z
goto label_0005+1
label_0005
movlw 1
andlw 0xFF
btfss STATUS, Z
goto label_0006
movf _d_main, W
sublw D'8'
movlw 1
btfss STATUS, Z
clrw
andlw 0xFF
btfsc STATUS, Z
goto label_0006+1
label_0006
movlw 1
andlw 0xFF
btfss STATUS, Z
goto label_0007
movf _d_main, W
sublw D'0'
movlw 1
btfss STATUS, Z
clrw
andlw 0xFF
btfsc STATUS, Z
goto label_0007+1
label_0007
movlw 1
sublw 0
btfsc STATUS, Z
goto label_0003
;;;;;;;; {
;;;;;;;; if(d==0x02)
movlw D'2'
subwf _d_main, W
btfss STATUS, Z
goto label_0008
;;;;;;;; if(cont==0x00)
movf _cont_main, F
btfss STATUS, Z
goto label_0009
;;;;;;;; cont++;
incf _cont_main, F
;;;;;;;; else cont=0x00;
goto label_0010
label_0009
clrf _cont_main
;;;;;;;;
;;;;;;;; if(d==0x04)
label_0010
label_0008
movlw D'4'
subwf _d_main, W
btfss STATUS, Z
goto label_0011
;;;;;;;; if(cont==0x01)
movlw D'1'
subwf _cont_main, W
btfss STATUS, Z
goto label_0012
;;;;;;;; cont++;
incf _cont_main, F
;;;;;;;; else cont=0x00;
goto label_0013
label_0012
clrf _cont_main
;;;;;;;;
;;;;;;;; if(d==0x06)
label_0013
label_0011
movlw D'6'
subwf _d_main, W
btfss STATUS, Z
goto label_0014
;;;;;;;; if(cont==0x02)
movlw D'2'
subwf _cont_main, W
btfss STATUS, Z
goto label_0015
;;;;;;;; cont++;
incf _cont_main, F
;;;;;;;; else cont=0x00;
goto label_0016
label_0015
clrf _cont_main
;;;;;;;;
;;;;;;;; if(d==0x08)
label_0016
label_0014
movlw D'8'
subwf _d_main, W
btfss STATUS, Z
goto label_0017
;;;;;;;; if(cont==0x03)
movlw D'3'
subwf _cont_main, W
btfss STATUS, Z
goto label_0018
;;;;;;;; if(flag==0x00)
movf _flag_main, F
btfss STATUS, Z
goto label_0019
;;;;;;;; {output_high_port_b(0);
bsf PORTB, 0
;;;;;;;; flag=0x01;
movlw D'1'
movwf _flag_main
;;;;;;;; cont=0x00;}
clrf _cont_main
;;;;;;;; else
goto label_0021
label_0019
;;;;;;;; {output_low_port_b(0);
bcf PORTB, 0
;;;;;;;; flag=0x00;
clrf _flag_main
;;;;;;;; cont=0x00;}
clrf _cont_main
;;;;;;;; else cont=0x00;
label_0020
goto label_0021
label_0018
clrf _cont_main
;;;;;;;; }
label_0021
label_0017
;;;;;;;;else cont=0x00;
goto label_0022
label_0003
clrf _cont_main
;;;;;;;; }
label_0022
;;;;;;;;}
goto label_0000
label_0001
_main__end
_delay_us__code
_delay_us
rrf param00_delay_us, 1
rrf param00_delay_us, 1
movlw D'63'
andwf param00_delay_us, 1
movlw D'3'
subwf param00_delay_us, 1
label_0002
nop
decfsz param00_delay_us, 1
goto label_0002
nop
return
_delay_us__end
END

El mismo fue realizado con el programa C2C-plus. Ya se que es un poco largo como para leerlo pero estaria muy agradecido si alguien me puede decir cual es mi error... :D
 
solamente te digo una cosa.... en el programa te tiene que tirar la/las lineas que estan mal en el programa
 
Estimados amigos y colegas.
Deseándoles un feliz año nuevo, les vengo a trae el programa para la cerradura digital. Ya anteriormente lo había hecho en ASM pero en esta oportunidad, aprovechando que estoy aprendiendo, en Basic para Pic's del Pic Simulator Ide. Le agradezco los comentarios.
Código:
Define CLOCK_FREQUENCY = 4
AllDigital

Symbol raw1 = RB4
Symbol raw2 = RB5
Symbol raw3 = RB6
Symbol raw4 = RB7
Symbol col1 = RB0
Symbol col2 = RB1
Symbol col3 = RB2
Symbol col4 = RB3

Define LCD_BITS = 8
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 0
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_EREG = PORTA
Define LCD_EBIT = 2
Define LCD_READ_BUSY_FLAG = 1
Define LCD_INITMS = 2

Dim cancel As Bit
Dim igual As Bit
Dim grabo As Bit
Dim button As Byte
Dim puerto As Byte
Dim direc As Byte
Dim datoe As Byte
Dim temp1 As Byte
Dim temp2 As Byte
Dim temp3 As Byte
Dim temp4 As Byte
Dim dir(8) As Byte
Dim dig(8) As Byte
Dim cue_dig As Byte

Read 9, datoe
If datoe <> 1 Then Gosub ini_eeprom

Lcdinit

	Lcdcmdout LcdClear

	Gosub mensaje1
	puerto = TRISB
	cancel = 0
	grabo = 0
	igual = 0
	loop:
		WaitUs 50
		Gosub teclado
		TRISB = puerto
		If button = 0x0a Then Goto apertura
		If button = 0x0b Then Goto cambio
	Goto loop


apertura:
temp4 = 3
	Gosub ent_cla
	Gosub lee_mem
	Gosub com_cla
	If igual = 0 Then
		Gosub mensaje3
	Else
		Gosub abrir
		Gosub mensaje4
	Endif
	WaitUs 5
Gosub bor_dig
Gosub bor_dir
button = 0
Gosub mensaje1
Goto loop

cambio:
temp4 = 3
	Gosub ent_cla
	Gosub lee_mem
	Gosub com_cla
	If igual = 0 Then
		Gosub mensaje3
	Else
		Gosub bor_dig
		Gosub bor_dir
		Gosub mensaje7
		WaitUs 10
		Gosub ent_cla
		Gosub car_tem
		Gosub ent_cla
		Gosub com_cla
		If igual = 1 Then
			Gosub gra_cla
		Else
			Gosub mensaje6
		Endif
		Gosub mensaje5
	Endif
	WaitUs 5
Gosub bor_dig
Gosub bor_dir
button = 0
Gosub mensaje1
Goto loop
End                                               

ent_cla:
	Gosub mensaje2
	cue_dig = 0
		For temp3 = 7 To 0 Step -1
		no_tec:
		Gosub teclado
		If button = 0 Then Goto no_tec
		If button = "B" Then
			cancel = 1
			Goto salir
		Endif
		TRISB = puerto
		Lcdout "*"
		dig(cue_dig) = button
		cue_dig = cue_dig + 1

	Next temp3
		salir:
	If cancel = 1 Then
		Gosub mensaje1
		cancel = 0
	Endif
	TRISB = puerto

Return                                            
com_cla:
igual = 1
cue_dig = 0
For direc = 7 To 0 Step -1
	If dir(cue_dig) <> dig(cue_dig) Then igual = 0
	cue_dig = cue_dig + 1
Next direc
Return                                            
lee_mem:
Read 9, datoe
If datoe <> 1 Then Gosub ini_eeprom
cue_dig = 0
For direc = 7 To 0 Step -1
	Read cue_dig, dir(cue_dig)
	cue_dig = cue_dig + 1
Next direc
Return                                            
car_tem:
cue_dig = 0
For direc = 7 To 0 Step -1
	dir(cue_dig) = dig(cue_dig)
	cue_dig = cue_dig + 1
Next direc
Gosub bor_dig
Return                                            

gra_cla:
cue_dig = 0
For direc = 7 To 0 Step -1
	Write cue_dig, dig(cue_dig)
	cue_dig = cue_dig + 1
Next direc
Write 9, 1
grabo = 1
Return                                            
ini_eeprom:
cue_dig = 0
For direc = 7 To 0 Step -1
	Write cue_dig, 1
	cue_dig = cue_dig + 1
Next direc
	Write 9, 1
Return                                            
bor_dir:
cue_dig = 0
For direc = 7 To 0 Step -1
	dir(cue_dig) = 0
	cue_dig = cue_dig + 1
Next direc
Return                                            
bor_dig:
cue_dig = 0
For direc = 7 To 0 Step -1
	dig(cue_dig) = 0
	cue_dig = cue_dig + 1
Next direc
Return                                            
mensaje1:
	Lcdcmdout LcdClear
	Lcdout "(A)Apertura"
	Lcdcmdout LcdLine2Home
	Lcdout "(B)Cambiar Clave"
Return                                            
mensaje2:
	Lcdcmdout LcdClear
	Lcdout "(B)Cancelar"
	Lcdcmdout LcdLine2Home
	Lcdout "Clave?"
Return                                            
mensaje3:
	Lcdcmdout LcdClear
	Lcdout " Acceso Denegado"
Return                                            
mensaje4:
	Lcdcmdout LcdClear
	Lcdout "Acceso Permitido"
Return                                            
mensaje5:
	Lcdcmdout LcdClear
	Lcdout " Clave Cambiada "
Return                                            
mensaje6:
	Lcdcmdout LcdClear
	Lcdout "  No Concuerdan "
Return                                            
mensaje7:
	Lcdcmdout LcdClear
	Lcdout " Ingrese Nueva  "
	Lcdcmdout LcdLine2Home
	Lcdout "     Clave      "
Return                                            

teclado:
	temp1 = 0
	Gosub get_button
	If button = 0 Then Goto salir3
	temp1 = button
	WaitUs 100
	Gosub get_button
	temp2 = temp1 - button
	If temp2 = 0 Then
	button = temp1
	Else
	button = 0
	Endif
	salir3:
Return                                            

get_button:
	button = 0
	PORTB = 0x00
	TRISB = 0xf0
	col1 = 1
	If raw1 = 1 Then button = 1
	If raw2 = 1 Then button = 4
	If raw3 = 1 Then button = 7
	If raw4 = 1 Then button = 0x0a
	col1 = 0
	If button <> 0 Then Return
	col2 = 1
	If raw1 = 1 Then button = 2
	If raw2 = 1 Then button = 5
	If raw3 = 1 Then button = 8
	If raw4 = 1 Then button = 0
	col2 = 0
	If button <> 0 Then Return
	col3 = 1
	If raw1 = 1 Then button = 3
	If raw2 = 1 Then button = 6
	If raw3 = 1 Then button = 9
	If raw4 = 1 Then button = 0x0b
	col3 = 0
	If button <> 0 Then Return
	col4 = 1
	If raw1 = 1 Then button = 0x0c
	If raw2 = 1 Then button = 0x0d
	If raw3 = 1 Then button = 0x0e
	If raw4 = 1 Then button = 0x0f
	col4 = 0
Return                                            
abrir:
temp4 = TRISA
temp3 = PORTA
TRISA = 0x00
PORTA = %00000001
WaitMs 5
TRISA = temp4
PORTA = temp3
Return
 
Última edición por un moderador:
Atrás
Arriba