list p=16f84a
#include<p16f84a.INC>
R_ContA    EQU 0E
R_ContB    EQU 10
cont       EQU 20
cont1      EQU 30

           org 0
           goto INICIO
           org 4
           GOTO INT
           org 5
        
INICIO     BSF STATUS,5 
           MOVLW  0XFF
           MOVWF  PORTB
           CLRF   PORTA
           BSF    OPTION_REG,6
           BCF STATUS,5
           MOVLW  90
           MOVWF  INTCON
           
NADA       SLEEP
           GOTO NADA
           
           clrf cont1
           bsf  cont1,0
           
INT  
           
           btfsc  portb,1                    
           goto   uno
           goto   SEGUIR
           
uno        btfsc  cont1,0
           goto   on_led
           MOVF	cont,W
	       XORLW	B'1011'		
       	   BTFSC	STATUS,Z		
	       GOTO	reini		
	       INCF	cont,F		
	       MOVF	cont,W		
       	   GOTO	tabla                     
           
on_led    clrf    cont1
                  
reini	CLRF	cont		
     	MOVF	cont,W		
	    GOTO	tabla		


Pulsadores   BTFSS PORTB,1
	         return
             BCF INTCON,INTF
             RETFIE
  		


tabla	ADDWF	PCL,F

GOTO VEL_0
GOTO VEL_10
GOTO VEL_20
GOTO VEL_30
GOTO VEL_40
GOTO VEL_50
GOTO VEL_60
GOTO VEL_70
GOTO VEL_90
GOTO VEL_100
		

;voy a utilizar una frecuencia de 100 Hz la cual tiene una duracion de 10ms
VEL_100   ;10 ms en ON y 0 ms en OFF
       bsf    PORTA,1
       call   Retardo_10ms
       call   Pulsadores
       goto   VEL_100

VEL_90   ;9 ms en ON y 1 ms en OFF
       bsf    PORTA,1
       call   Retardo_9ms
       bcf    PORTA,1
       call   Retardo_1ms
       call   Pulsadores
      
       goto   VEL_90

VEL_80   ;8 ms en ON y 2 ms en OFF
       bsf    PORTA,1
       call   Retardo_8ms
       bcf    PORTA,1
       call   Retardo_2ms
       call   Pulsadores
       goto   VEL_80

VEL_70   ;7 ms en ON y 3 ms en OFF
       bsf    PORTA,1
       call   Retardo_7ms
       bcf    PORTA,1
       call   Retardo_3ms
       call   Pulsadores
       goto   VEL_70

VEL_60   ;6 ms en ON y 4 ms en OFF
       bsf    PORTA,1
       call   Retardo_6ms
       bcf    PORTA,1
       call   Retardo_4ms
       call   Pulsadores
       
       goto   VEL_60

VEL_50   ;5 ms en ON y 5 ms en OFF
       bsf    PORTA,1
       call   Retardo_5ms
       bcf    PORTA,1
       call   Retardo_5ms
       call   Pulsadores
       
       goto   VEL_50

VEL_40   ;4 ms en ON y 6 ms en OFF
       bsf    PORTA,1
       call   Retardo_4ms
       bcf    PORTA,1
       call   Retardo_6ms
       call   Pulsadores
       
       goto   VEL_40

VEL_30   ;3 ms en ON y 7 ms en OFF
       bsf    PORTA,1
       call   Retardo_3ms
       bcf    PORTA,1
       call   Retardo_7ms
       call   Pulsadores
       
       goto   VEL_30

VEL_20   ;2 ms en ON y 8 ms en OFF
       bsf    PORTA,1
       call   Retardo_2ms
       bcf    PORTA,1
       call   Retardo_8ms
       call   Pulsadores
      
       goto   VEL_20

VEL_10  ;1 ms en ON y 9 ms en OFF
       bsf    PORTA,1
       call   Retardo_1ms
       bcf    PORTA,1
       call   Retardo_9ms
       call   Pulsadores
       
       goto   VEL_10

VEL_0   ;10 ms en OFF
        bcf    PORTA,1
        call   Retardo_10ms
        call   Pulsadores
         
        goto   VEL_0

; RETARDOS de 1 ms hasta 10 ms.  

Retardo_10ms				 
	movlw	0a			 
	goto	Retardos_ms		 
Retardo_9ms				 
	movlw	09			 
	goto	Retardos_ms		 
Retardo_8ms				 
	movlw	08			 
	goto	Retardos_ms	 
Retardo_7ms				 
	movlw	07			 
	goto	Retardos_ms		 
Retardo_6ms				 
	movlw	06			 
	goto	Retardos_ms		 
Retardo_5ms				 
	movlw	05			 
	goto	Retardos_ms	 
Retardo_4ms				 
	movlw	04			 
	goto	Retardos_ms		 
Retardo_3ms				 
	movlw	03			 
	goto	Retardos_ms		 
Retardo_2ms				 
	movlw	02			 
	goto	Retardos_ms		 
Retardo_1ms				 
	movlw	01 
 
Retardos_ms
	movwf	R_ContB			 
R1ms_BucleExterno
	movlw	0xf9			  
	movwf	R_ContA			 
R1ms_BucleInterno
	clrwdt				 
	decfsz	R_ContA,F		  
	goto	R1ms_BucleInterno		 
	decfsz	R_ContB,F		 
	goto	R1ms_BucleExterno 	 
	return	

SEGUIR                  
           BCF INTCON,INTF
           RETFIE

           
           END           