	LIST P=16F88, 
	#INCLUDE "p16F88.inc"

	__CONFIG _CONFIG1,_CPD_OFF&_CP_OFF&_DEBUG_OFF &_LVP_OFF&_MCLR_ON&_PWRTE_ON&_WDT_OFF&_INTRC_IO & _BODEN_OFF
			
estado	equ	0x03	; Haciendo asignaciones
trisa	equ	0x05
trisb	equ	0x06	      
porta	equ	0x05
portb	equ	0x06
RET		equ h'0C'
RET1	equ h'0D'
RET2	equ h'0E'
PDel0   equ h'0D'
PDel1	equ h'0E'

	

	CBLOCK 0x20 ; Start Registers at End of the Values
  llaves
	ENDC

;================= Start of Code =================
		org 0
		goto inicio
		org 4

inicio	BSF     estado,5	; cambio al banco 1 del pic
        MOVLW   0x1F
        MOVWF   trisa		; Asigna al puerto A como entrada
        MOVLW   0x00	
        MOVWF   trisb		; y Al puerto B como salida
        BCF     estado,5	; Regresa al banco 0
        CLRF    porta		; limpia el puerto A
        CLRF    portb		; limpia el puerto B


swich   MOVF	porta,0		; carga w con el puerto A
        ANDLW   b'00001111'     	; retiene los 4 bits de interes (las llaves)
		MOVWF   llaves		; y los guarda en llaves
        XORLW   0x00		; verifica si es el primer efecto
        BTFSC   estado,2	; si es así
        CALL    efect1		; lo llama y lo ejecuta
        MOVF    llaves,0	; sino, carga llaves en w
        XORLW   0x02		; y verifica si es el segundo efecto
        BTFSC   estado,2	; si es así
        CALL    efect2		; lo llama y lo ejecuta
        MOVF    llaves,0	; y así con los demás
        XORLW   0x04		; ya me aburrí
        BTFSC   estado,2	; como verás el resto es lo mismo
        CALL    efect3
        MOVF    llaves,0
		XORLW	0x08
		BTFSC	estado,2
		CALL	efect4
		MOVF	llaves,0
		GOTO    swich		; Comienza a revisar de nuevo


	banksel ANSEL
	clrf ANSEL

	banksel OSCCON

	bsf OSCCON, IRCF2 ; 110 is 4 MHz
	bsf OSCCON, IRCF1
	bcf OSCCON, IRCF0
;
; ============ the 16F88 has a clock fail safe system that's not used here =
	bcf OSCCON,SCS0 ; 00 is Oscillator mode defined by FOSC <2:0>
	bcf OSCCON,SCS1 ;
	nop ; allow some time for oscillator to settle
	nop
; =========================== OSCCAL ================================
; many of the PIC chips come with an oscillator calibration value that's
; specific for each chip and by reading that value and storing it into
; the OSCCAL register the internal clock is more accurate than not using
; it. But the 16F88 does not use that method and instead had OSCTUNE to
; tweak the internal oscillator frequency. For most apps you can just
; forget about this. It's here leftover from another project.
;====================================================================
	banksel OSCTUNE
	bsf OSCTUNE,TUN5
	bcf OSCTUNE,TUN4
	bsf OSCTUNE,TUN3
	bsf OSCTUNE,TUN2
	banksel PORTA


;======================== Efectos =========================

efect1	MOVLW b'10000000'
		MOVWF PORTB
		CALL clokon
		MOVLW b'11000000'
		MOVWF PORTB
		CALL clokon
		MOVLW b'11100000'
		MOVWF PORTB
		CALL clokon
		MOVLW b'11110000'
		MOVWF PORTB	
		CALL clokon
		MOVLW b'11111000'
		MOVWF PORTB
		CALL clokon
		MOVLW b'11111100'
		MOVWF PORTB	
	    CALL clokon
		MOVLW b'11111110'
		MOVWF PORTB
		CALL clokon
		MOVLW b'11111111'
		MOVWF PORTB	
		CALL clokon
		MOVLW b'01111111'
		MOVWF PORTB
		CALL clokon
		MOVLW b'00111111'
		MOVWF PORTB
		CALL clokon
		MOVLW b'00011111'
		MOVWF PORTB
		CALL clokon
		MOVLW b'00001111'
		MOVWF PORTB	
		CALL clokon
		MOVLW b'00000111'
		MOVWF PORTB
		CALL clokon
		MOVLW b'00000011'
		MOVWF PORTB	
	    CALL clokon
		MOVLW b'00000001'
		MOVWF PORTB
		CALL clokon
		MOVLW b'00000000'
		MOVWF PORTB	
		CALL clokon
        return

efect2  CLRF    portb		
        BSF     portb,0		; (00000001)
        CALL    clokon
        BSF     portb,1		; (00000011)
        CALL    clokon
        BSF     portb,2		; (00000111)
        CALL    clokon
        BSF     portb,3		; (00001111)
        CALL    clokon
        BSF     portb,4		; (00011111)
        CALL    clokon
        BSF     portb,5		; (00111111)
        CALL    clokon
        BSF     portb,6		; (01111111)
        CALL    clokon
        BSF     portb,7		; (11111111)
        CALL    clokon
        BCF     portb,0		; (11111110)
        CALL    clokon
        BCF     portb,1		; (11111100)
        CALL    clokon
        BCF     portb,2		; (11111000)
        CALL    clokon
        BCF     portb,3		; (11110000)
        CALL    clokon
        BCF     portb,4		; (11100000)
        CALL    clokon
        BCF     portb,5		; (11000000)
        CALL    clokon
        BCF     portb,6		; (10000000)
        CALL    clokon
        RETURN			    ; a revisar nuevamente las llaves

efect3  CLRF    portb		; limpia el puerto B
        BSF     portb,7		; (10000000)
		BSF     portb,0		; (10000001)
        CALL    clokon
        BSF     portb,6		; (11000001)
        BSF     portb,1		; (11000011)
        CALL    clokon
        BSF     portb,5		; (11100011)
        BSF     portb,2		; (11100111)
        CALL    clokon
        BSF     portb,4		; (11110111)
        BSF     portb,3		; (11111111)
        CALL    clokon
        BCF     portb,7		; (01111111)
        BCF     portb,0		; (01111110)
        CALL    clokon
        BCF     portb,6		; (00111110)
        BCF     portb,1		; (00111100)
        CALL    clokon
        BCF     portb,5		; (00011100)
        BCF     portb,2		; (00011000)
        CALL    clokon
        BCF     portb,4		; (00001000)
        BCF     portb,3		; (00000000)
        CALL    clokon
        CALL    clokon
        BSF     portb,3		; (00001000)
        BSF     portb,4		; (00011000)
        CALL    clokon
        BSF     portb,5		; (00111000)
        BSF     portb,2		; (00111100)
        CALL    clokon
        BSF     portb,6		; (01111100)
        BSF     portb,1		; (01111110)
        CALL    clokon
        BSF     portb,7		; (11111110)
        BSF     portb,0		; (11111111)
        CALL    clokon
 		BCF     portb,3		; (11110111)
        BCF     portb,4		; (11100111)
        CALL    clokon
        BCF     portb,5		; (11000111)
        BCF     portb,2		; (11000011)
        CALL    clokon
        BCF     portb,6		; (10000011)
        BCF     portb,1		; (10000001)
        CALL    clokon
        BCF     portb,7		; (00000001)
        BCF     portb,0		; (00000000)
        CALL    clokon
        RETURN
 
efect4	MOVLW b'11000000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'01100000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00110000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00011000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00001100'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00000110'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00000011'
		MOVWF PORTB
		CALL DELAY
		
		MOVLW b'00000110'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00001100'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00011000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00110000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'01100000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'11000000'
		MOVWF PORTB
		CALL DELAY
				
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
        MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA

		MOVLW b'11000000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'01100000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00110000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00011000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00001100'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00000110'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00000011'
		MOVWF PORTB
		CALL DELAY
		
		MOVLW b'00000110'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00001100'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00011000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00110000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'01100000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'11000000'
		MOVWF PORTB
		CALL DELAY
				
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
        MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
		MOVWF PORTB
		CALL  clokon
		MOVLW B'11111111'
		MOVWF PORTB
		CALL  clokon

		MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA ;retardo de 500mS
        CLRF  PORTB
        CALL  DEMORA
	   	MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA		
   
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		
		MOVLW B'00001111'				;nuevo comienzo
        MOVWF PORTB
        CALL  DEMORA ;retardo de 500mS
        CLRF  PORTB
        CALL  DEMORA
	   	MOVLW B'00001111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		MOVLW B'00001111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		   
		MOVLW B'11110000'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11110000'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11110000'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA

		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
       
		MOVLW B'00001111'
        MOVWF PORTB
        CALL  DEMORA ;retardo de 500mS
        CLRF  PORTB
        CALL  DEMORA
	   	MOVLW B'00001111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		MOVLW B'00001111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		   
		MOVLW B'11110000'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11110000'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11110000'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA

		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		
		MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA ;retardo de 500mS
        CLRF  PORTB
        CALL  DEMORA
	   	MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA		
   
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
	
		MOVLW b'11000000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'01100000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00110000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00011000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00001100'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00000110'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00000011'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00000001'
		MOVWF PORTB	
		CALL DELAY
		
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
        MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
        
		MOVLW b'11000000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'01100000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00110000'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00011000'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00001100'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00000110'
		MOVWF PORTB	
		CALL DELAY
		MOVLW b'00000011'
		MOVWF PORTB
		CALL DELAY
		MOVLW b'00000001'
		MOVWF PORTB	
		CALL DELAY
		
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
        MOVLW B'11111111'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA

		MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA ;retardo de 500mS
        CLRF  PORTB
        CALL  DEMORA
	   	MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA
		MOVLW B'11000011'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
		CALL  DEMORA		
   
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA
		MOVLW B'00111100'
        MOVWF PORTB
        CALL  DEMORA
        CLRF  PORTB
        CALL  DEMORA

        RETURN


	
;**********RUTINA DE RETARDO***********

clokon			MOVLW H'2'
				MOVWF RET
LOOP2			MOVLW H'90'
				MOVWF RET1
LOOP1			MOVLW H'90'
				MOVWF RET2
LOOP			DECFSZ RET2,F
				GOTO LOOP
				DECFSZ RET1,F
				GOTO LOOP1
				DECFSZ RET,F
				GOTO LOOP2
				RETURN

DEMORA      movlw     .100     
            movwf     PDel0    
PLoop1      movlw     .100      
            movwf     PDel1    
PLoop2      clrwdt              
PDelL1      goto      PDelL2         
PDelL2      goto      PDelL3         
PDelL3      clrwdt              
            decfsz    PDel1,  1
            goto      PLoop2   
            decfsz    PDel0,  1 
            goto      PLoop1    
PDelL4      goto      PDelL5         
PDelL5      goto 	  PDelL6         
PDelL6      goto      PDelL7         
PDelL7      clrwdt              
            return    


DELAY		MOVLW h'2'
			MOVWF RET
LOOP21		MOVLW h'75'
			MOVWF RET1
LOOP12		MOVLW h'86'
			MOVWF RET2
BLOOP		DECFSZ RET2,f
			GOTO BLOOP
			DECFSZ RET1,f
			GOTO LOOP12
			DECFSZ RET,f
			GOTO LOOP21
			return
		END


