;Remember that, for the microswitches (SW4..SW3), SW4 is the most significant bit
;and the ON position=0, the OFF position=1.
;develop a program in assembler for Bolt v.Lite system with the following requirements:
;reads microswitches SW3..SW1 and obtains a number n between 0..15 (decimal)
;lights led Bn, the rest remains off.
;if user modify value of microswitches, the program automatically modifies which of
;the leds is ON. 

	processor 18F2550
	include	  <p18F2550.inc>
	include	 "KEYBOLT2.inc"	;auxiliary file

J	equ	H'80'	  
K	equ	H'81'
L	equ 	H'82'
CLAVE100 equ H'83'
	 
		org 	0x800	;modify to org=0 to simulate in MPLAB
		PUERTOS
INICIO: BOLTSWITCH
		CLRF	PORTB
		BCF		CLAVE100,3			;CLEARS BIT SW4
		INCF	CLAVE100			;
		BSF		LED0				;LED0=ON
MALLA2:	DECFSZ	CLAVE100
		GOTO	UNO
		GOTO	DOS		
UNO:	RLNCF	PORTB
		GOTO	MALLA2
DOS:	CALL	retrobolt			;delay to watch the led ON
		GOTO	INICIO				;repites program
			
		


;DELAY SUBROUTINE APROX. 1 SECOND. MODIFY TO (16.4 x L) MILISECONDS

retrobolt:	movlw	D'61'	;valor de L. Modifique para cambiar el valor del retraso.
		movwf	L
lloop		movlw	D'255'	; w := 200 decimal
		movwf	J	; J := w
jloop:		movwf	K	; K := w
kloop:		decfsz	K,f	; K = K-1, skip next if zero
		goto 	kloop
		decfsz	J,f	; J = J-1, skip next if zero
		goto	jloop
		decfsz	L,f
		goto	lloop
		return


		end	

