	;Expt11b.asm
        ;Project: Whistle-On  Whistle-Off
	;List P = 16F84
	;#include <p16F84.inc>
	;__CONFIG 1Bh    ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC


	ORG 00		;Start of memory for 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 flag file
	CLRF 05		;Clear the display
	CLRF 06		;Clear the display
	GOTO Main

Delay	NOP		; Create 1mS delay
	DECFSZ 1A,1
	GOTO Delay
	RETURN

Delay1	MOVLW 40h
	MOVWF 1B
DelayA	DECFSZ 1A,1
	GOTO DelayA
	DECFSZ 1B,1
	GOTO DelayA
	RETURN

Look	BCF 1F,0	;Clear the "whistle" flag
	MOVLW 040h	;Number of loops
	MOVWF 0E	;Loops file
	CLRF 0Ch	;Holds the LOW count	
Look1	CALL Delay
	BTFSC 05,1	
	GOTO look2
	INCF 0Ch,1	;LOW detected
Look2	DECFSZ 0E,1
	GOTO Look1
	MOVLW 18h
	SUBWF 0Ch,0
	BTFSS 03,0	;Test Carry flag. If set C=more than 10h	
	RETURN
	BSF 1F,0	;Whistle detected
	RETURN	

Main	CALL Look
	BTFSS 1F,0
	GOTO Main	;No whistle
	MOVLW 04	;Whistle - turn on display
	MOVWF 05
Main1	CALL Delay1	
	CALL Look	
	BTFSC 1F,0
	GOTO Main1	;whistle
Main2	CALL Delay1
	CALL Look
	BTFSS 1F,0
	GOTO Main2	;No whistle
	MOVLW 00	;Whistle - turn off display
	MOVWF 05
Main3	CALL Delay1	
	CALL Look	
	BTFSC 1F,0
	GOTO Main3	;whistle	
	GOTO Main	;no whistle

	END		;Tells assembler end of program









