In this session you will learn how to simulate inputs and outputs that would normally be available at the input/output pins of a PIC device.
This requires the use of a stimulus file which you will create alongside your .asm source file.
Simulation of input/output can be achieved using the simulator and an additional
stimulus file. Copy the following program into a new source file and create
a new project as done previously.
| ; Second program to add two numbers together and store the
result ; ; Two four bit numbers are added together, the values being entered via portB ; as a byte. ie. the upper nibble and the lower nibble of the byte value entered ; on portb are added together and the result is output on portA. |
|||
| ; ; ****** PROGRAM EQUATES ****** |
|||
| LIST | p=16C54 |
||
| porta | EQU | 0x05 | |
| portb | EQU | 0x06 | |
| temp1 | EQU | 0x07 | |
| temp2 | EQU | 0x08 | |
| w | EQU | 0 | |
| f | EQU | 1 | |
| ; ; ****** MAIN PROGRAM ****** |
|||
| start | ORG | 0x000 | |
| BSF | 3,5 | ;select page 1 | |
| MOVLW | 0xFF | ||
| TRIS | portb | ;Configure port B as an input | |
| MOVLW | 0x00 | ||
| TRIS | porta | ;Configure port A as an output | |
| BCF | 3,5 | ;select page 0 | |
| ; | |||
| read | MOVF | portb,w | ;Read value from port B into w |
| MOVWF | temp1 | ;Store value in temp1 and | |
| MOVWF | temp2 | ;temp2 | |
| SWAPF | temp2,f | ;Swap nibbles in temp2 | |
| MOVLW | 0x0F | ;Move mask byte into w | |
| ANDWF | temp1,f | ;Mask off upper nibbles | |
| ANDWF | temp2,w | ;temp1 and temp2 | |
| ADDWF | temp1,w | ;temp1 + temp2 > w | |
| MOVWF | porta | ;Store the result on port A | |
| GOTO | read | ||
| ; ; ****** RESET VECTOR ****** |
|||
| ORG | 0x1FF |
;Reset Vector of 16C54 is 0x1FF | |
| GOTO | start | ||
| END | |||
In order to simulate input, an additional stimulus file must be written.
Go to the File menu and select New Source.
Type in the file as shown below and save it as input.sti
! indicates comment
| ! Stimulus file for input/output | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| STEP | RB7 | RB6 | RB5 | RB4 | RB3 | RB2 | RB1 | RB0 | |
| 4 | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | !63 |
| 9 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 | !23 |
The STEP column (in the table above) indicates the step or cycle that the values on that
line should occur.
eg. In the above, after executing STEP 4 the byte value 0x063 will appear
on RB7 - RB0. After STEP 9 the byte value on port B will change to 0x023.
More values can be added at different steps depending upon the application.
Before single stepping the program it must be indicated to the project that an input stimulus file is in use. Go to the Debug menu, select Simulator stimulus and then Pin stimulus. Enter <input.sti> and click on OK.
Open the stopwatch under the 'Window' drop down menu.
The stopwatch indicates the value of the target frequency and also indicates the step or cycle number. Every time a program is single stepped the stopwatch must be cleared to zero.
After clearing the stopwatch, reset the program and single step through the
program.
When step/cycle 4 is reached the value on port b should change to 0x063.
Similarly, when step/cycle 9 is reached the value on port b should change
to 0x023.
Continue to single step through the program and try to follow the function
of each line.
Updated 29.06.07 ML
Powered by Google
Site Map