	;Expt11.asm
        ;Project: Sound Detection
	;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 02	;Load W with 0000 0010
	MOVWF 05	;Make RA1 input
	BCF 03,5	;Go to Bank 0 - the program memory area.	
	CLRF 1F		;Clear detection flag	
	CLRF 05		;Clear display
	CLRF 06		;Clear display
	GOTO Main

Delay	NOP		;Create 1mS delay
	DECFSZ 1A,1
	GOTO Delay
	RETURN

Main	BTFSS 05,1	;Test the input line on port A
	GOTO Main1	;LOW detected
	BTFSC 1F,0	;HIGH detected. First pass of routine?
	GOTO Main	;HIGH already detected
	BSF 06,0	;Turn on LED
	CALL Delay
	BCF 06,0	;Turn off LED
	BSF 1F,0	;Set the detection flag
	GOTO Main
Main1	BCF 1F,0	;Clear the detection flag
	GOTO Main

	END		;Tells assembler end of program



