	;Expt1c.asm
        ;Project: Two pushes to turn on a LED
	;List P = 16F84
	;#include <p16F84.inc>
	;__CONFIG 1Bh    ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC


	ORG 0		;This is the start of memory for the program.
SetUp	BSF 03,5	;Go to Bank 1
	CLRF 06		;Make all port B output
	MOVLW 01	;Load W with 0000 0001
	MOVWF 05	;Make RA0 input
	BCF 03,5	;Go to Bank 0 - the program memory area.
	CLRF 1F		;Clear the button file
	CLRF 06		;Blank the output
	GOTO Main
		
Delay	NOP		;Create approx 250mS delay
	DECFSZ 1A,1
	GOTO Delay
	DECFSZ 1B,1
	GOTO Delay
	RETURN	

Delay2	NOP		;Create 1mS debounce delay	
	DECFSZ 1A,1
	GOTO Delay2
	RETURN

Sw	BTFSS 05,0	;Test the push button
	GOTO Sw3	;Button not pressed	
	BTFSC 1F,2	;Test end-of-flash flag
	RETURN
	BTFSC 1F,0	;First pass?
	RETLW 00	;No
	BTFSS 1F,1	;Test first-press flag
	GOTO Sw2	;First press
	BSF 06,0	;Button has been pressed twice. Illuminate LED
	CALL Delay	;Keep LED on
	CALL Delay	;Keep LED on
	BCF 1F,1	;Clear second-push flag bit
	BSF 1F,2	;Set end-of-flash flag
	BCF 06,0	;Turn LED off
	RETURN
Sw2	BSF 1F,1	;Set the first-press flag
	BSF 1F,0	;Set button pass flag bit
	RETURN	
Sw3	BCF 1F,0	;Clear button pass flag bit
	BCF 1F,2	;Clear end-of-flash flag
	RETURN

Main	CALL Sw
	CALL Delay2	;Debounce switch	
	GOTO Main

	END		;Tells assembler end of program