	;Expt1b.asm
        ;Project: LED on for 0.5 sec with debounce
	;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-press 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	

Main	BTFSS 05,0	;Test the input line on port A
	GOTO Main2	;Button not pressed
	BTFSC 1F,0	;Button pressed first time?
	GOTO Main	;Button already pressed
Main1	NOP
	NOP
	NOP
	NOP
	DECFSZ 1A,1	;First time button pressed. 
	GOTO Main1	;Create short delay and look again
	BTFSS 05,0	;Is switch still pressed?
	GOTO Main2	;It was only noise
	BSF 06,0	;Turn on LED
	CALL Delay	;Illuminate for 250mS
	CALL Delay	;Illuminate for 250mS
	BCF 06,0	;Turn off LED
	BSF 1F,0	;Set button-press flag
	GOTO Main	;Loop Main
Main2	BCF 1F,0	;Clear button-press flag
	GOTO Main	;Loop Main


	END		;Tells assembler end of program