  	       ;Experiment-11 for "5x7 Video Screen" Project      
  	        ;PIC16F84 and only F84 chip         
      		    ;  ELEVATOR DISPLAY
	
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 00h
	RETLW 0Eh	;9
	RETLW 11h
	RETLW 11h
	RETLW 0Fh
	RETLW 01h
	RETLW 11h
	RETLW 0Eh
	RETLW 00h	;8
	RETLW 0Eh
	RETLW 11h
	RETLW 11h
	RETLW 0Eh
	RETLW 11h
	RETLW 11h
	RETLW 0Eh	
	RETLW 00h
	RETLW 1Fh	;7
	RETLW 01h
	RETLW 02h
	RETLW 04h
	RETLW 08h
	RETLW 08h
	RETLW 08h
	RETLW 00h	;6
	RETLW 0Eh
	RETLW 11h
	RETLW 10h
	RETLW 1Eh
	RETLW 11h
	RETLW 11h
	RETLW 0Eh
	RETLW 00h	;5
	RETLW 1Fh	
	RETLW 10h
	RETLW 10h
	RETLW 1Eh
	RETLW 01h
	RETLW 11h
	RETLW 0Eh
	RETLW 00h	;4
	RETLW 02h
	RETLW 06h
	RETLW 0Ah
	RETLW 12h
	RETLW 1Fh
	RETLW 02h
	RETLW 02h
	RETLW 00h	;3
	RETLW 0Eh
	RETLW 11h
	RETLW 01h
	RETLW 06h
	RETLW 01h
	RETLW 11h
	RETLW 0Eh
	RETLW 00h	;2
	RETLW 0Eh
	RETLW 11h
	RETLW 01h
	RETLW 0Eh
	RETLW 10h
	RETLW 10h
	RETLW 1Fh
	RETLW 00h	;1
	RETLW 04h
	RETLW 0Ch
	RETLW 14h
	RETLW 04h
	RETLW 04h
	RETLW 04h
	RETLW 04h
	RETLW 00h	;G
	RETLW 0Eh
	RETLW 11h
	RETLW 10h
	RETLW 17h
	RETLW 11h
	RETLW 11h
	RETLW 0Eh
	RETLW 00h
	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
	


     ;FillTop moves the 5 Ghost locations down one bit
	; and fills the top row with new data.
	;File 16h contains the new data for the 5 locations

FillTop	RRF 11h,1	;Move each bit down the file
	RRF 12h,1	; to make room at the top
	RRF 13h,1	
	RRF 14h,1
	RRf 15h,1
	BCF 11h,6	;Clear bit 6 in each file = 7th row of LEDs
	BCF 12h,6	;   on the Video Screen.
	BCF 13h,6
	BCF 14h,6
	BCF 15h,6
	BTFSS 16h,4	;See if bit4 (the 5th bit) is 0 or 1
	GOTO L		;If it's 0, go to the next test
	BSF 11h,6	;If it's 1, set bit 6 of the Ghost file
L	BTFSS 16h,3
	GOTO M
	BSF 12h,6
M	BTFSS 16h,2	;File 16h was generated by adding thr value of
	GOTO N		;   of each pixel in the row of each number 
	BSF 13h,6	;   see Table1 and diagram 1 for details.
N	BTFSS 16h,1
	GOTO O
	BSF 14h,6
O	BTFSS 16h,0
	RETURN
	BSF 15h,6
	RETURN

FilBott	RLF 11h,1	;Same principle as above, but this time
	RLF 12h,1	;  the bits in the file are moved up to
	RLF 13h,1	;  leave a gap at the bottom. 
	RLF 14h,1
	RLF 15h,1
	BCF 11h,0	;Clear the lowest bit og each Ghost file
	BCF 12h,0
	BCF 13h,0
	BCF 14h,0
	BCF 15h,0
	BTFSS 16h,4
	GOTO P
	BSF 11h,0
P	BTFSS 16h,3
	GOTO Q
	BSF 12h,0
Q	BTFSS 16h,2
	GOTO R
	BSF 13h,0
R	BTFSS 16h,1
	GOTO S
	BSF 14h,0
S	BTFSS 16h,0
	RETURN
	BSF 15h,0
	RETURN



          ;FilGho fills the Ghost area with 7 rows of "G" data
		;from Table1

	
FilGho	MOVLW 08
	MOVWF 1A	;1A is count file for 7 cycles of "FilGho"
	MOVLW 58h
	MOVWF 19h	;File19h is button B pointer for Table1
	MOVLW 50h	;Jump down table1 xxh locations
	MOVWF 17h	;file17h is button A pointer for Table1	
FilGho1	CALL Table1
	MOVWF 16h
	CALL FillTop
	DECF 17h,1	;File 17h is the table pointer for button A
	DECF 19h,1	;File 19h is the table pointer for button B
	MOVF 17h,0	;Put pointer into W
	DECFSZ 1A,1
	GOTO FilGho1
	RETURN 
	

	
	;MAIN ROUTINE

Main	CALL FilGho	;Put "G" on screen
	CALL Ghost	;Display whatever is in Ghost files
	BTFSS 05h,2	;Test for buttonA
	GOTO Main2		;Pushed
	GOTO Main  

Main2	MOVLW 08
	MOVWF 1A
Main3	MOVLW 20h
	MOVWF 18h	;File 18h holds number of scans before adding next row
Main4	CALL Ghost
	DECFSZ 18h,1
	GOTO Main4
	MOVF 17h,0	;Put table1 pointer into W
	CALL Table1
	MOVWF 16h
	CALL FillTop
	DECF 17h,1
	DECF 19h,1	;19h is pointer for buttonB
	DECFSZ 1A,1
	GOTO Main3	
Main5	CALL Ghost	;Display whatever is in Ghost files
	BTFSS 05h,2	;Test for button A
	GOTO MainA	;Button A Pushed
	BTFSS 05h,3	;Test for Button B
	GOTO MainB	;Button B pushed
	GOTO Main5

MainA	MOVF 17h,0	;Copy 17h into W
	XORLW 00h
	BTFSC 03,2	;Button A not to work. On floor 9!
	GOTO Main5
	GOTO Main2
MainB	MOVF 19h,0	;Copy 19h into W
	XORLW 50h
	BTFSC 03,2	;Button B not to work. On G floor!
	GOTO Main5	
Main6	MOVLW 08
	MOVWF 1Ah
Main7	MOVLW 20h
	MOVWF 18h	;File 18h holds the number of scans before adding next row
Main8	CALL Ghost
	DECFSZ 18h,1
	GOTO Main8
	MOVF 19h,0	;Put table1 pointer into W
	CALL Table1
	MOVWF 16h
	CALL FilBott
	INCF 17h,1
	INCF 19h,1	;19h is pointer for button B
	DECFSZ 1A,1
	GOTO Main7
	GOTO Main5

        END







 