          ;Experiment-5B for "5x7 Video Screen" Project      
             ;PIC16F84 and only F84 chip         
             ;Toggling a LED (with de-bounce) 

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 for button A    
	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
	MOVLW 00
	MOVWF 06h	;Zero the output port
	GOTO Main

Switch	BTFSS 05,2	;Is switch A pushed?
	GOTO Switch2	;YES.
	MOVF 1Dh,0	;NO. Copy 1Dh into W
	XORLW 00	;XOR W with 00
	BTFSS 03,2	;Is file 1Dh=0?
	GOTO Switch1	;NO.
	RETURN		;YES.
Switch1	DECF 1Dh,1	;Decrement the debounce file	
	RETURN
Switch2	MOVF 1Dh,0	;1Dh is the debounce file
	XORLW 00	;
	BTFSS 03,2	;Is file 1Dh=0?
	RETURN		;NO.
	MOVLW 01	;YES. LED is on line0 of port6
	XORWF 06,1	;Toggle the LED	
	MOVLW 80h	;Load W with 80h loops
	MOVWF 1Dh	;Put 80h into debounce file
	RETURN

Main	NOP
	CALL Switch
	NOP
	NOP
	GOTO Main

        END

 
