Выбрать главу

$0008     main

//** Labels locations **

//ADDRESS LABEL

//----------------------------------------------

$0008     _main:

$0016     L_main_0:

$0024     L_main_3:

$002E     L_main_2:

$0034     L_main_1:

//** Variables locations **

//ADDRESS VARIABLE

//----------------------------------------------

$0000     STACK_0

$0001     STACK_1

$0002     STACK_2

$0003     STACK_3

$0004     STACK_4

$0005     STACK_5

$0006     STACK_6

$0007     STACK_7

$0008     STACK_8

$0009     STACK_9

$000A     STACK_10

$000B     STACK_11

$000C     STACK_12

$000D     STACK_13

$000E     STACK_14

$000F     STACK_15

$0010     STACK_16

$0011     STACK_17

$0012     STACK_18

$0013     STACK_19

$0014     STACK_20

$0015     main_Sum_L0

$0017     main_i_L0

$0F82     PORTC

$0F94     TRISC

$0FD8     STATUS

$0FD9     FSR2L

$0FDA     FSR2H

$0FDB     PLUSW2

$0FDC     PREINC2

$0FDD     POSTDEC2

$0FDE     POSTINC2

$0FDF     INDF2

$0FE0     BSR

$0FE1     FSR1L

$0FE2     FSR1H

$0FE3     PLUSW1

$0FE4     PREINC1

$0FE5     POSTDEC1

$0FE6     POSTINC1

$0FE7     INDF1

$0FE8     WREG

$0FE9     FSR0L

$0FEA     FSR0H

$0FEB     PLUSW0

$0FEC     PREINC0

$0FED     POSTDEC0

$0FEE     POSTINC0

$0FEF     INDF0

$0FF3     PRODL

$0FF4     PRODH

$0FF5     TABLAT

$0FF6     TBLPTRL

$0FF7     TBLPTRH

$0FF8     TBLPTRU

$0FF9     PCL

$0FFA     PCLATH

$0FFB     PCLATU

$0FFD     TOSL

$0FFE     TOSH

$0FFF     TOSU

Figure 5.41: EXAMPLE.LST

.HEX file  This is the most important output file as it is the one sent to the programming device to program the microcontroller. Figure 5.42 shows the EXAMPLE.HEX file.

:1000000004EF00F0FFFFFFFF946A156A166A010E05

:10001000176E000E186E000E006E1850005C02E1A4

:1000200017500A0807E31750152618501622174ACA

:10003000182AF1D715C082FFFFD7FFFFFFFFFFFF90

:020000040030CA

:0E000000FFF9FFFEFFFFFBFFFFFFFFFFFFFF0B

:00000001FF

Figure 5.42: EXAMPLE.HEX

5.3.3 Using the Simulator

The program developed in Section 5.3.2 is simulated following the steps given here, using the simulator in software (release mode). That is, no hardware is used in this simulation.

Example 5.2

Describe the steps for simulating the program developed in Example 5.1. Display the values of various variables and PORTC during the simulation while single-stepping the program. What is the final value displayed on PORTC?

Solution 5.2

The steps are as follows:

Step 1  Start the mikroC IDE, making sure the program developed in Example 5.1 is displayed in the Code Editor window.

Step 2  From the drop-down menu select Debugger→Select Debugger→Software PIC Simulator, as shown in Figure 5.43.

Figure 5.43: Selecting the debugger

Step 3  From the drop-down menu select Run→Start Debugger. The debugger form shown in Figure 5.44 will appear.

Figure 5.44: Starting the debugger

Step 4  Select the variables we want to see during the simulation. Assuming we want to display the values of variables Sum, i, and PORTC:

 • Click on Select from variable list and then find and click on the variable name Sum

 • Click Add to add this variable to the Watch list

 • Repeat these steps for variable i and PORTC

The debugger window should now look like Figure 5.45.

Figure 5.45: Selecting variables to be displayed

Step 5  We can now single-step the program and see the variables changing.

Press the F8 key on the keyboard. You should see a blue line to move down. This shows the line where the program is currently executing. Keep pressing F8 until you are inside the loop and you will see that variables Sum and i have become 1, as shown in Figure 5.46. Recently changed items appear in red. Double-clicking an item in the Watch window opens the Edit Value window, where you can change the value of a variable or register, or display the value in other bases such as decimal, hexadecimal, binary, or as a floating point or character.

Figure 5.46: Single-stepping through the program

Step 6  Keep pressing F8 until the program comes out of the for loop and executes the line that sends data to PORTC. A this point, as shown in Figure 5.47, i = 11 and Sum = 55.

Figure 5.47: Single-stepping through the program

Step 7  Press F8 again to send the value of variable Sum to PORTC. As shown in Figure 5.48, in this case PORTC will have the decimal value 55, which is the sum of numbers from 1 to 10.

Figure 5.48: PORTC has the value 55

This is the end of the simulation. Select from drop-down menu Run→Stop Debugger.

In the above simulation example, we single-stepped through the program to the end and then we could see the final value of PORTC. The next example shows how to set breakpoints in the program and then execute up to a breakpoint.

Example 5.3

Describe the steps involved in simulating the program developed in Example 5.1. Set a breakpoint at the end of the program and run the debugger up to this breakpoint. Display the values of various variables and PORTC at this point. What is the final value displayed on PORTC?