Sei sulla pagina 1di 24

Cronometro programable con alarma

LIST

P=16f1787

#include <p16f1787.inc>

; CONFIG1
; __config 0xFFE1
__CONFIG _CONFIG1, _FOSC_XT & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON
& _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON &
_FCMEN_ON
; CONFIG2
; __config 0xDFFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_ON &
_BORV_LO & _LPBOR_OFF & _LVP_OFF

ORG 0x00
GOTO PRINCIPAL
org

0x04

BCF

INTCON,IOCIF

BCF

INTCON,INTF

GOTO INTER
org

0x09

GOTO INICIO_PROG

;--------------------------INTERRUPCIONES----------------------------------'
INTER
BTFSC

INTCON,TMR0IF

GOTO

INTER_TMR0

BANKSEL

PIR1

BTFSC

PIR1,TMR1IF

GOTO

INTER_TMR1

BANKSEL

IOCCF

BTFSC

IOCCF,IOCCF0

GOTO

S_P

BTFSC

IOCCF,IOCCF1

GOTO

RE_SET

BTFSC

IOCCF,IOCCF3

GOTO

INTER_ALARMA

;---------------------INTERRUPCION STAR-PAUSE----------------S_P
BANKSEL

IOCCF

BCF

IOCCF,IOCCF0

MOVLB

.2

BSF

0X35,0

RETFIE
;--------------------------INTERRUCION DEL TMR0(BARRIDO)--------------------'
INTER_TMR0
BCF

INTCON,TMR0IF

MOVLB

.2

BSF

0X39,0

BANKSEL

TMR0

MOVLW

0XC1

MOVWF

TMR0

RETFIE
;--------------------INTERRUPCION RESET------------------------

RE_SET
MOVLB

.2

BSF

0X37,0

BANKSEL

IOCCF

BCF

IOCCF,IOCCF1

RETFIE
;------------------INTERRUPCION DE ALARMA----------------------INTER_ALARMA
MOVLB

.2

BSF

0X45,0

BANKSEL

IOCCF

BCF

IOCCF,IOCCF3

RETFIE
RETARDO_500MS
BANKSEL

.0

MOVLW

.10

MOVWF

0X23

MOVLW

.20

MOVWF

0X22

MOVLW

.250

MOVWF

0X21

NOP
DECFSZ
GOTO

0X21,F
$-.2

DECFSZ
GOTO

0X22,F
$-.6

DECFSZ
GOTO

0X23,F
$-.10

RETURN
;---------------------INTERRUPCION POR EL TMR1---------------INTER_TMR1
BANKSEL

PIR1

BCF

PIR1,TMR1IF

CL
INCF

CONT1

MOVF

CONT1,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP1
CONT1,W
0X09

BTFSC

STATUS,0

GOTO

SALIR_TMR1

CLRF

CONT1

MOVLW

CERO

MOVWF

DP1

CH
INCF

CONT2

MOVF

CONT2,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP2
CONT2,W
0X09

BTFSC

STATUS,0

GOTO

SALIR_TMR1

CLRF

CONT2

MOVLW

CERO

MOVWF

DP2

SL
INCF

CONT3

CALL

VERI_ALAR

MOVF

CONT3,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP3
CONT3,W
0X09

BTFSC

STATUS,0

GOTO

SALIR_TMR1

CLRF

CONT3

MOVLW

CERO

MOVWF

DP3

SH
INCF

CONT4

CALL

VERI_ALAR

MOVF

CONT4,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP4
CONT4,W
0X05

BTFSC

STATUS,0

GOTO

SALIR_TMR1

CLRF

CONT4

MOVLW

CERO

MOVWF

DP4

ML
INCF

CONT5

CALL

VERI_ALAR

MOVF

CONT5,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP5
CONT5,W
0X09

BTFSC

STATUS,0

GOTO

SALIR_TMR1

CLRF

CONT5

MOVLW

CERO

MOVWF

DP5

MH
INCF

CONT6

CALL

VERI_ALAR

MOVF

CONT6,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP6
CONT6,W
0X05

BTFSC

STATUS,0

GOTO

SALIR_TMR1

CLRF

CONT6

MOVLW

CERO

MOVWF

DP6

GOTO

NUMEROS

SALIR_TMR1

ADDWF

PCL,F

RETLW

CERO

RETLW

UNO

RETLW

DOS

RETLW

TRES

RETLW

CUATRO

RETLW

CINCO

RETLW

SEIS

RETLW

SIETE

RETLW

OCHO

RETLW

NUEVE

RETLW

CERO

VERI_ALAR MOVLB
MOVF
XORWF
BTFSS

.2
AUX1,W
CONT3,W
STATUS,Z

RETURN
MOVF

AUX2,W

XORWF
BTFSS

CONT4,W
STATUS,Z

RETURN
MOVF
XORWF
BTFSS

AUX3,W
CONT5,W
STATUS,Z

RETURN
MOVLB
MOVF
XORWF
BTFSS

.0
AUX4,W
CONT6,W
STATUS,Z

RETURN
BANKSEL

T1CON

MOVLW

0X34

MOVWF

T1CON

MOVLB

.2

BSF

0X48,0

RETURN

SALIR_TMR1
BANKSEL

TMR0

MOVLW

0X1E

MOVWF

TMR1L

MOVLW

0XFB

MOVWF

TMR1H

RETFIE

PRINCIPAL
;--------------CONFIGURANCION DE LA FRECUENCIA A 4MHZ-------------------/
BANKSEL
CLRF

OSCCON
OSCCON

MOVLW

0X68

MOVWF

OSCCON

;--------------CONFIGURACION DE INTERRUPCIONES Y PUERTOS----------------/


CLRF

INTCON

BANKSEL

OPTION_REG

MOVLW

0X02

MOVWF

OPTION_REG

BANKSEL

TRISC

BSF

TRISC,TRISC3

BSF

TRISC,TRISC0

BSF

TRISC,TRISC1

BCF

TRISC,TRISC5

CLRF

TRISD

CLRF

TRISB

BANKSEL

WPUC

BSF

WPUC,TRISC0

BSF

WPUC,TRISC1

BSF

WPUC,TRISC3

BANKSEL

IOCCN

BSF

IOCCN,IOCCN0

BSF

IOCCN,IOCCN1

BSF

IOCCN,IOCCN3

BANKSEL

PIE1

MOVLW

0X01

MOVWF

PIE1

BANKSEL

T1CON

MOVLW

0X34

MOVWF

T1CON

CLRF

T1GCON

MOVLW

0XC1

BANKSEL

TMR0

MOVWF

TMR0

MOVLW

0X1E

MOVWF

TMR1L

MOVLW

0XFB

MOVWF

TMR1H

MOVLW

DP1

MOVWF

FSR1

MOVLW

0XF8

MOVWF

INTCON

;----------------------NUMEROS EN 7 SEGMENTO Y DISPLAYS-------------------------/

CERO

EQU

3F

UNO

EQU

06

DOS
TRES

EQU
EQU

5B
4F

CUATRO

EQU

66

CINCO

EQU

6D

SEIS

EQU

7D

SIETE

EQU

07

OCHO

EQU

7F

NUEVE

EQU

67

DP1

EQU

70

DP2

EQU

71

DP3

EQU

72

DP4

EQU

73

DP5

EQU

74

DP6

EQU

75

ON

EQU

76

CONT1

EQU

77

CONT2

EQU

78

CONT3

EQU

79

CONT4

EQU

7A

CONT5

EQU

7B

CONT6

EQU

7C

AUX1

EQU

7D

AUX2

EQU

7E

AUX3

EQU

7F

AUX4

EQU

58

;--------------------------INICIANDO EL PROGRAMA-------------------------;
INICIO_PROG
MOVLB

.2

CLRF

0X35

CLRF

0X39

CLRF

0X38

CLRF

0X37

CLRF

AUX2

CLRF

AUX1

CLRF

AUX3

MOVLB
CLRF

.0
AUX4

MOVLW

0X01

MOVWF

ON

MOVLW

CERO

MOVWF

DP1

MOVWF

DP2

MOVWF

DP3

MOVWF

DP4

MOVWF

DP5

MOVWF

DP6

MOVF

INDF1,W

MOVWF
MOVF

PORTB
ON,W

MOVWF

PORTD

MOVLB

.2

VERIFICACION

BTFSC

0X45,0

GOTO

AJUSTE_ALARMA

BTFSC

0X48,0

GOTO

SONAR_ALARMA

BTFSC

0X35,0

GOTO

STAR_PAUSE

BTFSC

0X37,0

GOTO

REINICIO

BTFSC

0X39,0

CALL

NORMAL_BARRIDO

GOTO

VERIFICACION

NORMAL_BARRIDO
MOVLB

.2

BCF

0X39,0

BANKSEL

PORTB
MOVF

INDF1,W

MOVWF
MOVF
MOVWF
INCF

PORTB
ON,W
PORTD
FSR1,F

RLF

ON,F

MOVLW

0X76

XORWF

FSR1,W

BTFSS

STATUS,Z

RETURN
MOVLW

0X01

MOVWF

ON

MOVLW

DP1

MOVWF

FSR1

RETURN
MINUTO_BARRIDO
MOVLB

.2

BCF

0X39,0

MOVLW

0X10

MOVWF

ON

MOVLW

DP5

MOVWF

FSR1

BANKSEL

PORTB

MOVF

INDF1,W

MOVWF
MOVF

PORTB
ON,W

MOVWF
CALL

PORTD
RETARDO_500MS

BANKSEL

PORTB

MOVLW

0X20

MOVWF

ON

MOVLW

DP6

MOVWF

FSR1

BANKSEL

PORTB

MOVF

INDF1,W

MOVWF
MOVF
MOVWF
CALL

PORTB
ON,W
PORTD
RETARDO_500MS

RETURN
SEGUNDOS_BARRIDO
MOVLB

.2

BCF

0X39,0

MOVLW

0X04

MOVWF

ON

MOVLW

DP3

MOVWF

FSR1

BANKSEL

PORTB

MOVF

INDF1,W

MOVWF
MOVF

PORTB
ON,W

MOVWF
CALL

PORTD
RETARDO_500MS

MOVLW

0X08

MOVWF

ON

MOVLW

DP4

MOVWF

FSR1

BANKSEL

PORTB

MOVF

INDF1,W

MOVWF
MOVF
MOVWF
CALL
RETURN

PORTB
ON,W
PORTD
RETARDO_500MS

;-------------------------------STAR-PAUSE---------------STAR_PAUSE
MOVLB

.2

BCF

0X35,0

BANKSEL

T1CON

MOVF
XORLW

0X35

BTFSS

STATUS,Z

GOTO

SI_UNO

MOVLW

0X34

MOVWF

T1CON

GOTO
SI_UNO

T1CON,W

BSF
GOTO

VERIFICACION
T1CON,TMR1ON
VERIFICACION

SONAR_ALARMA
MOVLB

.2

BCF

0X48,0

MOVLW

.100

MOVWF

0X23

MOVLW

.150

MOVWF

0X22

MOVLB

.2

BTFSC

0X39,0

CALL

NORMAL_BARRIDO

CALL

CAMBIAR_PIN

MOVLW

.100

MOVWF

0X21

MOVLB

.2

BTFSC

0X37,0

GOTO

INICIO_PROG

DECFSZ
GOTO

0X21,F
$-.4

DECFSZ
GOTO

0X22,F
$-.12

DECFSZ

0X23,F

GOTO

$-.16

CLRF

AUX1

CLRF

AUX2

CLRF

AUX3

MOVLB

.2

CLRF

AUX4

GOTO

INICIO_PROG

CAMBIAR_PIN
BANKSEL

PORTC

BTFSS

PORTC,RC5

GOTO

ENCENDER_PIN

BCF

PORTC,RC5

RETURN
ENCENDER_PIN
BSF
RETURN

PORTC,RC5

REINICIO
MOVLB

.2

BCF

0X37,0

BANKSEL

T1CON

MOVLW

0X34

MOVWF

T1CON

MOVLW

0XC1

BANKSEL

TMR0

MOVWF

TMR0

MOVLW

0X1E

MOVWF

TMR1L

MOVLW

0XFB

MOVWF

TMR1H

MOVLW

CERO

MOVWF

DP1

MOVWF

DP2

MOVWF

DP3

MOVWF

DP4

MOVWF

DP5

MOVWF

DP6

CLRF

CONT1

CLRF

CONT2

CLRF

CONT3

CLRF

CONT4

CLRF

CONT5

CLRF

CONT6

GOTO

VERIFICACION

AJUSTE_ALARMA
MOVLB

.2

BCF

0X45,0

CLRF

0X35

CLRF

0X39

CLRF

0X37

BANKSEL

T1CON

MOVLW

0X34

MOVWF

T1CON

MOVLW

CERO

MOVWF

DP1

MOVWF

DP2

MOVF

AUX1,W

CALL

NUMEROS

MOVWF

DP3

MOVF

AUX2,W

CALL

NUMEROS

MOVWF

DP4

MOVF

AUX3,W

CALL

NUMEROS

MOVWF

DP5

MOVF

AUX4,W

CALL

NUMEROS

MOVWF

DP6

CLRF

CONT1

CLRF

CONT2

CLRF

CONT3

CLRF

CONT4

CLRF

CONT5

CLRF

CONT6

MOVLW

0X01

MOVWF

ON

MOVLW

DP1

MOVWF

FSR1

MOVLB

.2

MODIF_MIN

CLRF

0X35

CLRF

0X45

CLRF

0X37

CLRF

0X39

GOTO

COMPROBAR_MIN

COMPROBAR_MIN
MOVLB

.2

BTFSC

0X35,0

CALL

AUMENTAR_MIN

BTFSC

0X37,0

GOTO

SALIR_ALAR

MOVLB

.2

BTFSC

0X45,0

GOTO

MODIF_SEG

BTFSC

0X39,0

CALL

MINUTO_BARRIDO

GOTO

COMPROBAR_MIN

AUMENTAR_MIN
AUMEN_ML
MOVLB

.2

BCF

0X35,0

INCF

AUX3

MOVF

AUX3,W

CALL

NUMEROS

MOVWF
MOVF

DP5
AUX3,W

SUBLW
BTFSC

0X09
STATUS,0

RETURN
CLRF

AUX3

MOVLW

CERO

MOVWF

DP5

MOVLB

.0

AUMEN_MH

INCF

AUX4

MOVF

AUX4,W

CALL

NUMEROS

MOVWF
MOVF
SUBLW

DP6
AUX4,W
0X05

BTFSC

STATUS,0

RETURN
CLRF

AUX4

MOVLW

CERO

MOVWF

DP6

RETURN
MODIF_SEG
MOVLB

.2

CLRF

0X35

CLRF

0X45

CLRF

0X37

CLRF

0X39

GOTO

COMPROBAR_SEG

COMPROBAR_SEG
MOVLB

AUMENTAR_SEG

.2

BTFSC

0X45,0

GOTO

SALIR_ALAR

BTFSC

0X35,0

CALL

AUMENTAR_SEG

BTFSC

0X37,0

GOTO

SALIR_ALAR

BTFSC

0X39,0

CALL

SEGUNDOS_BARRIDO

GOTO

COMPROBAR_SEG

AUMEN_SL
MOVLB

.2

BCF

0X35,0

INCF

AUX1

MOVF

AUX1,W

CALL

NUMEROS

MOVWF
MOVF

DP3
AUX1,W

SUBLW
BTFSC

0X09
STATUS,0

RETURN
CLRF

AUX1

MOVLW

CERO

MOVWF

DP3

MOVLB

.2

AUMEN_SH

INCF

AUX2

MOVF

AUX2,W

CALL

NUMEROS

MOVWF
MOVF

DP4
AUX2,W

SUBLW
BTFSC

0X05
STATUS,0

RETURN
CLRF
MOVLW

AUX2
CERO

MOVWF

DP4

RETURN
SALIR_ALAR
BANKSEL

T1CON

MOVLW

0X1E

MOVWF

TMR1L

MOVLW

0XFB

MOVWF

TMR1H

MOVLW

0XC1

MOVWF

TMR0

MOVLB

.2

CLRF

0X35

CLRF

0X45

CLRF

0X37

CLRF

0X39

MOVLW

0XF8

MOVWF

INTCON

MOVLW

CERO

MOVWF

DP1

MOVWF

DP2

MOVWF

DP3

MOVWF

DP4

MOVWF

DP5

MOVWF

DP6

GOTO
END

VERIFICACION