; PROGRAM PING-PONG FOR BOLT 18F2550
; IF SW1=ON (0) SHIFTS LEDS OF PORT B 8 TIMES TO THE RIGHT
; IF SW1=OFF(1) SHIFTS LEDS OF PORT B 8 TIMES TO THE LEFT
; TO SIMULATE IN MPLAB:
; ORG=0, AND WRITE A ";" BEFORE INSTRUCTION "CALL retrobolt".
; TO AVOID WASTING TIME SIMULATING DELAY SUBRUTINE
; TO EXECUTE PROGRAM IN BOLT 18F2550, ORG=0X800

	processor 18F2550
	include	  <p18F2550.inc>
	include	 "KEYBOLT2.inc"				;AUXILIAR FILE

J	equ	H'80'	  
K	equ	H'81'
L	equ 	H'82'
	 
			org 	0x800			;MODIFY TO 0X000 TO SIMULATE IN MPLAB
			PUERTOS				;MACRO INITIALIZE PORTS
INICIO 			bsf 	LED0
INIC1   		bcf 	STATUS,C
	   		btfsc 	SW1			;TEST RA4
	   		goto 	TRES 
DOS			btfss 	LED7
    			goto 	TRES   			   		 	
DERECHA 		rrcf 	PORTB			;SHIFT LEDS TO RIGHT
			call 	retrobolt 	
			btfss 	LED0
			goto 	DERECHA
			goto 	INIC1	
TRES 			btfss 	SW1			;TEST RA4
			goto 	INIC1
CINCO 			btfss 	LED0
			goto 	INIC1
IZQUIERDA 		rlcf 	PORTB 			;SHIFT LEDS TO LEFT
			call 	retrobolt	
		  	btfss 	LED7
	   		goto 	IZQUIERDA
			goto 	INIC1   	

;DELAY SUBROUTINE APROX 100 MILISECONDS. MODIFY TO (16.4 x L) MILISECONDS

retrobolt:		movlw	D'6'	;L VALUE. MODIFY TO CHANGE DELAY
			movwf	L
lloop			movlw	D'255'	; w := 255 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	

