; ------------------------------------------------------------------------------
; -------------------------------------- TAD LEDS ------------------------------
; ------------------------------------------------------------------------------
LEDS_F_INIT
CLRF LEDS_V_COUNTER,0
CLRF LEDS_V_FLAGS,0 ; b[0] = Scanning direction, b[1] = Blinking status
CLRF LEDS_V_STATUS,0
CLRF LEDS_V_STATUS,0
; DEFAULT CHECKPOINT / LIMIT FOR PROGRESS BAR
MOVLW .0
MOVWF LEDS_V_WORKMODE,0
MOVLW .30
MOVWF LEDS_V_PROGRESS_CHECKPOINT,0
CALL LEDS_F_STARTMODE
RETURN
LEDS_F_RUN
MOVLW .0
SUBWF LEDS_V_WORKMODE,0
BTFSC STATUS,Z,0
GOTO LEDS_F_RESET_STATUS
MOVLW .1
SUBWF LEDS_V_WORKMODE,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_RUN
MOVLW .2
SUBWF LEDS_V_WORKMODE,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_RUN
MOVLW .10
SUBWF LEDS_V_WORKMODE,0
BTFSC STATUS,Z,0
GOTO LEDS_F_BLINKING_5HZ
MOVLW .11
SUBWF LEDS_V_WORKMODE,0
BTFSC STATUS,Z,0
GOTO LEDS_F_BLINKING_10HZ
; SI NO EXISTE MODO CORRECTO ENVIAMOS AL MODO ESPERA
MOVLW .0
MOVWF LEDS_V_WORKMODE,0
RETURN
LEDS_F_RESET_STATUS ; Cuando cambiemos el modo de trabajo, reseteamos los estados
CLRF LEDS_V_FLAGS,0
CLRF LEDS_V_STATUS,0
RETURN
; ------ STARTING MODE START -----
LEDS_F_STARTMODE
CLRF LATD,0
CLRF LATE,0
BSF LATD,RD0,0
BSF LATD,RD1,0
RETURN
; ------ STARTING MODE END ------
; ----- SCANNING MODE START -----
LEDS_F_SCANNING_RUN
MOVLW LEDS_TICKS_CHECKPOINT ; Es un define de arriba
CPFSEQ LEDS_V_COUNTER,0
RETURN
CLRF LATD,0 ; Apagamos todos los leds
CLRF LATE,0
MOVLW .0
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_0
MOVLW .1
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_1
MOVLW .2
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_2
MOVLW .3
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_3
MOVLW .4
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_4
MOVLW .5
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_5
MOVLW .6
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_6
MOVLW .7
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_7
MOVLW .8
SUBWF LEDS_V_STATUS,0,0
BTFSC STATUS,Z,0
GOTO LEDS_F_SCANNING_STATUS_8
RETURN
LEDS_F_SCANNING_STATUS_0
BSF LATD,RD0,0
BSF LATD,RD1,0
BSF LEDS_V_FLAGS,0,0 ; Cambiamos direccion a la derecha
GOTO LEDS_F_INCREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_1
BSF LATD,RD1,0
BSF LATD,RD2,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_2
BSF LATD,RD2,0
BSF LATD,RD3,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_3
BSF LATD,RD3,0
BSF LATD,RD4,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_4
BSF LATD,RD4,0
BSF LATD,RD5,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_5
BSF LATD,RD5,0
BSF LATD,RD6,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_6
BSF LATD,RD6,0
BSF LATD,RD7,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_7
BSF LATD,RD7,0
BSF LATE,RE0,0
BTFSC LEDS_V_FLAGS,0,0
GOTO LEDS_F_INCREASE_SCANNING_STATUS
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_SCANNING_STATUS_8
BSF LATE,RE0,0
BSF LATE,RE1,0
BCF LEDS_V_FLAGS,0,0 ; Cambiamos direccion a la izquierda
GOTO LEDS_F_DECREASE_SCANNING_STATUS
LEDS_F_INCREASE_SCANNING_STATUS
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_COUNTER
RETURN
LEDS_F_DECREASE_SCANNING_STATUS
DECF LEDS_V_STATUS,1,0
CLRF LEDS_V_COUNTER
RETURN
; ----- LEDS SCANNING MODE END -----
; ----- LEDS PROGRESS MODE START -----
LEDS_F_PROGRESS_RUN
MOVLW .0
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_0
MOVLW .1
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_1
MOVLW .2
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_2
MOVLW .3
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_3
MOVLW .4
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_4
MOVLW .5
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_5
MOVLW .6
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_6
MOVLW .7
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_7
MOVLW .8
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_8
MOVLW .9
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_9
MOVLW .10
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_10
MOVLW .11
SUBWF LEDS_V_STATUS,0
BTFSC STATUS,Z,0
GOTO LEDS_F_PROGRESS_STATUS_11
CLRF LEDS_V_STATUS,0 ; Si no es ningun modo de los anteriores, algo ha pasado, reseteamos
RETURN
LEDS_F_PROGRESS_STATUS_0
CLRF LATD,0
CLRF LATE,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_1
BSF LATD,0,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_2
BSF LATD,1,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_3
BSF LATD,2,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_4
BSF LATD,3,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_5
BSF LATD,4,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_6
BSF LATD,5,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_7
BSF LATD,6,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_8
BSF LATD,7,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_9
BSF LATE,0,0
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
INCF LEDS_V_STATUS,1,0
CLRF LEDS_V_PROGRESS_COUNTER
RETURN
LEDS_F_PROGRESS_STATUS_10
SETF LATD,0
BSF LATE,0
BSF LATE,1
MOVF LEDS_V_PROGRESS_COUNTER,0
CPFSEQ LEDS_V_PROGRESS_CHECKPOINT,0
RETURN
LEDS_F_PROGRESS_STATUS_11
CLRF LEDS_V_PROGRESS_COUNTER,0
CLRF LEDS_V_STATUS,0
; Test --> Cuando acabe la barra de progreso, enviamos a modo blinking 10hz
; MOVLW .10
; MOVWF LEDS_V_WORKMODE
; Test --
RETURN
; ----- LEDS PROGRESS MODE START -----
; ----- LEDS BLINKING MODE START -----
LEDS_F_BLINKING_5HZ
MOVLW 0x63
CPFSGT LEDS_V_BLINKING_COUNTER,0
RETURN
CLRF LEDS_V_BLINKING_COUNTER,0
BTFSS LEDS_V_FLAGS,1
GOTO LEDS_F_ALLON
GOTO LEDS_F_ALLOFF
LEDS_F_BLINKING_10HZ
MOVLW .50
CPFSGT LEDS_V_BLINKING_COUNTER,0
RETURN
CLRF LEDS_V_BLINKING_COUNTER,0
BTFSS LEDS_V_FLAGS,1
GOTO LEDS_F_ALLON
GOTO LEDS_F_ALLOFF
; ----- LEDS BLINKING MODE END -----
LEDS_F_ALLON
BSF LEDS_V_FLAGS,1
SETF LATD,0
SETF LATE,0
RETURN
LEDS_F_ALLOFF
BCF LEDS_V_FLAGS,1
CLRF LATD,0
CLRF LATE,0
RETURN
; ------------------------------------------------------------------------------
; ---------------------------------- END TAD LEDS ------------------------------
; ------------------------------------------------------------------------------