	;Expt11a.asm
        ;Project: Sound to Frequency
	;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 01,5	;Make sure timer is incremented via internal clock
	BCF 01,3	;Make sure Prescaler is assigned to TMR0
	BSF 01,0	;PS0   (OPTION) Timer0 rate 1:256  (256x256uS)
	BSF 01,1	;PS1        when PS0, PS1 and PS2 are SET
	BSF 01,2	;PS2
	BCF 03,5	;Go to Bank 0 - the program memory area.	
	BCF 0B,7	;Disable all interrupts	
	BCF 0B,5	;Disable the TMR0 Interrupt		
	CLRF 05		;Clear display
	CLRF 06		;Clear display
	GOTO Main

Delay	MOVLW 64h	;Load with 100. Create 100mS delay
	MOVWF 1B
DelayA	NOP		
	DECFSZ 1A,1
	GOTO DelayA
	DECFSZ 1B,1
	GOTO DelayA
	RETURN

Delay1	MOVLW 10	
	MOVWF 1A	
DelayB	DECFSZ 1A,1
	GOTO DelayB
	RETURN	

Display BSF 0B,2	;reset the "time-up" flag
	MOVF 0C,0	;Put count file into W
	MOVWF 06	;Display the count on 8 LEDs	
	CALL Delay 	
	GOTO Main

Main	CLRF 0Ch	;Holds the count
	BTFSS 05,1	;Test input line on port A
	GOTO Main	;LOW detected
	CLRF 01	 	;clear TMR0 register		
	BCF 0B,2	;Clear TMR0 overflow interrupt flag	
Main1	INCF 0C,1	;Increment the count
Main2	CALL Delay1	;Reduce the number of "looks" per sec
	BTFSC 05,1	;Test input line on port A
	GOTO Main2	;Input is still HIGH	
Main3	CALL Delay1	;Reduce the number of "looks" per sec
	BTFSS 05,1	;Test input line on port A
	GOTO Main3	;Still LOW	
	BTFSS 0B,2	;Check the "time-up" flag
	GOTO Main1	;HIGH detected	
	GOTO Display	

	END		;Tells assembler end of program


