	;Test1.asm
        ;Project: Test Routine
	;List P = 16F84
	;#include <p16F84.inc>
	__CONFIG 1Fh	;_CP_OFF & _PWRTE_ON & _WDT_ON & _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 1F	;Load W with 0001 1111
	MOVWF 05	;All Port A input
	BCF 03,5	;Go to Bank 0 - the program memory area.
	BCF 03,0	;Clear the carry flag
	CLRF 1F		;Clear the flag file
	GOTO Sect1a	
	
Delay	NOP		;Create 250mS delay
	DECFSZ 1A,1
	GOTO Delay
	BTFSC 05,0	;Look at input
	GOTO Sect2a	;Go to next section 
	DECFSZ 1B,1
	GOTO Delay
	RETURN		;Return

Sect1a	MOVLW 01	;Put 0000 0001 into W
	MOVWF 06	;Illuminate the lowest LED
Sect1b	RLF 06,1	;Shift to the left so that end LED shows equal time
Sect1c	RLF 06,1	;Shift LED to the left.
	BTFSC 03,0	;Has LED reached end of display?
	GOTO Sect1d	;Yes
	CALL Delay	;No. Illuminate LED
	GOTO Sect1c	;Loop shift-left instructions.
Sect1d	RRF 06,1	;Shift to the right so that end LED shows equal time
Sect1e	RRF 06,1	;Shift LED to the right.
	BTFSC 03,0	;Has LED reached end of display?
	GOTO Sect1b	;Yes. 
	CALL Delay	;No. Illuminate LED
	GOTO Sect1e	;Loop shift-right instructions.

Delay2	NOP		;Create 250mS delay
	DECFSZ 1A,1
	GOTO Delay2		
	DECFSZ 1B,1
	GOTO Delay2
	RETURN		;Return

Sect2a	MOVLW 02	;2 loops of "Pb"
	MOVWF 1Eh	;The 2-loop file
Sect2b	MOVLW 73h	
	MOVWF 06	;Output "P"
	CALL Delay2
	CALL Delay2
	CLRF 06 
	CALL Delay2
	MOVLW 7Ch	
	MOVWF 06	;Output "b"
	CALL Delay2
	CALL Delay2
	CLRF 06		;Blank display	
	CALL Delay2
	DECFSZ 1E,1	;Decrement the 2-loop file
	GOTO Sect2b
	GOTO Sect3a	;Go to next section

Sect3a	CLRF 06	
	BTFSS 05,0	;Button pressed?
	GOTO Sect3a
	MOVLW 02	;2 loops of "4-LEDs flashing"
	MOVWF 1Eh	;The 2-loop file
Sect3b	MOVLW 0Fh
	MOVWF 06
	CALL Delay2
	CALL Delay2
	MOVLW 0F0h
	MOVWF 06
	CALL Delay2
	CALL Delay2
	DECFSZ 1E,1	;Decrement the 2-loop file
	GOTO Sect3b
	GOTO Sect4a	;Go to next section

Table1	ADDWF 02h,1	;Add W to the Program Counter to create a jump.
	RETLW 77h	;A    format= gfedcba
	RETLW 3Eh	;U    If any table value has a leading letter, it must be
	RETLW 5Eh	;d    preceded with a "0."   E.g: 0A3h, 0FFh, 0CCh
	RETLW 06h	;I
	RETLW 3Fh	;O		

Sect4a	CLRF 06	
	BTFSS 05,0	;Button pressed?
	GOTO Sect4a
	
Sect4b	CLRF 1Dh	
Sect4c	MOVF 1D,0	;Copy file 1D to W
	CALL Table1
	MOVWF 06	;Output a letter
	CALL Delay2
	CALL Delay2
	CLRF 06 
	CALL Delay2
	INCF 1D,1
	MOVLW 05
	XORWF 1Dh,0
	BTFSS 03,2	;Check zero bit in Status	
	GOTO Sect4c		
	GOTO Sect5a	;Go to next section	

Delay5	NOP		;Create 1mS delay
	DECFSZ 1A,1
	GOTO Delay5
	RETURN

Sect5a	BTFSS 05,1	;Test the input line on port A
	GOTO Sect5b	;LOW detected
	BTFSC 1F,0	;HIGH detected. First pass of routine?
	GOTO Sect5a	;HIGH already detected
	BSF 06,0	;Turn on LED
	CALL Delay5
	BCF 06,0	;Turn off LED
	BSF 1F,0	;Set the detection flag
	GOTO Sect5a
Sect5b	BCF 1F,0	;Clear the detection flag	
	CLRF 06	
	BTFSS 05,0	;Button pressed?
	GOTO Sect5a	
	GOTO Sect6a

Table2	ADDWF 02h,1	;Add W to the Program Counter to create a jump.
	RETLW 73h	;P    format= gfedcba
	RETLW 3Fh	;O    If any table value has a leading letter, it must be
	RETLW 78h	;t    preceded with a "0."   E.g: 0A3h, 0FFh, 0CCh	

Sect6a	CLRF 1Dh	
Sect6b	MOVF 1D,0	;Copy file 1D to W
	CALL Table2
	MOVWF 06	;Output a letter
	CALL Delay2
	CALL Delay2
	CLRF 06 
	CALL Delay2
	INCF 1D,1
	MOVLW 03
	XORWF 1Dh,0
	BTFSS 03,2	;Check zero bit in Status	
	GOTO Sect6b		
	GOTO Sect7a	;Go to next section	

Table7	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
	RETLW 40h	;"-" overflow

Delay7	MOVLW 80h	;Create 100mS delay
	MOVWF 1B		
Delay7A	DECFSZ 1A,1
	GOTO Delay7A
	DECFSZ 1B,1
	GOTO Delay7A
	RETURN

Delay8	MOVLW 20h	;Create "Look" delay
	MOVWF 1A		
Delay8B	DECFSZ 1A,1
	GOTO Delay8B	
	RETURN

Look	CLRF 0C		;Count-down file		
	BSF 06,7	;Take cap HIGH
Look2	CALL Delay8	
	BTFSS 05,4	;Is input LOW?
	GOTO Look3
	INCF 0C,1
	GOTO Look2
Look3	MOVF 0C,0	;Put file 0C into W
	CALL Table7		
	MOVWF 06	;Output to 7-Segment display
	CALL Delay7	
	BCF 06,7	;Take cap low 
	CALL Delay7	;100mS delay
	RETURN	

Sect7a	CALL Look
	BTFSC 05,0	;Button pressed?
	GOTO Sect8	
	GOTO Sect7a

Sect8	CALL Delay2
	BTFSC 05,0	;Button released?
	GOTO Sect8	
	CALL Delay2
	GOTO Sect1a	;Repeat tests

	END		;Tells assembler end of program









