You are on page 1of 22

ECNG2005 labs

Lab exercises for ECNG2005 labs


re: ECNG2006 Introduction to microprocessors
Contributors:
K. Hall
F. Mohammed
C. Radix
A. Sinanan
A. Williams
K. Edwards
A. Joseph
O. Regalado
K. Narine
I. Mohammed
Y. Panchu
S. Patrick
A. Abdool
C. Arneaud
N. Harrichand
H. Lawrence
D. Caberrea
P. Pollucksingh
V. Narine
c
Dept.
of Electrical and Computer Engineering, U.W.I. , St. Augustine
February 3, 2010

Contributes 30% of ECNG2005 mark:


1.5% Lab 1 PIC16F877 Toolchain Comparison (1 session)
1.5% Lab 2 PIC16F877 Basic programming (1 session)
3% Lab 3 PIC16F877 Further Programming with Basic Peripherals (2 sessions)
9% Lab 4 PIC16F877 Embedded Application Programming (4 sessions)

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 1

Lab 1
ID#
You may not be allowed in the lab if your pre-lab is incomplete. You will have 3 hours in the lab
to complete the exercises. All answers should be written on this lab-sheet in PEN. Please do not
attach any extraneous pieces of paper.
At the end of this unit the student will be able to:

utilize the MPLAB IDE, CCS compiler and other software tools, to develop software for
the MicroChip PIC16xxx series of microcontroller, in C/C++ and assembly language.
Pre-Lab
Please read through the entire lab script FIRST, so you know what is expected of you, and THEN
complete the following questions.
1. Please identify
your lab group (Thursday 9am-12noon or Friday 1pm-4pm):
your ECNG2006 uP group designator (e.g. A3):
2. In your own words, dierentiate between an integrated development environment (IDE) and
a simulator.
Hint: what do they input/output? what features do they oer? Is one a 5 marks
component of the other? You should use examples to support your answer.

3. Simulators come in three avors:


Groups C1,M1,P1,R1,H1 instruction cycle-level,
Groups C2,M2,P2,R2,H2 machine cycle-level,
Groups C3,M3,P3,R3 gate-level.
In your own words, debate why it is advantageous to simulate at the level assigned to your
5 marks
group, rather than at either of the other two levels.

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 2

4. For the Microsoft Windows XP operating system:


(a) How do you open a command window?

1 mark

(b) What is the meaning of the term command line interpreter? What is the command
1 mark
line interpreter for windows?

(c) What is the meaning of the term command line parameter?

1 mark

(d) How do you specify command parameters when you are using the command line inter1 mark
preter?

(e) How do you specify command parameters when you are using the Windows GUI?

1 mark

(f) What is the meaning of the term environment variable?

1 mark

(g) How do you set, clear OR examine the values of environment variables when you are at
the command line interpreter? Replicate the command for any ONE of these actions
on the environment variable PATH below.
1 mark

(h) How do you set, clear OR examine the values of environment variables when you are
1 mark
using the Windows GUI?Walk through the procedure

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 3

5. In this lab we will be looking at dierent tool-chains which can be used with the PIC16F877
under Windows XP. For your assigned tool, identify and explain TWO features (apart from
price) which make it superior to the competing tool in its category. You should support
your arguments using user testimonials which are not supplied by the tool creators. Cite all
references. Students are advised to check manufacturing companys website for USER blogs
comparing the product with its competitor
7 marks
Group(s)
C1,M1
P1
R1
H1
C2
M2

Tool
MPLAB
SDCC
GPLINK
MPASM
MPSIM
Command Batch les

Category
IDE
Compiler
Linker
Assembler
Simulator
Script

Tool
PICC
CCSC
MPLINK
GPASM
GPSIM
MinGW makeles

Group(s)
P2,R2
H2
C3
M3
P3
R3

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 4

6. Algorithms are descriptions of how a function can be achieved. in this lab, we will be using
a particular algorithm to calculate the logarithm of an integer. It is based on the principle of
comparing the number to an incrementally increasing exponent of the base. This is not the
only possible algorithm.
Groups C1,M1,P1,R1,H1 Borcharts algorithm
(e.g. http://www.dattalo.com/technical/theory/logs.html)
Groups C2,M2,P2,R2,H2 Exploits oating point representation
(e.g http://wehner.org/fpoint/)
Groups C3,M3,P3,R3 Uses a lookup-table
(e.g. http://www.dattalo.com/technical/software/pic/piclog.html)
Read about the alternative algorithm you have been assigned, and contrast it with the one
5 marks
used in this lab (looplogm.c). Use the calculation of log5 25 to support your answer.

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 5

Software Installation
Students may wish to install the same software on their own machine. A CD can be obtained
from Mr. Hall, or the software can by downloaded from their respective sites. To avoid problems,
please install software in the specied order. Please note that the OS in the lab is Windows XP.
Administrative privileges are required for a proper installation. We will not be able to give support
for problems experienced under other operating systems.
Microchip MPLAB IDE Depending on the version, the default installation directory is either
\ Program Files\ Microchip OR \ Program Files\ MPLAB OR \ Program Files\ MPLAB
IDE.
Please create a directory called Third Party within the installation directory. All other
software should be installed here.
CCS PCWH Please install in a subdirectory of your MPLAB installation;
for example \ Program Files\ Microchip\ Third Party\ PICC. Installation may complain
that it cannot nd the REG les; if so please use the les in the installation directory of the
CD. If the installation either fails to nd MPLAB.INI for versions of MPLAB greater than
6.0, or fails to set data in registry, then you should install the plug-in.
CCS MPLAB plug-in Only required for MPLAB versions greater than 6.0. Please Install in the
same directory as the CCS PCWH i.e. Third Party\ PICC
GPUTILS Please install in Third Party\GPUtils
GPUTILS MPLAB plug-in Only required for MPLAB versions greater than 6.0. Please Install
in the same directory as the GPUTILS i.e. Third Party\ GPUtils
GPSIM Please install in Third Party\ GPSIM
SDCC Please install in Third Party\ SDCC
MinGW Make Please install in Third Party\ MinGW
PIC16F877 Visual Simulator Please install in Third Party\ Visual Simulator.

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 6

In the Lab
Before you start, please ensure that the computer is set up to show le extensions:
Click on My Computer then select the following from the menu(s) and pop-up windows:
Tools -- Folder Options -- View.
Ensure that the checkbox labelled Hide extensions for know files is clear.
Click OK or APPLY.
Next, create a directory on the Z: drive . This is the directory you will work with during the lab.
In the My Computer window, double-click on the icon for the drive.
Right click and select New Folder.
Name the directory uPxxxxxxxx where xxxxxxxx is your ID number.
Finally, unzip the archive ecng2005-uP-lab1.zip into the directory you have just created.
Please ENSURE that you delete your directory at the END of the lab (you can copy it to your Z:
drive or a key rst!)

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 7

Command Line Basics


1. Open a command window. Tick each of the following items as you try it:
The prompt tells you which directory is currently active. e.g. D:\myfolder
To change directories we type the command cd followed by the name of the directory to
which we wish to move e.g. cd \anotherfolder. The directory name is the command
line parameter that we supply for the command cd.
To change drives we type the new drive letter followed by a colon. e.g Z:
If we do not speciy the full path of the directory then we will move to a subdirectory
of the current directory. We also have directory shortcuts . and .. which stand for the
current and parent directories respectively.
Now lets get to work!
(a) Use the cd command to make the folder you created your active directory. Use the space
below to make notes to help you remember how to do this.

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

(b) Within a directory we can list the les and subdirectories using the dir command. The
dir command also works if we give it the path to a directory e.g. dir C:\otherfolder
Use the dir command to list the les in another directory . Use the space below to make
notes to help you remember how to do this.

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

(c) At the command line we often cannot remember all the options for a command. Most
commands have help. To display help for a command, try typing the command name
followed by -h , /h, or /?. Not all of these options will work with all programs, but
usually at least one will.
Try dir /?. Which options are available for the dir command? Choose one and use it.
Write a short description of what you did and what happened.

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

1 mark

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 8

(d) We can print the contents of a le to the screen using the command type. Print the
contents of any text le (weve supplied lab1read.asc) in the command window.

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

(e) We can even start applications. To start Windows Notepad type notepad. You should
close the instance of Windows Notepad which just opened before proceeding.
If you have a sequence of commands that you execute regularly, it can be tedious to type
and retype them. You can place a sequence of commands in an ASCII text le called a
script or BATCH le. When you type the name of the batch le, the commands will be
executed in sequence.
Use the dir command to look in the directory for les with the .bat extension. Type
the name of the le (excluding the .bat extension) at the command prompt.
What happened?

1 mark
Show your lecturer or TA and have them sign/stamp your script here.
Edit the batch le (you can use Windows Notepad) and change it so that it uses the
commands you have learned to change active directory to your folder, and type out the
contents of lab1read.asc, regardless of the directory from which it is called. Save and
test your batch le. Write down the nal batch le commands here.

Show your lecturer or TA and have them sign/stamp your script here.

2 marks

(f) Type set at the command line to see ALL the environment variables which are currently
set. You can also use the set command to create and alter environment variables.
When you set or clear environment variables at the command line, the changes only
aect that command window. If you open another window, the changes will not be
there. Close your current command window. Open a new window and have a look.
If you ever need/want to make global changes to environment variables, right-click on
My Computer,Advanced,Environment Variables.
Create an environment variable called ECNG2005 and then change the value from Test
to Ok. What command(s) did you use?

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

1 mark

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 9

(g) Environment variables are useful; they often specify default values to applications. Some
environment variables actually control how the command window/computer behaves.
For example the PROMPT environment variable controls how the command prompt is
displayed. You may use the prompt or set commands to alter it. Change the prompt so
that it displays your name before the drive letter and path. What command did you use?

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

(h) The PATH environment variable lists all the places (search paths) that the computer
will look for a program. If you type the name of a program which is not in the current
directory, and not in one of the search paths, then the computer will complain. Start
Windows notepad by typing notepad (or notepad.exe at the prompt). Try clearing the
path variable (set PATH=). Does notepad still start from the command prompt?

Show your lecturer or TA and have them sign/stamp your script here.
Please close all command windows before proceeding.

Build Tools
Compilers take ASCII text les, that contain source code, as their input. You can edit any
source code le in any ASCII text editor. This is IMPORTANT! There is no need to cut and
paste code between dierent editor applications - simply close the le, then open the same
le in another editor.
Go ahead any create a Visual C/C++ project. You will be able to open the resulting *.c
or *.cpp les in Windows Notepad, change them, and then use the changed le in Visual
C/C++.
If you open a le that is not ASCII text in any text editor, it will look like junk.
Windows Notepad is an Editor. Visual C/C++ is an Integrated Development Environment
that includes an editor. When you click build, it passes a command (just like the ones we
have just used) to start the compiler.
We are going to investigate compilers for the PIC16F877.

c
DECE,
UWI, St. Augustine, Trinidad

1 mark

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 10

2. Open an ASCII text editor (e.g. Windows Notepad) and examine the code in looplogm.c.
This code will calculate the base-n logarithm of the integer x. The initial value of n should
be 3, and the initial value of x should be 81. If not correct and save the le.
Make two subdirectories called SDCC and PICC in your working directory. Place a COPY
of looplogm.c in each of your directories.
(a) Open a new command window. In this window we will utilise the CCS PIC-C compiler
to compile the code.
You need to set the PATH environmental variable so that ccsc.exe to run correctly.
The command will depend on the path to the PICC directory on your computer. A
typical command would look like:
set PATH=%PATH%;F:\Program Files\MicroChip\Third Party\PICC
You need to change the active directory to PICC subdirectory of your personal
folder. A typical command would look like cd D:\uP12345678\PICC Edit the copy
of looplogm.c in this directory. Be sure to include a #DEVICE line in your le to
specify the target processor (PIC16F877).
Run the compiler command: ccsc.exe looplogm.c +FM +P -J. What was dis1 mark
played?

If you have any errors, ask your lecturer/TA for assistance.


Once your le has compiled correctly, look at your folder. List the names and extensions of the les which have been created. For each le: Indicate whether it is
an ASCII text le, and if it is, write out one/two lines from the le. (Try to choose
interesting ones!)

Filename

Filesize

ASCII?(human
Extract (if ASCII)
readable?

looplogm.c
looplogm.sym
looplogm.hex

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

2 marks

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 11

We could also create a batch le to run CCSC compiler. In your batch le called
myccsc.bat place the commands you have just learned to set the path, change the
directory, and run ccsc on looplogm.c.
If you replace the name of your le within the batch le with %1 then you can specify
the le to be compiled along with the name of the batch le at the command line.
For example myccsc myfile to compile myfile.c.
Test your nal batch le and write it below. Test your batch le in a new command
window.

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

Close all command windows.


(b) Open a new command window. In this window we will utilise the SDCC compiler to
compile the code.
You need to set the PATH environmental variable for sdcc.exe to run correctly.
1 mark
How are you going to do this?

You need to change the active directory to the SDCC subdirectory of your personal
1 mark
folder. How are you going to do this?

Make sure there is a copy of looplogm.c in the SDCC directory. No preprocessor


directives are needed for this compiler. Unlike the #DEVICE needed for PICC, we
will specify the processor on the command line for SDCC.
Run the compiler command: sdcc -S -V -mpic14 -p16F877 myfile.c. Please
1 mark
note that the command line options are case sensitive. What was displayed?

If you have any errors, ask your lecturer/TA for assistance.

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 12

Once your le has compiled correctly, look at your folder. List the names and
extensions of the les which have been created. For each le: Indicate whether it is
an ASCII text le, and if it is, write out one/two lines from the le. (Try to choose
interesting ones!)

Filename

Filesize

ASCII?(human
Extract (of ASCII les)
readable?)

looplogm.c
looplogm.asm
looplogm.d

Show your lecturer or TA and have them sign/stamp your script here.
2 marks
We could also create a batch le named mysdcc.bat to run the SDCC compiler.
Try it below!

Show your lecturer or TA and have them sign/stamp your script here.
Close all command windows.
The nal le which is required for download to the PIC16F877 microcontroller is an Intel
HEX format le *.hex".
You should have noticed that although both compilers generated les, only CCSC created a
".hex le. CCSC accomplished the compiling, assembling, and linking in one step.
SDCC generated an assembly language le *.asm. To complete the job for SDCC we would
need to use a separate assembler and a linker.
Assemblers and linkers can also be used for code which you write directly in assembly.

c
DECE,
UWI, St. Augustine, Trinidad

1 mark

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 13

3. Alter your SDCC batch le so that the search path for gpasm.exe and gplink.exe is added.
They are located in Third Party\GPUtils\.
Add the path of GPUTIlS to your path. Add the following lines at the end of your batch
le: ( These commands are available in the le batfileadd.txt; you may need to change
looplogm to %1 if you have used that option previously).
set GPUTILS_HEADER_PATH=F:\Program Files\MicroChip\Third Party\GPUtils\header
set GPUTILS_LKR_PATH=F:\Program Files\MicroChip\Third Party\GPUtils\lkr
gpasm -c looplogm.asm
gplink -m -o looplogm.hex looplogm.o (line wraps)
F:\Program Files\MicroChip\Third Party\SDCC\lib\pic\libsdcc.lib
Run the SDCC batch le in a new command window. If you have any errors, ask your
lecturer/TA for assistance.
(a) Once your le has compiled, assembled and linked correctly, look at your folder. List
the names and extensions of the ADDITIONAL les which have been created by gpasm
and gplink. For each le: Indicate whether it is an ASCII text le, and if it is, write
out one/two lines from the le. (Try to choose interesting ones!)

Filename
looplogm.hex
looplogm.o

Filesize

ASCII?

Extract

Show your lecturer or TA and have them sign/stamp your script here.

2 marks

4. Compare the les generated by the two processes from the same original C le. Are they
identical? Did you expect them to be? Explain why you did or did not think so.

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

4 marks

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 14

Build Tools Roundup - Make Utility


5. (a) The batch le works well for a single le, but where we want to establish rules for
compiling les it is often more productive to use a makele. Using this makele we can
specify dierent targets, and how they come together to form the nal executable. We
will only use a simple makele here (an electronic copy of makefile is available).
%.asm:

%.c
F:\Program Files\MicroChip\Third Party\SDCC -S -V -mpic14 -p16F877 $<

%.o:

%.asm
F:\Program Files\MicroChip\Third Party\gpasm -c $<

%.hex:

%.o
F:\Program Files\MicroChip\Third Party\gplink -m -o $@ $< \\
F:\Program Files\MicroChip\Third Party\SDCC\lib\pic\libsdcc.lib

Each rule starts in the rst column (no space or TAB) and species the Target. Our
targets all start with % which is a wildcard i.e. the rule will match any le which has
the same sux. This is followed by a list of dependencies (les that must exist in order
to produce the target) . Then the following lines (each starting with a TAB) list the
command(s) used to make the target ($@) from the dependencies($<).
Check the rules in the le called makele (no extension) in the SDCC directory.
Open a command window and add the paths for sdcc, gputils, and mingw\bin to
the search path.
Make the SDCC directory the active directory.
Test your makele is syntactically correct by using the command:mingw32-make. If
you have any errors, ask your lecturer/TA for assistance.
Type the following command: mingw32-make myfile.hex
4 marks
Delete myfile.hex and try it again.
Show your lecturer or TA and have them sign/stamp your script here.
You should notice that make automatically builds only the les that need to be updated.
This is one advantage over using scripts or batch les.

(b) Challenge(Bonus 10 marks): Place a makele in the CCSC sub-directory that could be
used to build a hex le using the ccsc compiler. Write your rule(s) down here.

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 15

Development Tools
We have looked at tools used to build the hex le from the source code. Now we will look
at tools which assist in the development of correctly functioning programs. The rst of the
development tools we will look at is the simulator.
Even though we have compiled the code on a HOST PC, the output le needs to be loaded
onto a TARGET microprocessor in order to run.
The HOST PC cannot normally run this le by itself. A simulator is a program which will
allow the HOST PC to interpret the machine code intended for the TARGET processor.
This is a convenient alternative for the developer, as software development can start even
though the hardware is not available.
6. GPSIM is a Windows based simulator for the PIC16F877. To start gpsim,

Open a new command window.


Change the active directory to SDCC (or CCSC for next question!).
Add the search paths for gpsim, and gputils.
Use the following command to start gpsim: gpsim -p pic16f877 looplogm.hex

You will see text printed in the command window and a button bar will pop up.
(a) Open the Program Memory window, using the menu on the button bar. This has two
tabs, one tab shows the assembly language code, with each instruction next to its stored
address, and equivalent instruction code, while the other shows the bytes of instruction
code stored in the program memory in a matrix form. What range of instruction memory
locations are occupied by looplogm.hex.
Show your lecturer or TA and have them sign/stamp your script here.
(b) Open the RAM window, using the menu on the button bar. This is a matrix view of
the data memory.
You can step through the assembly language code using the step button. The command
window reports the status of the processor with each step. By looking at the RAM
window while you step, you can see how information moves from one register to another
in response to the instructions.
How many data memory locations are being used by looplogm.hex?
Show your lecturer or TA and have them sign/stamp your script here.
(c) It is inconvenient to keep stepping through a program. To move more quickly, set a
BreakPoint by double clicking on a program line in the Program Window. Reset the
processor (using the button on the button bar), then run. The processor should stop
before executing the line you have indicated.
Show your lecturer or TA and have them sign/stamp your script here.
(d) Open the StopWatch Window. This is used to determine how many cycles the code
takes to run. Play with the Stopwatch and the breakpoint to see how long the code
takes to execute.
How many cycles are being used by looplogm.hex?
Show your lecturer or TA and have them sign/stamp your script here.
Close GPSIM when you are done.
c
DECE,
UWI, St. Augustine, Trinidad

1 mark

1 mark

1 mark

1 mark

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 16

7. Repeat the process described in 6 to measure the number of instruction memory locations,
data memory locations, and cycles required by the version of looplogm.hex generated using
3 marks
CCSC (instead of the one generated using SDCC).

Show your lecturer or TA and have them sign/stamp your script here.
8. The PIC16F877 Visual Simulation was written to illustrate what goes on inside the microcontroller on each clock cycle i.e. it is a cycle-level simulator. GPSIM is an instruction-level
simulator. It does not show us what goes on within the instruction-cycle.
When you launch the PIC16F877 Visual Simulation, the main window will look like the layout
diagram shown in your data-sheet book.
Just like the GPSIM simulator, this simulator loads in the Hex le output by the compiler.
Launch the PIC16F877 Visual Simulation from the Windows Menu.
To load in a hex le, Click on TASKS, DECODE HEX File; a window named
Decode Hex File will come up; you should Choose Select File to Decode. Locate
either of your compiled hex les and press OK. In the Hex Data Field, you will see
the actual contents of the HEX le.
When parsed (using the Intel Hex format) the byte-codes to be loaded at particular
addresses are displayed in the Parsed data Field.
Click the DECODE button, to interpret the instruction op-codes & operands as mnemonics.
(a) Does this match the GPSIM views of program memory? Is that what you expected?
1 mark
Explain your answer.

(b) Click the Back to the interface button and run the simulator by Clicking the start
processing button. You will see two dots moving around the screen.
Blue Dot represents information ow due to the fetch phase of the pipeline.
Red Dot represents information ow due to the execute phase of the pipeline.
Each phase is made up of 4 sections, Q1 to Q4, the duration of which is set by the
clock. The currently executing phase is displayed on the left. Pay particular attention
to what happens when a goto instruction is executed. How is pipeline execution aected? 2 marks

You should close/pause the PIC16F877 Visual Simulation when you are nished.
c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 17

Build & Development Tools Roundup The Integrated Development Environments(IDE)


An IDE allows us to perform all the tasks we have looked at from a single interface. Some
IDEs are supplied with their own tool-chain, while others contain no tools and must be
congured to work with your tools. Environmental variables, batch les, scripts, makeles,
and command line parameters can all be used with an IDE to make it operate seamlessly with
a tool-chain. Instead of manually calling separate programs to translate from .c to .asm to
.o to .exe; we can automatically call appropriate programs.
The MPLAB IDE is an example of an IDE that comes with its own tools, but allows you
the option to choose other build tools (like the CCS compiler), and customize environmental
variables, and command line parameters.
9. (a) Start the MPLAB IDE from the menu. Like most Windows based IDEs there is a menu,
toolbar, workspace and a status bar. Create a new project in your CCSC subfolder.
Click PROJECT on the menu bar and select PROJECT WIZARD. In the
PROJECT WIZARD box click NEXT. From the DEVICE drop down menu
select PIC16F877 and click NEXT. Select CCS C COMPLIER form the ACTIVE TOOLSUITE dropdown box and then click NEXT.
Enter myproject in the box named PROJECT NAME. Then browse and nd
the PICC folder you created for the PROJECT DIRECTORY box and click
NEXT.
A window will now come up with the buttons ADD and REMOVE, add your le
looplogm.c from the CCSC directory and then click FINISH in the new window.
Then go to WINDOW on the menu bar and select project1.mcw. You will see
looplogm.c . Now double click the looplogm.c link and your program will
appear.

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

(b) The MPLAB IDE has a built in editor. It can be used to view and edit any ASCII-type
le. Try opening dierent les in the CCSC directory.

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

1 mark

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 18

(c) The MPLAB IDE also has a built in simulator. Go to the menu bar and select DEBUGGER > SELECT TOOL > MPLAB SIM. This means that you will be executing
your code on the simulator. You should be able to use the les which have already
been generated. To display the Program Memory click on the VIEW > PROGRAM
MEMORY menu item. The buttons at the bottom left of the window, allow you to
access three dierent views of the Simulator Program Memory. State the name of each
the view, and identify how the views dier from each other. Are these views similar to
the ones we had in the other two simulators?
2 marks

(d) The PC value displayed in the status bar is set to 0x00. Let us investigate how to
advance the PC to the next instruction location. To advance to the next instruction
location click on the DEBUGGER menu and choose STEP OVER from the menu.
What do we see happening? Is this similar to what happened in the other two simulators?

Show your lecturer or TA and have them sign/stamp your script here.

2 marks

(e) The MPLAB IDE project has been set up to use the same CCSC compiler we used at the
command line. Click on the PROJECT > BUILD ALL menu item (or press F10),
to compile the project. A build window should appear stating the build was successful.
Have a close look. Can you see the command used to launch the compiler? Write it
below.

Show your lecturer or TA and have them sign/stamp your script here.

1 mark

(f) In the GPSIM simulator we used breakpoints, a view of RAM and a stopwatch. Locate
the equivalent functions in MPLAB.

Show your lecturer or TA and have them sign/stamp your script here.

c
DECE,
UWI, St. Augustine, Trinidad

3 marks

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 19

Performance Comparison
So far we have compared the sizes of les, the number of instruction and data memory
locations used, and the number of cycles that the program requires to run.
The performance of the nal *.hex le depends on:
the algorithm implemented
the compiler/assembler used to generate the *.hex le
the language and data types used for implementation
We will investigate each of these in turn, using the skills we have acquired during this lab.
The comparison criteria to be used are:
I the size of the source code le in bytes
II the number of instruction memory locations used by the nal program
III the number of data memory locations used by the nal program
IV the number of instruction cycles required to execute the program on test case A
V the number of instruction cycles required to execute the program on test case B
The test cases to be used are A: log3 81 and B: log5 25.
10. Challenge Question: (Bonus 10 marks) Use the test cases to discuss WHY the algorithm you
researched for the pre-lab is likely to perform better or worse than the algorithm implemented
in looplogm.c. In addition to the specied comparison criteria, you could also consider the
accuracy/suitability of the nal solution.

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 20

Item
I
II
III
IV
V
Units
bytes instruction-words data-words cycles cycles
looplogm.c with CCSC
looplogm.c with SDCC
liblogm.c with CCSC
liblogm.c with SDCC
asmlogm.asm
Table 1: Performance comparison results

11. Use data from previous pages, and modify the programs and re-run them to obtain data to
2 marks
update the rst two rows in Table 3.
Demonstrate the changes made to your TA/lecturer, who will sign/stamp your script as
conrmation.
12. The program liblogm.c uses the compiler provided math libraries to calculate the answer.
10 marks
Compile and/or assemble programs as necessary to ll the second two rows of the Table 3.
Demonstrate this to your TA/lecturer, who will sign/stamp your script as conrmation.
13. Make a new project in MPLAB to assemble asmlogm.asm. You may use either the MPASM
5 marks
or the GPASM assembler. Make the measurements needed to update Table 3.
Demonstrate this to your TA/lecturer, who will sign/stamp your script as conrmation.
14. Use your data to identify which is the most eective implementation of logarithm. Justify
3 marks
your choice, and explain whether this is what you had expected.

Total marks 100.


This exercise is worth 5% of your ECNG2005 lab mark.
PLAIGIARISM DECLARATION:
For the purposes of this exercise, unauthorised collaboration is any form of collaboration which does NOT fall into one of the following categories:
verbal or written discussion/clarication of question and/or related concepts
assistance in troubleshooting circuitry and/or using/operating the IDE/debugger
Department of Electrical and Computer Engineering
PLAGIARISM Plagiarism is the presentation by a student of an assignment which has in fact been copied in whole or in part from another students
work, or from any other source (e.g. published books or periodicals), without due acknowledgement in the text.
COLLUSION Collusion is the presentation by a student of an assignment as his or her own which is in fact the result in whole or part of unauthorised
collaboration with another person or persons.
DECLARATION I declare that this assignment is my own work and does not involve plagiarism or collusion. I have read and understood University
Examination Regulations 73,75,76 and 79 regarding cheating.
Signed:

Date:

(Department of Electrical and Computer Engineering)

c
DECE,
UWI, St. Augustine, Trinidad

ECNG2005 labs (P)

February 3, 2010

Lab 1-p. 21

Write the number you have been assigned here


.
Answer the following questions for the TARGET platform whose number you were assigned.
1. What is the name of the target platform?

2. Where did you nd the information?

3. Who is the manufacturer of the tool-chain?

.
.

4. What is the price of this tool-chain?


5. Which HOST platform/operating system(s) can use this toolchain?
6. Which of the following items does the tool-chain contain?

IDE

pre-dened header les

make utility OR makeles

pre-dened library les OR librarian

batch/shell les OR other scripts

simulator

assembler

downloader

disassembler

debug kernel + monitor

linker

other

compiler

Reection & Feedback


Indicate the objectives that you feel you have achieved in this lab exercise.
utilize the MPLAB IDE, CCS compiler, and other software tools, to develop software for
the MicroChip PIC16Cxxx series of microcontroller, in C/C++ and assembly language.
Which aspect of this lab exercise did you have the most diculty understanding?

Which aspect of this lab exercise did you like best? Why did you like it?

Identify one thing (if any) that you learned while doing this lab exercise.

Identify one way in which this lab exercise could be improved.

c
DECE,
UWI, St. Augustine, Trinidad

You might also like