Lab 1 (1-30-09)
Report Due: 2-6-09

In this lab you will learn how to use Microchip’s MPLAB interactive program 
development environment to build PIC microcontroller applications and simulate 
their execution. Using MPLAB you will develop an assembly language application 
for the QuikFlash microcontroller trainer and download it to the QuickFlash 
microcontroller using the Tera Term Pro Terminal Emulator program. Finally you 
will learn to use the QuikBug monitor program that has been burned into the 
memory of the PIC18F452 microcontroller on the QuikFlash board.

Preparation: You should have read Chapters 2 through 5 and Appendix A4 from 
your textbook before coming to lab. You may also want to take a look at the 
MPASM User's Guide and the MPLAB IDE Quick Start Guide. Both of these are on-
line. You can also download a copy of the MPLAB IDE for your own computer. 

Part 1. The MPLAB IDE Simulator Tutorial

Using one of the PCs in the lab, start the MPLAB IDE either by clicking on 
its icon or by selecting Microchip ‘MPLAB IDE | MPLAB IDE’ from the Windows 
task bar Start button. Make sure it's MPLAB IDE v6.30. Work through the MPLAB 
SIM tutorial which will show you how to create and build PIC microcontroller 
assembly language applications and simulate their execution. Start the tutorial 
by clicking on 'Help' on the main menu, then 'Topics' | 'Debuggers MPLAB SIM'. 
Click 'OK'. This will bring up the 'MPLAB SIM Simulator' Help window. Step 
through the tutorial.

Part 2. Creating an Application with MPLAB

Create and build the P1 application for the QuickFlash board (See Figure 5-7 
in your text book for the assembly language source code. This code may be 
copied and pasted into the MPLAB editor from the following web page: 
http://www.picbook.com/downloads/asm/P1.asm). The result will be a .HEX file 
ready for downloading to the microcontroller’s Flash memory.

Part 3. Setting up the QuickFlash board.

The TA will give each lab team a QuickFlash board, its power supply, and its 
serial connection cable. Handle the QuickFlash board with great care, being 
sure not to touch any of its components or solder connections. Connect the 
serial cable between the PC and the QuickFlash board. Plug in the board’s power 

Turn on the QuickFlash by flipping its on-off switch (SW1). You may notice 
that a program that displays the current temperature on the board’s LCD 
display (among other things), or perhaps some other program, has been burned 
into the board’s PIC16F452 microcontroller and begins to execute.

Part 4. Using Tera Term Pro and the QuikBug Monitor to download, run, and 
debug a QuikFlash application

Start the ttermpro (Tera Term Pro) terminal emulator program on the PC by 
clicking on its icon on the desktop or by selecting it from the task bar’s 
‘Start’ button. Select 'Setup' | 'Serial port' from the program’s menu. 
Make sure the settings are as follows:

Port: COM1
Baud rate: 19200
Data: 8 bit
Parity: none
Stop: 1 bit
Flow control: none
Transmit delay:  0 msec/char   20 msec/line

Probably the only parameter you will have to change from the defaults is the 
last one.

Turn off the QuikFlash board and turn it back on again. Within four seconds 
press any key on the PC keyboard. This will cause the QuikBug monitor program 
in the microcontroller to take control of it. You interact with this debugger 
over the serial link using the PC. The commands are: Help, reseT, Load, Display, 
Break, Watch, Run, Step, Modify. Each command is initiated by typing the 
appropriate letter (the one capitalized above). Although the QuikBug documentation 
states that function keys can also be used, you may find that they do not work. 
Use the QuikBug debugger to perform the following tasks:

1.  Reset the microcontroller
2.  Run the program preloaded into the microcontroller. What do you see 
    happening on the QuikFlash’s LCD display?
3.  Reset the microcontroller.
4.  Download the P1 program (the .HEX file) you developed with MPLAB in Part 2 
    above. (See Section 5.8 and Appendix A4 of your textbook if you don’t know 
    how to do this.)
5.  Reset and run the program. What do you see happening?
6.  Reset and single step through the first several instruction in the program. 
    After each step, write down (or copy and paste) what you see in the Tera 
    Term Pro window; i.e., the values displayed.
7.  Set a break point at the first instruction in the Initial subroutine and run 
    the program to that point. Single step through the first several instructions 
    of the routine. What values get loaded into the WREG?
8.  Examine the values stored in the first two variables of the program’s data 
    memory (the values of the first two variables in the program’s cblock). What 
    are they?
9.  Reset the program and set a break point at the movff TRMR0L,TMR0LCOPY 
    instruction in the LoopTime subroutine.
10. Set a Watch for the variable TMR0HCOPY, Run to the break point, and single 
    step several times until TMR0HCOPY changes. What are the old and new values? 
    Explain what is happening.
11. Set a Watch for the TIMR0H Special Function Register. Single step until TIMR0H 
    is updated. What is the new value, in decimal, stored in TIMR0H? 
12. Reset the program, set a break point at the first instruction in the LoopTime 
    subroutine, and Run the program to that point. Modify the INTCON Special 
    Function Register so that its TIMR01F bit is cleared (TIMR0 has not rolled 
    over). Step several times and notice what happens. Explain what you see.
13. Modify the TIMR01F bit so that it is set (TIMR0 has rolled over). Once again 
    Step several times and explain what you see.
14. Reset the program and set a break point at the decf ALIVECNT,F instruction in 
    the BlinkAlive subroutine.
15. Run the program and when it breaks examine the ALIVECNT variable. What is its 
16. Repeat step 15 several times and explain what is happening.

For your report, submit a printed copy of the assembled listing (.LST) file and
the .HEX file generated by MPLAB for the P1 program. Also submit written or 
printed copy of everything required in Part 3 of this lab exercise. This should 
include the answers to all questions.