          ;Experiment-10 for "5x7 Video Screen" Project      
          ;PIC16F84 and only F84 chip         
          ;  "Button A" starts/stops action. 

Start   ORG 0x00
        BSF 03,5        ;Go to page1 for setting-up the ports	 
	MOVLW 04h       ;Put 04 into W     
	MOVWF 05h       ;  to make RA2 input 
	MOVLW 00h	;Put 00 into W   
        MOVWF 06h       ;to make all RB lines output
        BCF 03,5        ;Go to Page0 for programming
	GOTO Main

Back	BSF 05h,1
	BCF 05h,1	;Reset 4017 and allow 4017 to clock		
	MOVLW 00h
	MOVWF 06h	;Turn off LEDs to prevent "streaking"
	MOVF 19h,0	;Copy 19h into W
	MOVWF 18h	;Copy W into file 18h
Back1	CALL Clock
	DECFSZ 18h,1
	GOTO Back1
	MOVLW 7Fh
	MOVWF 06h	;Turn on all 7 LEDs
	CALL Delay
	RETURN

ButtonA	BTFSC 05,2
	RETURN		;Button A NOT pushed
	GOTO ButtonA
	

Clock	BCF 05,0	;Clock the 4017
	NOP
	BSF 05,0
	RETURN
	
Delay   MOVLW 03
        MOVWF 1Ah
Delay1  DECFSZ 1Bh,1
        GOTO Delay1
        DECFSZ 1Ch,1
        GOTO Delay1
	CALL ButtonA
        DECFSZ 1Ah,1
        GOTO Delay1
        RETURN

Scan	MOVLW 080h	;Determines the number of scans before 
	MOVWF 1Ch	; incrementing routine 
Scan1	BSF 05h,1        ;Reset 4017
        BCF 05h,1        ;allow 4017 to clock via clock line
	MOVLW 05h
	MOVWF 19h	;File 19h counts the number of columns
	
Scan2	CALL Short
	BCF 05,0	;Clock the 4017
	BSF 05,0
	DECFSZ 19h,1
	GOTO Scan2
	CALL ButtonA
	DECFSZ 1Ch,1
	GOTO Scan1
	RETURN

	;Short Delay

Short	DECFSZ 1Bh,1
	GOTO Short
	RETURN


	;Moves a colum of LEDs across the screen and back, 
	;then up and down the screen

Main   MOVLW 05
	MOVWF 19h	 ;Put 5 in the Count file for 5 columns
	BSF 05h,1        ;Reset 4017
        BCF 05h,1        ;allow 4017 to clock via clock line
	
Main1	MOVLW 7F
	MOVWF 06h	 ;Turn on 7 outputs for LEDs
	CALL Delay
	MOVLW 00	 ;Turn off LEDs to prevent mirroring
	MOVWF 06h
	CALL Clock	 ;Clock the 4017
	DECFSZ 19h,1	 ;Decrement the count file
	GOTO Main1

	MOVLW 03h
	MOVWF 19h	 ;3 shifts  - yes 3 shifts!
Main2	CALL Back
	DECFSZ 19h,1
	GOTO Main2
	BSF 05h,1
	BCF 05h,1	;Reset 4017
	CALL Delay	;This illuminates the first row!


	MOVLW 01
	MOVWF 06h	;Turn on first LED
	BCF 03h,0       ;clear the carry flag
Main3	CALL Scan
	RLF 06,1
	BTFSS 06,7	;When 8th! output is HIGH, program repeats	
	GOTO Main3

	MOVLW 20h
	MOVWF 06h
Main4	CALL Scan
	RRF 06,1
	BTFSS 06,0
	GOTO Main4
	CALL Scan	;This illuminates bottom row!
	GOTO Main	

        END







 
