Test Routine

This TEST ROUTINE is supplied in the chip when you buy a kit. It is removed when any other program is "burnt" into the chip. You may need to use it (or some of the sub-routines), at a later date. That's why it has been presented here. It is included in All PicLab-1.hex
Click on "All PicLab-1.hex" and a window will open with all the .hex files. Locate Notepad.exe in the window and click on it.  Notepad will open. Click on the file you want to open and slide it across to the Notepad window. The .hex values will appear!

To use the TEST ROUTINE, build the PIC LAB-1 and go over the construction, making sure all the components have been fitted and all connections are soldered perfectly. 
Fit the 4 cells to the battery holder.  
Fit the pre-programmed PIC16F84 chip to an 18 pin IC socket, supplied in the kit as a spare IC socket (to make the chip easier to fit and remove from the Multi Chip Programmer) and the project is ready for testing.
There is one slight problem with the Test Routine. Some constructors find it difficult to get past the AUdiO loop of the program and into the POt loop.
The best thing to do is fit the microphone and pot to the board before turning the project on.
You are now ready to perform the Test Routine:
Turn the project ON and the row of 8 LEDs will scan across and back. The individual segments of the 7-segment display will also turn ON. Push button "A."
The letters "Pb" will show on the 7-segment display - for "Push button."
Push button "A" again and the top 4 LEDs will blink, followed by the lower 4 LEDs. Push button "A" again. The letters "AUdiO" will show on the display. Push button "A" again.
The microphone will already be fitted to the 2-pin plug marked "MIC." Talk or whistle into the microphone. The lowest LED will turn ON to indicate audio. While whistling into the microphone, push button "A" again. It is important to whistle while pushing button "A" to get the micro to enter the next loop.
The letters POt will flash on the 7-segment display. Push button "A" again.
The pot will already be fitted into the 2-pin plug labelled "Pot." Rotate it in both directions. The 7-segment display will indicate rotation. 
All the input and output devices are now tested. 
Push button "A" to repeat the sequence.

TEST ROUTINE PROGRAM
Many of the sub-routines in the Test Routine will be very handy when you are designing your own program. 
At the moment they are too complex to understand. The Experiments in this course start with very simple routines and carry out a single function. 
After testing the project, go to the start of the experiments: Expt 1.asm 
The TEST ROUTINE is an example of linear programming. This is very simple programming where the microcontroller advances down the program into self-contained sections. You don't have the problem of jumping up and down the program looking for faulty instructions. When writing the program, each section is written and tested before going to the next section. This will make the program longer, but much easier to diagnose.

			;Test1.asm
 			;Project: TEST ROUTINE
 	List P = 16F84
 	#include <p16F84.inc>
    __CONFIG 1Fh ;_CP_OFF & _PWRTE_ON & _WDT_ON & _RC_OSC

SetUp







Delay








Sect1a

Sect1b
Sect1c




Sect1d
Sect1e





Delay2 






Sect2a

Sect2b















Sect3a




Sect3b











Table1






Sect4a



Sect4b
Sect4c













Delay5




Sect5a








Sect5b





Table2




Sect6a
Sect6b













Table7












Delay7

Delay7A





Delay8

Delay8B



Look

Look2




Look3







Sect7a




Sect8



ORG 0 
BSF 03,5 
CLRF 06 
MOVLW 1F 
MOVWF 05 
BCF 03,5 
BCF 03,0 
CLRF 1F 
GOTO Sect1a 

NOP 
DECFSZ 1A,1
GOTO Delay
BTFSC 05,0 
GOTO Sect2a 
DECFSZ 1B,1
GOTO Delay
RETURN 

MOVLW 01 
MOVWF 06 
RLF 06,1 
RLF 06,1 
BTFSC 03,0 
GOTO Sect1d 
CALL Delay 
GOTO Sect1c 
RRF 06,1 
RRF 06,1 
BTFSC 03,0 
GOTO Sect1b  
CALL Delay 
GOTO Sect1e 

NOP 
DECFSZ 1A,1
GOTO Delay2 
DECFSZ 1B,1
GOTO Delay2
RETURN 

MOVLW 02 
MOVWF 1Eh 
MOVLW 73h 
MOVWF 06 
CALL Delay2
CALL Delay2
CLRF 06 
CALL Delay2
MOVLW 7Ch 
MOVWF 06 
CALL Delay2
CALL Delay2
CLRF 06 
CALL Delay2
DECFSZ 1E,1 
GOTO Sect2b
GOTO Sect3a 

CLRF 06 
BTFSS 05,0 
GOTO Sect3a
MOVLW 02 
MOVWF 1Eh 
MOVLW 0Fh
MOVWF 06
CALL Delay2
CALL Delay2
MOVLW 0F0h
MOVWF 06
CALL Delay2
CALL Delay2
DECFSZ 1E,1 
GOTO Sect3b
GOTO Sect4a 

ADDWF 02h,1 
RETLW 77h 
RETLW 3Eh 
RETLW 5Eh 
RETLW 06h 
RETLW 3Fh  

CLRF 06 
BTFSS 05,0 
GOTO Sect4a

CLRF 1Dh 
MOVF 1D,0 
CALL Table1
MOVWF 06 
CALL Delay2
CALL Delay2
CLRF 06 
CALL Delay2
INCF 1D,1
MOVLW 05
XORWF 1Dh,0
BTFSS 03,2  
GOTO Sect4c 
GOTO Sect5a 

NOP 
DECFSZ 1A,1
GOTO Delay5
RETURN

BTFSS 05,1 
GOTO Sect5b 
BTFSC 1F,0 
GOTO Sect5a 
BSF 06,0 
CALL Delay5
BCF 06,0 
BSF 1F,0 
GOTO Sect5a
BCF 1F,0  
CLRF 06 
BTFSS 05,0 
GOTO Sect5a 
GOTO Sect6a

ADDWF 02h,1 
RETLW 73h 
RETLW 3Fh 
RETLW 78h 

CLRF 1Dh 
MOVF 1D,0 
CALL Table2
MOVWF 06 
CALL Delay2
CALL Delay2
CLRF 06 
CALL Delay2
INCF 1D,1
MOVLW 03
XORWF 1Dh,0
BTFSS 03,2  
GOTO Sect6b 
GOTO Sect7a  

ADDWF 02h,1 
RETLW 3Fh 
RETLW 06h 
RETLW 5Bh 
RETLW 4Fh 
RETLW 66h 
RETLW 6Dh 
RETLW 7Dh 
RETLW 07h 
RETLW 7Fh 
RETLW 6Fh 
RETLW 40h

MOVLW 80h 
MOVWF 1B 
DECFSZ 1A,1
GOTO Delay7A
DECFSZ 1B,1
GOTO Delay7A
RETURN

MOVLW 20h 
MOVWF 1A 
DECFSZ 1A,1
GOTO Delay8B 
RETURN

CLRF 0C  
BSF 06,7 
CALL Delay8 
BTFSS 05,4 
GOTO Look3
INCF 0C,1
GOTO Look2
MOVF 0C,0 
CALL Table7 
MOVWF 06 
CALL Delay7 
BCF 06,7 
CALL Delay7 
RETURN 

CALL Look
BTFSC 05,0 
GOTO Sect8 
GOTO Sect7a

CALL Delay2
BTFSC 05,0 
GOTO Sect8 
CALL Delay2
GOTO Sect1a 

END 
;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Load W with 0001 1111
;All Port A input
;Go to Bank 0 - the program memory area.
;Clear the carry flag
;Clear the flag file


;Create 250mS delay


;Look at input
;Go to next section 


;Return

;Put 0000 0001 into W
;Illuminate the lowest LED
;Shift to the left so that end LED shows equal time
;Shift LED to the left.
;Has LED reached end of display?
;Yes
;No. Illuminate LED
;Loop shift-left instructions.
;Shift to the right so that end LED shows equal time
;Shift LED to the right.
;Has LED reached end of display?
;Yes.
;No. Illuminate LED
;Loop shift-right instructions.

;Create 250mS delay




;Return

;2 loops of "Pb"
;The 2-loop file

;Output "P"





;Output "b"


;Blank display 

;Decrement the 2-loop file

;Go to next section


;Button pressed?

;2 loops of "4-LEDs flashing"
;The 2-loop file








;Decrement the 2-loop file

;Go to next section

;Add W to the Program Counter to create a jump.
;A    format= gfedcba
;U    If any table value has a leading letter, it must be
;d     preceded with a "0." E.g: 0A3h, 0FFh, 0CCh
;I
;O


;Button pressed?



;Copy file 1D to W

;Output a letter







;Check zero bit in Status

;Go to next section 

;Create 1mS delay




;Test the input line on port A
;LOW detected
;HIGH detected. First pass of routine?
;HIGH already detected
;Turn on LED

;Turn off LED
;Set the detection flag

;Clear the detection flag

;Button pressed?



;Add W to the Program Counter to create a jump.
;P    format= gfedcba
;O    If any table value has a leading letter, it must be
;t     preceded with a "0." E.g: 0A3h, 0FFh, 0CCh 


;Copy file 1D to W

;Output a letter







;Check zero bit in Status

;Go to next section

;Add W to the Program Counter to create a jump.
;0    format= gfedcba
;1    If any table value has a leading letter, it must be
;2    preceded with a "0." E.g: 0A3h, 0FFh, 0CCh
;3
;4
;5
;6
;7
;8
;9
;"-" overflow

;Create 100mS delay






;Create "Look" delay





;Count-down file
;Take cap HIGH

;Is input LOW?



;Put file 0C into W


;Output to 7-Segment display

;Take cap low 
;100mS delay



;Button pressed?




;Button released?


;Repeat tests

;Tells assembler end of program