;---------------Encabezado-------------
LIST P=16F84A
INCLUDE <P16F84A.INC>
CBLOCK 0x0C
ContA
ENDC
;-------Configuración de puertos-------
ORG 0x00
GOTO inicio
ORG 0x04
GOTO ISR
ORG 0X05
inicio
BSF STATUS,RP0 ; configurando puertos
clrf TRISB
MOVLW b'11111111' ; carga w con 0000 0001
MOVWF TRISA ; RB0/INT es entrada
BCF OPTION_REG,6 ; seleccionamos flanco descendente
BCF STATUS,RP0
;-------Habilitación de interrupciones-------
BSF INTCON,GIE ; habilitamos todas las interrupciones
BSF INTCON,INTE ; que sean interrupciones externas
CLRF PORTB ; limpio el puerto B
movlw d'1' ; Primer número por donde quieres que empiece el conteo.
movwf ContA ; Guarda el valor de W a F
Pulsador
btfsc PORTA,4 ; Botón pulsado.
goto Pulsador ; si no está pulsado vuelve a Pulsador
movf ContA,W ; Si esta pulsado? pasa ContA a W
movwf PORTB ; muestra el resultado por PORTB.
call Retardo_500ms
clrf PORTB
goto Pulsador
;-------------Rutina de servicio de interrupciones-------------
ISR
incf ContA ;incrementa en 1 los segundos
movf ContA,W
call Retardo_500ms
BCF INTCON,INTF ; borro bandera de interrupción
RETFIE
INCLUDE <RETARDOS.INC>
END clrf TRISB
MOVLW b'11111111' ; carga w con 0000 0001
MOVWF TRISA ; RB0/INT es entrada
PUSH MOVWF W_TEMP ; Copy W to TEMP register,
SWAPF STATUS, W ; Swap status to be saved into W
MOVWF STATUS_TEMP ; Save status to STATUS_TEMP register
;
;
; Aca tu rutina de interrupcion
;
;
;
POP SWAPF STATUS_TEMP,W ; Swap nibbles in STATUS_TEMP register
; and place result into W
MOVWF STATUS ; Move W into STATUS register
; (sets bank to original state)
SWAPF W_TEMP, F ; Swap nibbles in W_TEMP and place result in W_TEMP
SWAPF W_TEMP, W ; Swap nibbles in W_TEMP and place result into W
RETFIECBLOCK 0x0C
Guarda_W
Guarda_Status
Guarda_Cont_A
Cont_A
ENDCmovwf Guarda_W
swapf STATUS,W
movwf Guarda_Status
movf Cont_A,W
movwf Guarda_Cont_Amovf Guarda_Cont_A,W
movwf Cont_A
swapf Guarda_Status,W
movwf STATUS
swapf Guarda_W,F
swapf Guarda_W,W
BCF INTCON,INTF ; borro bandera de interrupción
RETFIE;---------------Encabezado-------------
LIST P=16F628A
INCLUDE <P16F628A.INC>
CBLOCK 0x0C
Guarda_W
Guarda_Status
Guarda_Cont_A
Cont_A
ENDC
;-------Configuración de puertos-------
ORG 0x00
GOTO inicio
ORG 0x04
GOTO ISR
ORG 0X05
inicio
BSF STATUS,RP0 ; configurando puertos
clrf TRISA
MOVLW b'11111111'
MOVWF TRISB
BCF OPTION_REG,6 ; seleccionamos flanco descendente
BCF STATUS,RP0
;-------Habilitación de interrupciones-------
BSF INTCON,GIE ; habilitamos todas las interrupciones
BSF INTCON,INTE ; que sean interrupciones externas
CLRF PORTA ; limpio el puerto B
movlw d'1' ; Primer número por donde quieres que empiece el conteo.
movwf Cont_A ; Guarda el valor de W a F
; --------------Guardamos los registros antes de la interrupción ----------------------
movwf Guarda_W
swapf STATUS,W
movwf Guarda_Status
movf Cont_A,W
movwf Guarda_Cont_A
Pulsador
btfsc PORTB,0 ; Botón pulsado.
goto Pulsador ; si no está pulsado vuelve a Pulsador
movf Cont_A,W ; Si esta pulsado? pasa ContA a W
movwf PORTA ; muestra el resultado por PORTB.
call Retardo_500ms
clrf PORTA
goto Pulsador
;-------------Rutina de servicio de interrupciones-------------
ISR
incf Cont_A ;incrementa en 1 los segundos
movf Cont_A,W
call Retardo_500ms
; ---------------------- antes de acabar la interrupción ponemos todos los registros como antes.
movf Guarda_Cont_A,W
movwf Cont_A
swapf Guarda_Status,W
movwf STATUS
swapf Guarda_W,F
swapf Guarda_W,W
BCF INTCON,INTF ; borro bandera de interrupción
RETFIE
INCLUDE <RETARDOS.INC>
END
CBLOCK 0x0C
Guarda_W
Guarda_Status
Guarda_Cont_A
Cont_A
ENDC
; --------------Guardamos los registros antes de la interrupción ----------------------
movwf Guarda_W
swapf STATUS,W
movwf Guarda_Status
movf Cont_A,W
movwf Guarda_Cont_A
Pulsador
btfsc PORTB,0 ; Botón pulsado.
goto Pulsador ; si no está pulsado vuelve a Pulsador
movf Cont_A,W ; Si esta pulsado? pasa ContA a W
movwf PORTA ; muestra el resultado por PORTB.
call Retardo_500ms
clrf PORTA
goto Pulsador
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT & _DATA_CP_OFF & _LVP_OFF & _MCLRE_OFF
LIST P=16F628A
INCLUDE <P16F628A.INC>
CBLOCK 0x20
contador
pulsador
ENDC
#DEFINE Salida PORTB,3 ; Puerto donde se conecta los diodos LED.
#DEFINE Un_segundo_carga -d'39'
; ZONA DE CÓDIGOS ********************************************************************
ORG 0x05 ; El programa comienza en la dirección 0.
goto Inicio
org 4
goto Boton_int
Inicio
bsf STATUS,RP0 ; Acceso al Banco 1.
clrf TRISB
movlw b'00000111'
movwf OPTION_REG
movwf CMCON
bcf STATUS,RP0 ; Acceso al Banco 0.
clrf PORTB
movlw b'10100000'
movwf INTCON
Memoria
movlw d'10'
movwf contador
movlw d'2'
movwf pulsador
Probar
movf pulsador,W
sublw d'2'
btfss STATUS,Z ; revisa si activar_display_1 ha llegado al límite superior, si no es asó salta una línea y sigue el conteo.
goto Principal
movf pulsador,W
sublw d'3'
btfss STATUS,Z ; revisa si activar_display_1 ha llegado al límite superior, si no es asó salta una línea y sigue el conteo.
goto Un_segundo
Principal
movlw d'100'
movwf contador
bsf Salida
call Un_segundo
movlw d'100'
movwf contador
bcf Salida
call Un_segundo
goto Inicio
Un_segundo
movlw Un_segundo_carga
movwf TMR0
bcf INTCON,T0IF
Timer0_Rebosamiento
btfss INTCON,T0IF
goto Timer0_Rebosamiento
decfsz contador,1
goto Un_segundo
RETURN
Boton_int
btfsc Salida
goto Principal_int
goto Un_segundo_int
Principal_int
incf pulsador
bcf INTCON,T0IF
retfie
Un_segundo_int
decf pulsador
bcf INTCON,T0IF
retfie
END
Error[118] E:\BINWATCH\PRUEBAS\UNSEGUNDO_PIC16F628_INT.ASM 20 : Overwriting previous address contents (0005)
Error[118] E:\BINWATCH\PRUEBAS\UNSEGUNDO_PIC16F628_INT.ASM 20 : Overwriting previous address contents (0005)
Message[302] E:\BINWATCH\PRUEBAS\UNSEGUNDO_PIC16F628_INT.ASM 21 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[302] E:\BINWATCH\PRUEBAS\UNSEGUNDO_PIC16F628_INT.ASM 23 : Register in operand not in bank 0. Ensure that bank bits are correct.
Message[305] E:\BINWATCH\PRUEBAS\UNSEGUNDO_PIC16F628_INT.ASM 75 : Using default destination of 1 (file).
Message[305] E:\BINWATCH\PRUEBAS\UNSEGUNDO_PIC16F628_INT.ASM 79 : Using default destination of 1 (file).