	;Expt9.asm
        ;Project: Pulse Detection with a coil
	;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
	MOVWF 05	;Make RA1 input
	BCF 03,5	;Go to Bank 0 - the program memory area.	
	CLRF 1F		;Clear the button-press file
	CLRF 06		;Clear display
	GOTO Main

Table	ADDWF 02h,1	;Add W to the Program Counter to create a jump.
	RETLW 3Fh	;0    format= gfedcba
	RETLW 06h	;1    If any table value has a leading letter, it must be
	RETLW 5Bh	;2    preceded with a "0."   E.g: 0A3h, 0FFh, 0CCh
	RETLW 4Fh	;3
	RETLW 66h	;4
	RETLW 6Dh	;5
	RETLW 7Dh	;6
	RETLW 07h	;7
	RETLW 7Fh	;8
	RETLW 6Fh	;9	

Delay	NOP		;Create 1mS delay
	DECFSZ 1A,1
	GOTO Delay
	RETURN

Main	CLRF 1E		;Holds the count-value
Main1	BTFSS 05,1	;Test the input line on port A
	GOTO Main2	;LOW detected
	BTFSC 1F,0	;HIGH detected. First pass of routine?
	GOTO Main1	;HIGH already detected
	INCF 1E,1	;First time detected. Increment count.
	MOVLW 0A	;Has count reached ten?
	XORWF 1E,0	;Compare file 1E with ten
	BTFSC 03,2	;Check the zero flag in Status file
	GOTO Main	;Count has reached ten
	MOVF 1E,0	;Copy count into W
	CALL Table	;W will return with display-value
	MOVWF 06	;Output display value
	CALL Delay	;Debounce the coil
	BSF 1F,0	;Set detection flag
	GOTO Main1	;Loop Main1
Main2	BCF 1F,0	;Clear detection flag
	GOTO Main1	;Loop Main1

	END		;Tells assembler end of program


