HomeArticlesProjectsBlogContact
Articles
Test Routine
Colin Mitchell
Colin Mitchell
Make sure to subscribe to our newsletter and be the first to know the news.

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: Experiments - Page 2 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

        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
Sect1b  MOVWF 06        ;Illuminate the lowest LED
Sect1c  RLF 06,1        ;Shift to the left so that end LED shows equal time
        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
Sect1d  GOTO Sect1c     ;Loop shift-left instructions.
Sect1e  RRF 06,1        ;Shift to the right so that end LED shows equal time
        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"
Sect2b  MOVWF 1Eh       ;The 2-loop file
        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"
Sect3b  MOVWF 1Eh       ;The 2-loop file
        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
Sect4c  CLRF 1Dh
        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
Sect5b  GOTO Sect5a
        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
Sect6b  CLRF 1Dh
        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
Delay7A  MOVWF 1B
        DECFSZ 1A,1
        GOTO Delay7A
        DECFSZ 1B,1
        GOTO Delay7A
        RETURN
Delay8                  ;Create "Look" delay
        MOVLW 20h
Delay8B  MOVWF 1A
        DECFSZ 1A,1
        GOTO Delay8B
        RETURN
Look                    ;Count-down file
        CLRF 0C         ;Take cap HIGH
Look2   BSF 06,7
        CALL Delay8     ;Is input LOW?
        BTFSS 05,4
        GOTO Look3
        INCF 0C,1
Look3   GOTO Look2      ;Put file 0C into W
        MOVF 0C,0
        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


Colin Mitchell

Colin Mitchell

Expertise

electronics
writing
PIC-Chips

Social Media

instagramtwitterwebsite

Related Posts

TODO
Transistor Test
© 2021, All Rights Reserved.

Quick Links

Advertise with usAbout UsContact Us

Social Media