;------------------------------------------------------------
; Código assembler generado por Niple V6.6.2
; Proyecto: 
; Autor: SANCHEZ SANCHEZ AARON
; Fecha: 31/03/2023
; PIC: 16F873A
; Velocidad de reloj: 4 Mhz
; Descripcion: 
;------------------------------------------------------------


 LIST    P=PIC16F873A


_HS_OSC               equ  0x3FFE
_DEBUG_OFF            equ  0x3FFF
_WDT_OFF              equ  0x3FFB
_PWRTE_ON             equ  0x3FF7
_BODEN_OFF            equ  0x3FBF
_LVP_OFF              equ  0x3F7F
_CPD_OFF              equ  0x3FFF
_CP_OFF               equ  0x3FFF
_WRT_ENABLE_OFF       equ  0x3DFF

 __config _HS_OSC & _DEBUG_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_ENABLE_OFF & _CP_OFF


;------------------------------------------------------------
;                  Declaración de Registros
;------------------------------------------------------------
w                     equ  0x0000
status                equ  0x0003
fsr                   equ  0x0004
porta                 equ  0x0005
portb                 equ  0x0006
portc                 equ  0x0007
pclath                equ  0x000a
intcon                equ  0x000b
adcon0                equ  0x001f
_np_w                 equ  0x0020
_np_temp1             equ  0x0024
_np_temp2             equ  0x0025
_np_temp3             equ  0x0026
_np_temp4             equ  0x0027
_np_temp5             equ  0x0028
_np_temp1_int         equ  0x0029
_np_temp2_int         equ  0x002a
_np_temp3_int         equ  0x002b
_np_temp4_int         equ  0x002c
_np_banderas2         equ  0x0030
_np_est_inte          equ  0x0031
_np_indice            equ  0x0032
_np_presionada        equ  0x0034
_np_resultado         equ  0x0035
_np_status            equ  0x0036
_np_t1_bak            equ  0x0037
_np_t2_bak            equ  0x0038
_np_t3_bak            equ  0x0039
_np_t_bak             equ  0x003a
_np_tec               equ  0x003b
_np_tiempo            equ  0x003c
_np_tiempo1           equ  0x003d
_np_tiempo2           equ  0x003e
_np_tiempo3           equ  0x003f
tecla                 equ  0x0041
tiempo_l              equ  0x0042
tiempo_h              equ  0x0043
opcion                equ  0x0081
trisa                 equ  0x0085
trisb                 equ  0x0086
trisc                 equ  0x0087
cmcon                 equ  0x009c
adcon1                equ  0x009f


;------------------------------------------------------------
;                  Declaración de Bits
;------------------------------------------------------------
adon                  equ  0   ;-
c                     equ  0   ;-
gie                   equ  7   ;-
psa                   equ  3   ;-
rb0                   equ  0   ;-
rb1                   equ  1   ;-
rb2                   equ  2   ;-
rb3                   equ  3   ;-
rb4                   equ  4   ;-
rb5                   equ  5   ;-
rb6                   equ  6   ;-
rb7                   equ  7   ;-
rbie                  equ  3   ;-
rbif                  equ  0   ;-
rp0                   equ  5   ;-
rp1                   equ  6   ;-
to                    equ  4   ;-
z                     equ  2   ;-
cancelar              equ  1   ;-
inicio                equ  0   ;-
relay                 equ  4   ;-
un_min                equ  2   ;-
sub_inte              equ  0   ;bandera de subrrutina cancelada por interrupcion.


;------------------------------------------------------------
;               Declaración de Registros EEPROM
;------------------------------------------------------------


;------------------------------------------------------------
;                        Inicio
;------------------------------------------------------------

   org 0x00
   bsf status,rp0                   ;cambiar a banco 1
   bcf opcion,psa
   goto paso2
   org 0x04
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movwf _np_w
   swapf _np_w,1
   movf status,w
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movwf _np_status
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movf _np_tiempo,w
   movwf _np_t_bak
   movf _np_tiempo1,w
   movwf _np_t1_bak
   movf _np_tiempo2,w
   movwf _np_t2_bak
   movf _np_tiempo3,w
   movwf _np_t3_bak
intes
int_1
   btfss intcon,rbie
   goto int_2
   btfsc intcon,rbif
   goto inte_rb4a7
int_2
salir__intes

   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   bsf _np_banderas2,sub_inte       ;activar la bandera de rutina cancelada por interrupcion
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movf _np_t_bak,w
   movwf _np_tiempo
   movf _np_t1_bak,w
   movwf _np_tiempo1
   movf _np_t2_bak,w
   movwf _np_tiempo2
   movf _np_t3_bak,w
   movwf _np_tiempo3
   movf _np_status,w
   movwf status
   swapf _np_w,w
   retfie


   ;------------------------------------------------------------
   ;                      inicio de la interrupción por rb4 a 7
   ;------------------------------------------------------------
inte_rb4a7_salir
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movf portb,w
   bcf intcon,rbif
   goto intes
inte_rb4a7
   call teclado_matricial           ;llamada a rutina teclado_matricial
   movf _np_resultado,w
   movwf tecla

   movf tecla,w                     ;si no es ruido o error de lectura.
   xorlw d'64'
   btfsc status,z
   goto inte_rb4a7_salir
   goto inte_rb4a7_salir

;------------------------------------------------------------
;                      programa principal
;------------------------------------------------------------
paso2
   clrf _np_w
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   clrf _np_temp1
   clrf _np_temp2
   clrf _np_temp3
   clrf _np_temp4
   clrf _np_temp5
   clrf _np_temp1_int
   clrf _np_temp2_int
   clrf _np_temp3_int
   clrf _np_temp4_int
   clrf _np_banderas2
   clrf _np_est_inte
   clrf _np_indice
   clrf _np_presionada
   clrf _np_resultado
   clrf _np_status
   clrf _np_t1_bak
   clrf _np_t2_bak
   clrf _np_t3_bak
   clrf _np_t_bak
   clrf _np_tec
   clrf _np_tiempo
   clrf _np_tiempo1
   clrf _np_tiempo2
   clrf _np_tiempo3
   clrf tecla
   clrf tiempo_l
   clrf tiempo_h
   clrf porta
   movlw b'00000000'                ;configurar el puerto a como xxssssss
   bsf status,rp0                   ;cambiar a banco 1
   movwf trisa
   movlw b'00000111'                ;puerto a = e/s digital
   movwf adcon1
   movlw .7
   movwf cmcon
   bcf status,rp0                   ;cambiar a banco 0
   clrf portb
   movlw b'11110000'                ;configurar el puerto b como eeeessss
   bsf status,rp0                   ;cambiar a banco 1
   movwf trisb
   bcf status,rp0                   ;cambiar a banco 0
   clrf portc
   movlw b'00000000'                ;configurar el puerto c como ssssssss
   bsf status,rp0                   ;cambiar a banco 1
   movwf trisc

   bcf intcon,rbif                  ;limpiar la bandera antes de activarla
   bsf intcon,rbie                  ;activar interrupción por rb4-7.
   bsf intcon,gie                   ;activar habilitador general de interrupciones.
aqui
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   ;escribir en el puerto c
   movlw d'0'
   movwf portc
   clrf tiempo_h
   clrf tiempo_l
paso9


   movf tecla,w                     ;si tecla = d'1'
   xorlw d'1'
   btfss status,z
   goto paso20
   clrf tiempo_h
   movlw b'00110010'
   movwf tiempo_l
   bsf portc,inicio
   bsf portc,relay
paso13

   movlw .10
   call tmp_100_mc                  ;llamada a rutina tmp_100_mc

   movf tecla,w                     ;si tecla = d'4'
   xorlw d'4'
   btfss status,z
   goto paso45
   ;escribir en el puerto c
   movlw d'0'
   movwf portc
   bsf portc,cancelar

   movlw .1
   call tmp_1_mgc                   ;llamada a rutina tmp_1_mgc
   bcf portc,cancelar
   goto aqui
   goto aqui
paso20


   movf tecla,w                     ;si tecla = d'2'
   xorlw d'2'
   btfss status,z
   goto paso31
   clrf tiempo_h
   movlw b'01100100'
   movwf tiempo_l
   bsf portc,un_min
   bsf portc,relay
paso24

   movlw .10
   call tmp_100_mc                  ;llamada a rutina tmp_100_mc

   movf tecla,w                     ;si tecla = d'4'
   xorlw d'4'
   btfss status,z
   goto paso48
   ;escribir en el puerto c
   movlw d'0'
   movwf portc
   bsf portc,cancelar

   movlw .1
   call tmp_1_mgc                   ;llamada a rutina tmp_1_mgc
   bcf portc,cancelar
   goto aqui
   goto aqui
paso31


   movf tecla,w                     ;si tecla = d'3'
   xorlw d'3'
   btfss status,z
   goto paso9
   clrf tiempo_h
   movlw b'10010110'
   movwf tiempo_l
   bsf portc,un_min
   bsf portc,relay
paso35

   movlw .10
   call tmp_100_mc                  ;llamada a rutina tmp_100_mc

   movf tecla,w                     ;si tecla = d'4'
   xorlw d'4'
   btfss status,z
   goto paso42
   ;escribir en el puerto c
   movlw d'0'
   movwf portc
   bsf portc,cancelar

   movlw .1
   call tmp_1_mgc                   ;llamada a rutina tmp_1_mgc
   bcf portc,cancelar
   goto aqui
   goto aqui
paso45

   movf tiempo_h,w
   btfss status,z
   goto paso45_a
   movf tiempo_l,w
   btfsc status,z
   goto paso45_b
paso45_a
   movf tiempo_l,w
   btfsc status,z
   decf tiempo_h,1
   decf tiempo_l,1
   movf tiempo_h,w
   btfsc status,z
   movf tiempo_l,w
paso45_b
   btfss status,z                   ;si el z = 0
   goto paso13
   goto aqui
paso48

   movf tiempo_h,w
   btfss status,z
   goto paso48_a
   movf tiempo_l,w
   btfsc status,z
   goto paso48_b
paso48_a
   movf tiempo_l,w
   btfsc status,z
   decf tiempo_h,1
   decf tiempo_l,1
   movf tiempo_h,w
   btfsc status,z
   movf tiempo_l,w
paso48_b
   btfss status,z                   ;si el z = 0
   goto paso24
   goto aqui
paso42

   movf tiempo_h,w
   btfss status,z
   goto paso42_a
   movf tiempo_l,w
   btfsc status,z
   goto paso42_b
paso42_a
   movf tiempo_l,w
   btfsc status,z
   decf tiempo_h,1
   decf tiempo_l,1
   movf tiempo_h,w
   btfsc status,z
   movf tiempo_l,w
paso42_b
   btfss status,z                   ;si el z = 0
   goto paso35
   goto aqui


;------------------------------------------------------------
;                  Declaración de Subrutinas
;------------------------------------------------------------

teclado_matricial
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   bcf portb,0
   bcf portb,1
   bcf portb,2
   bcf portb,3
   clrf _np_temp2
teclado_matricial_ta
   incf _np_temp2,1
   btfss status,z
   goto teclado_matricial_ta
   movlw d'01'
   movwf _np_temp1
   btfss portb,4
   goto teclado_matricial_c
   btfss portb,5
   goto teclado_matricial_c
   btfss portb,6
   goto teclado_matricial_c
   btfss portb,7
   goto teclado_matricial_c
   goto teclado_matricial_e
teclado_matricial_c
   bsf portb,0
   bsf portb,1
   bsf portb,2
   bsf portb,3
   btfsc _np_temp1,0
   goto slt_1_no
   goto slt_1_si
slt_1_no
   bcf portb,0
   goto slt_1_s
slt_1_si
   nop
slt_1_s
   btfsc _np_temp1,1
   goto slt_2_no
   goto slt_2_si
slt_2_no
   bcf portb,1
   goto slt_2_s
slt_2_si
   nop
slt_2_s
   btfsc _np_temp1,2
   goto slt_3_no
   goto slt_3_si
slt_3_no
   bcf portb,2
   goto slt_3_s
slt_3_si
   nop
slt_3_s
   btfsc _np_temp1,3
   goto slt_4_no
   goto slt_4_si
slt_4_no
   bcf portb,3
   goto slt_4_s
slt_4_si
   nop
slt_4_s
   movlw d'01'
   movwf _np_temp3
   btfss portb,4
   goto teclado_matricial_d
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   incf _np_temp3,1
   btfss portb,5
   goto teclado_matricial_d
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   incf _np_temp3,1
   btfss portb,6
   goto teclado_matricial_d
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   incf _np_temp3,1
   btfss portb,7
   goto teclado_matricial_d
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   incf _np_temp3,1
   movlw d'4'
   addwf _np_temp2,1
   bcf status,c
   rlf _np_temp1,1
   btfss _np_temp1,4
   goto teclado_matricial_c
   movlw d'64'
   movwf _np_resultado
   movwf _np_presionada
   goto teclado_matricial_s
teclado_matricial_d
   movf _np_temp2,w
   addwf _np_temp3,w
   movwf _np_temp3
   xorwf _np_presionada,w
   btfsc status,z
   goto teclado_matricial_e
   movf _np_temp3,w
   movwf _np_resultado
   movwf _np_presionada
teclado_matricial_tbl
   movlw .00
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_01
   goto teclado_matricial_s
teclado_matricial_01
   movlw .01
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_02
   goto teclado_matricial_s
teclado_matricial_02
   movlw .02
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_03
   goto teclado_matricial_s
teclado_matricial_03
   movlw .03
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_f1
   goto teclado_matricial_s
teclado_matricial_f1
   movlw .04
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_04
   movlw 0xf1
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_04
   movlw .05
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_05
   movlw .04
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_05
   movlw .06
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_06
   movlw .05
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_06
   movlw .07
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_f2
   movlw .06
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_f2
   movlw .08
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_07
   movlw 0xf2
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_07
   movlw .09
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_08
   movlw .07
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_08
   movlw .10
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_09
   movlw .08
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_09
   movlw .11
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_f3
   movlw .09
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_f3
   movlw .12
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_0x13
   movlw 0xf3
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_0x13
   movlw .13
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_00
   movlw .13
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_00
   movlw .14
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_0x14
   movlw .00
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_0x14
   movlw .15
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_f4
   movlw .14
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_f4
   movlw .16
   xorwf _np_resultado,0
   btfss status,z
   goto teclado_matricial_e
   movlw 0xf4
   movwf _np_resultado
   goto teclado_matricial_s
teclado_matricial_e
   movlw d'64'
   movwf _np_resultado
   movwf _np_presionada
teclado_matricial_s
teclado_matricial_f
   bcf portb,0
   bcf portb,1
   bcf portb,2
   bcf portb,3
   clrf _np_temp2
teclado_matricial_th
   incf _np_temp2,1
   btfss status,z
   goto teclado_matricial_th
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   return

tmp_100_mc
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movwf _np_tiempo
   goto tmp_100_mc_1
tmp_100_mc_bucle2

tmp_100_mc_1
   nop
   nop
   nop
   nop
   nop
   nop
   nop
   movlw .22
   movwf _np_tiempo1
tmp_100_mc_bucle1
   nop
   movlw .112
   movwf _np_tiempo2
tmp_100_mc_bucle
   nop
   decfsz _np_tiempo2,1
   goto tmp_100_mc_bucle
   decfsz _np_tiempo1,1
   goto tmp_100_mc_bucle1
   nop
   decfsz _np_tiempo,1
   goto tmp_100_mc_bucle2
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   return

tmp_1_mgc
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   movwf _np_tiempo
   goto tmp_1_mgc_1
tmp_1_mgc_bucle2
   nop
   nop
   nop
   nop
   nop
   nop
   nop
tmp_1_mgc_1
   movlw .10
   movwf _np_tiempo1
tmp_1_mgc_bucle1
   nop
   nop
   movlw .99
   movwf _np_tiempo2
tmp_1_mgc_bucle0

   nop
   nop
   nop
   movlw .200
   movwf _np_tiempo3
tmp_1_mgc_bucle
   nop
   nop
   decfsz _np_tiempo3,1
   goto tmp_1_mgc_bucle
   nop
   nop
   nop
   decfsz _np_tiempo2,1
   goto tmp_1_mgc_bucle0
   nop
   nop
   nop
   decfsz _np_tiempo1,1
   goto tmp_1_mgc_bucle1
   decfsz _np_tiempo,1
   goto tmp_1_mgc_bucle2
   bcf status,rp0                   ;cambiar a banco 0
   bcf status,rp1
   return


;------------------------------------------------------------
;                  DATOS EN MEMORIA EEPROM
;------------------------------------------------------------
   org  0x2100
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff
   data   0xff

 End