Professional Documents
Culture Documents
Simulation of The Program (Debugging) : Any Change You Do in Your Program Should Be
Simulation of The Program (Debugging) : Any Change You Do in Your Program Should Be
Simulation of The Program (Debugging) : Any Change You Do in Your Program Should Be
REMINDERS:
1
Microlab File 2 – by Joseph Massoud
2- We open the simulator task bar using Debugger/select tool/ MPLAB SIM
2
Microlab File 2 – by Joseph Massoud
3
Microlab File 2 – by Joseph Massoud
5- We get the following screen; we move the new window to top right of the
screen
4
Microlab File 2 – by Joseph Massoud
5
Microlab File 2 – by Joseph Massoud
6
Microlab File 2 – by Joseph Massoud
7
Microlab File 2 – by Joseph Massoud
8
Microlab File 2 – by Joseph Massoud
9- We repeat the same procedure (select /Add SFR) for: STATUS, TRISB,
TRISD, PORTB, PORTD; we get the following screen.
Note that the order in which registers are shown is not mandatory
9
Microlab File 2 – by Joseph Massoud
10- We still have to add the representation of the memory address 0x25 (H’25’)
which is the memory location of the result in our program.
(Note: we can add any number of registers and memory locations that we need to watch
during the execution of the program). In our first program, these were the registers in
use.
10
Microlab File 2 – by Joseph Massoud
11- If we wish to delete a line, we right-click on the line and press delete
11
Microlab File 2 – by Joseph Massoud
12- Press on the window of the program so it becomes active ; Make a quick
build to be sure the program is error free and build succeeded; close the
window of build and we are back to main screen and ready for simulation.
Adjust the window of the program to be able to see the program.
12
Microlab File 2 – by Joseph Massoud
13- Press reset and the green pointing cursor should point to first line (confi).
If you couldn’t see it, make a quickbuild for the program and then Reset .
13
Microlab File 2 – by Joseph Massoud
14- The pointer stands at the first line ; it means we are ready to execute the first
line ( not yet executed) .
We always have to look at the value of the register involved before and after
the execution of the instruction.
Here the instruction concerns register Status and in particular the
bit RP0 ( bit 5) . RP0= 0 before execution;
To execute one line we press “step into” one time (step into is the step by
step button).
We will see that the instruction was executed ( BSF status,RP0) , and RP0
becomes =1 .
14
Microlab File 2 – by Joseph Massoud
15- Now it is the turn of the second line instruction : MOVLW H’FF’.
It should put FFh ( 1111 1111 ) in W register.
We see first the value of W before execution ( it is = 0x00 =00h=0000 0000).
After execution it will become FF.
I click again one time “step into” button . The instruction will be executed
and W=FF. The pointer moves to the next line.
15
Microlab File 2 – by Joseph Massoud
16- The third instruction is MOVWF TRISB; it should copy W value into
register TRISB;
The content of TRISB will become FF.
However, if we look before we execute, we see that TRISB by default is equal
to FF.
So after executing the instruction, the value of TRISB will remain FF because
the micro will write FF also in it.
16
Microlab File 2 – by Joseph Massoud
17
Microlab File 2 – by Joseph Massoud
18- The sixth instruction is BCF status,RP0; it will put 0 again in RP0 .
We continue the step by step execution ( and watch at each line the changes),
till we reach the last line ( LOOP GOTO LOOP) ; Then we will see that the
program will be looped to this line no matter how much we pressed step into.
This is because the instruction GOTO takes the program to the line specified,
and which is the same line here.
The PORTD will contain 09, and the memory result (address 0x25=25h) will
contain also 09.
The final watch screen will be as follows:
18
Microlab File 2 – by Joseph Massoud
C- Assignment 2 ( you may screen shot your results and save them)
GOLDEN REMARK :
Every time we change any line or letter in a program we should quickbuild the
program to validate the change; Otherwise the simulator will disregard the change and
execute the previous program.
a) Open lab12.asm ; make the step by step simulation and check the results on PORTD
and in memory location H’26’. It should show 19 in decimal ( and 13 in Hexa).
b) Open lab13.asm ; make the step by step simulation and check the results on PORTD
and in memory location H’27’. It should show 07 in decimal and Hexa.
c) Open lab14.asm ; make the step by step simulation and check the results on PORTD
and in memory location H’28’. It should show 11 in decimal (and 0B in Hexa.)
Close MPlab and open it again. Open the file lab1.asm .We are now in step 13 ;
( we open again the lab1.asm and prepare the watch window). We click Reset and we
check that the pointer indicates the first line of the program (if it doesn’t show we make a
quick build ).
Instead of using “step into” , we click on animate button which comes with double blue
arrows ( and not the single arrow). We will see that MPLAB will run through the
whole program and will see the same end results. We press pause when we reach
the last instruction.
E- Assignment 3
21- Using Full program animation( you may screen shot results and save them)
19