          ;Experiment-6 for "5x7 Video Screen" Project      
             ;PIC16F84 and only F84 chip         
             ;REACTION GAME 

Start   ORG 0x00
        BSF 03,5        ;Go to page1 for setting-up the ports
	MOVLW 04h	;Load W with 04                   
        MOVWF 05h       ;Make  RA2 input 
	MOVLW 00h       ;Put 00 into W         
        MOVWF 06h       ;Make all RB lines output
        BCF 03,5        ;Go to Page0 for programming
        MOVLW 02h       ;Put 02 into W to
        MOVWF 05h       ;    Reset the 4017
	BCF 03h,0       ;clear the carry flag

 
Game    MOVLW 01h	;Turn on the bottom LED
        MOVWF 06h	;   and output a HIGH to LED
	CALL Delay
	CALL Delay	;	
Game1	BCF 1E,5	;Reset the flag bit for button A
Game2   RLF 06h,1	;Shift the HIGH up the column
        CALL Delay

	CALL Target

	CALL Delay
	BTFSS 06h,6	;Has it reached the top?
        GOTO Game2	;NO.
Game3	BCF 1E,5	;Reset the flag bit for button A
	RRF 06h,1	;Shift the HIGH down
	CALL Delay

	CALL Target

	CALL Delay
	BTFSS 06h,0	;Has it reached the bottom?
	GOTO Game3	;NO.	
	GOTO Game1	;YES. Repeat the cycle


Target	MOVLW 80h
	MOVWF 1Ch
Target1	DECFSZ 1B,1
	GOTO Target1	
	BTFSS 06h,3	;Is target LED lit?
	GOTO Target2	;NO.
	BTFSC 05h,2	;Is button A pressed?
	GOTO Target3	;YES.
Target2	DECFSZ 1Ch,1	;NO.
	GOTO Target1 	
	RETURN

Target3	BTFSC 1Eh,5	;Has button A been pushed incorrectly?
	GOTO Target2	;YES.
	GOTO Game

Delay   MOVLW 01h
        MOVWF 1Ah
Delay1  DECFSZ 1Bh,1
        GOTO Delay1
	BTFSC 05h,2	;Is buttonA pressed?
	BSF 1Eh,5	;Yes. Set flag for button A
        DECFSZ 1Ch,1
        GOTO Delay1	
	DECFSZ 1Ah,1
	GOTO Delay1	        
        RETURN


        END

 