[Menu]>[Circuits Gallery]>[Count-down timer]


Debugging
of Count-down timer



Below, I will write the point of the software debugging work which used MPLAB.
I executed debugging by the way of debugging a step and the breakpoint.
As for those ways, refer to "Debugging of LED flasher" or "Debugging of signboard".

On this page, I will introduce the way of changing the part of the processing step for debugging.

Assembly specification by Directive

    There is 'IFDEF' directive in the assembler of MPLAB. When using this directive, the part to assemble by the definition of the label can be specified.
#define  _debug

(1)
#ifdef _debug
        movlw   d'255'
#else
        movlw   d'43'
#endif

(2)
#ifdef _debug
        movlw   d'255'
#endif

(3)
#ifndef _debug
        movlw   d'255'
#else
        movlw   d'43'
#endif

(4)
#ifndef _debug
        movlw   d'255'
#endif

The example on the left is defining '_debug' label in '#define'.
In this case, the assembly condition of the step which is specified by #ifdef, #ifndef, #else, #endif changes.

In case of (1) and (2), because '_debug' label is defined, the step (red) to #else or #endif is assembled. The step (blue) from #else to #endif isn't assembled.
#ifdef means "if a label(_debug) is defined".
#else means "not so".
Then, in case of (1) "If the label named _debug is defined, do assembling movlw d'255', not so(the _debug is not defined), do assembling movlw d'43'.".

(3) and (4) is opposite. The n of #ifndef means NOT.
Then. in case of (3) "If the label named _debug is not defined, do assembing movlw d'255', not so(the _debug is defined), do assembing movlw d'43'.".

Don't forget #endif.

This directive is the direction which specifies the part to assemble and doesn't interpret processing contents. This is not a logic IF like the C language.

This time, I used _debug as the label. However, this label isn't especially prescribed. The label for where you are plain can be used.

The part of the actual assembly result is shown below. It is the line that a red part is assembled.

When defining _debug label ( Debug mode )
LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE
                      00060 #DEFINE  _DEBUG

                      00153 #IFDEF _DEBUG
0042   30FF           00154         MOVLW   D'255'          ;(Debugging step)
                      00155 #ELSE
                      00156         MOVLW   D'43'           ;Set Hard timer value
                      00157 #ENDIF

                      00173 #IFNDEF _DEBUG
                      00174         BTFSC   PORTA,RA4       ;Stop switch ON ?
                      00175 #ENDIF
When not defining _debug label ( Actual mode )
LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE
                      00060 ;#define  _debug

                      00153 #IFDEF _DEBUG
                      00154         MOVLW   D'255'          ;(Debugging step)
                      00155 #ELSE
0047   302B           00156         MOVLW   D'43'           ;Set Hard timer value
                      00157 #ENDIF

                      00173 #IFNDEF _DEBUG
0051   1A05           00174         BTFSC   PORTA,RA4       ;Stop switch ON ?
                      00175 #ENDIF
    When not defining a label for the debugging, it puts semicolon (;) to the head of #define and it makes it a comment line.


Setting part of the directive
    In the software this time, I am putting a judgment for the debugging in the following part.
    The reading part of the BCD switch:Because it doesn't connect an actual BCD switch, it sets a test data for the debugging.
    The timer value setting part: The timer interrupt takes time when making an actual set value.
    It makes TMR0 = 255(the shortest) and it makes a judgment with the interruption number of two times and it makes the time of the debugging little.
    The reading part of the stop switch: The input port condition of MPLAB is fixed on '0'.(May be)
    The stop switch always becomes a pushed condition just as it is. With this, the counter becomes stop operation before the counter becomes a time-out condition. Because it is, in debugging, it makes the reading step of the stop switch invalid.
    The waiting time subroutine call part:The waiting time subroutine call of 1 millisecond isn't assembled in the debug mode.



Operation confirmation by the breakpoint

    I attempt to confirm the program which was assembled by the debug mode in the operation by the breakpoint.
    The breakpoints are set to PC=009Bh and 009Dh.

    The contents of the RAM memory change as follows every time it pushes the button after reset.
    In case of 00 00 00 01, it stops at PC=009Bh. PC=009Dh is a step after checking a time-out. When the contents of 0Fh of RAM address is 01, because the subtracted result is 0, PC jumps to process a time-out.

    0C0D0E0FRAM memory address
    01000000
    00090509
    00090508
    00090507

    Omitting
    00000001It jumps to process a time-out.