  	       ;Experiment-11 for "5x7 Video Screen" Project      
  	        ;PIC16F84 and only F84 chip         
      		    ;  0-9 Up Counter
	
Start   ORG 0x00
        BSF 03,5        ;Go to page1 for setting-up the ports	 
	MOVLW 0Ch       ;Put 0C into W     
	MOVWF 05h       ;  to make RA2 & RA3 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




Table1	ADDWF 02h,1	;Add W to Program Counter
	RETLW 3Eh	;0
	RETLW 41h	
	RETLW 41h
	RETLW 41h
	RETLW 3Eh
	RETLW 00h	;1
	RETLW 10h
	RETLW 20h
	RETLW 7Fh	
	RETLW 00h
	RETLW 27h	;2
	RETLW 49h
	RETLW 49h
	RETLW 49h
	RETLW 31h
	RETLW 22h	;3
	RETLW 41h
	RETLW 49h	
	RETLW 49h
	RETLW 36h
	RETLW 0Ch	;4
	RETLW 14h
	RETLW 24h
	RETLW 7Fh
	RETLW 04h	
	RETLW 7Ah	;5
	RETLW 49h
	RETLW 49h
	RETLW 49h
	RETLW 46h
	RETLW 3Eh	;6
	RETLW 49h
	RETLW 49h	
	RETLW 49h	
	RETLW 26h
	RETLW 40h	;7
	RETLW 47h
	RETLW 48h
	RETLW 50h
	RETLW 60h
	RETLW 36h	;8
	RETLW 49h
	RETLW 49h
	RETLW 49h
	RETLW 36h
	RETLW 32h	;9
	RETLW 49h
	RETLW 49h
	RETLW 49h	
	RETLW 3Eh
	RETLW 00h
	

    ;Ghost routine transfers data from the 
    ;        Ghost files to the Video Screen
	;  and scans the Video Screen ONCE

Ghost	BSF 05,1	;Reset 4017
	NOP
	BCF 05,1

	MOVF 11h,0	;Move the data from the 
	MOVWF 06h	;    Ghost files to 
	CALL DelA	;     the output port
	MOVF 12h,0	; and call a Delay so the 
	MOVWF 06h	;   LED can be illuminated
	CALL DelA
	MOVF 13h,0
	MOVWF 06h
	CALL DelA
	MOVF 14h,0
	MOVWF 06h
	CALL DelA
	MOVF 15h,0
	MOVWF 06h
	CALL DelA
	RETURN

DelA	DECFSZ 1Bh,1
	GOTO DelA
	MOVLW 00h
	MOVWF 06
Clk	BCF 05,0	;Clock the 4017 to the
	NOP	 	;   next output
	BSF 05,0
	RETURN
	

      ;"FillGh" Fill moves 5 bytes of data from Table1 to
	; to Ghost area via Indirect Addressing
         
FillGh	MOVLW 05
	MOVWF 18h	;5 cycles of Loading
	MOVLW 11h
	MOVWF 04	;Move start of Ghost locations to FSR
FillGh2	MOVF 17h,0	;Move table pointer to W
	CALL Table1
	MOVWF 00	;Move W to INDF (move into what FSR looks at)
	INCF 04h,1	;Increment the FSR to look at next file
	INCF 17h,1
	DECFSZ 18h,1
	GOTO FillGh2
	RETURN

	
	;MAIN ROUTINE

Main	MOVLW 00
	MOVWF 17h	;Load Table1 pointer with 00	
	CALL FillGh	;Put "0" on Screen


Main1	BCF 1E,5
Main2	CALL Ghost	;Display whatever is in Ghost files
	BTFSS 05h,2	;Test for buttonA
	GOTO Main3		;Pushed
	GOTO Main1  

Main3	BTFSC 1E,5
	GOTO Main2
	MOVF 17h,0	;Has pointer reached end of table?
	XORLW 32h	;End of Table is 32h bytes.
	BTFSS 03,2	;Test the zero flag
	GOTO  xxx
	MOVLW 00
	MOVWF 17h
xxx	CALL FillGh	;No. Put next number on screen
	BSF 1E,5	;Set the button flag
	GOTO Main2


        END



