;***** Definiciones
CBLOCK 0x21
CONFIG_SEM0
CONFIG_SEM1
CONFIG_SEM2
CONFIG_SEM3
CONFIG_SEM4
CONFIG_SEM5
CONFIG_SEM6
CONFIG_SEM7
ENDC
CBLOCK
CONTADOR1 ;contador proposito general
CONTADOR2
ENDC
;********************acualiza_sem*********************
ACTUALIZA_SEM
;*****************************************************
SEL_PRIMER_SEM ;Seleccionamos 1er sem
clrf CONTADOR1 ;Contador1 se dedicará a APUNTAR variables CONFIG_SEMX
clrf CONTADOR2 ;Contador2 marcará la luz a actualizar
R_SEMAFORO ;Refresco_Semaforo
movfw CONTADOR1
addlw 0x021 ;Posicion de la primera variable, se le suma el contador
movwf FSR ;se pasa a FSR para direccionamiento indirecto
R_LUZ ;Refresco_Luz
bcf CLOCK_SEM ;Ponemos a 0 el clock de semaforos
bsf DATA_SEM ;Ponemos a 1 DATA
btfss INDF,CONTADOR2 ;Exepto si el dato debe ser 0
bcf DATA_SEM
bsf CLOCK_SEM ;Ponemos a 1 el clock del semaforo
;Comprobamos si se terminó el bucle luz
movlw 0x07 ;Comprobamos si hemos llegado al final del bucle
xorwf CONTADOR2,W
btfsc STATUS,Z
goto R_LUZ_SALIR ;Salimos del bucle si termino
incf CONTADOR2,F ;Incrementamos contador
goto R_LUZ ;y volvemos a realizar el bucle.
R_LUZ_SALIR
;Comprobamos si terminó el bucle semaforo
movlw 0x07
xorwf CONTADOR1,W
btfsc STATUS,Z
goto A_S_SALIR
incf CONTADOR1,F
SEL_SIGUI_SEM ;Seleccionamos el siguiente semaforo
clrf CONTADOR2 ;Borramos contador2 de luces
goto R_SEMAFORO
A_S_SALIR
return