Student use of Mplab-ICD from the Morse Teaching Center Computers 10/17/00 EWJ

 Return to Main Robot Page

Mplab-ICD is an integrated development platform for Editing, Compiling, Programming, and Debuging the Microchip PIC16F877 microcontroller. This controller is used in the EE350/201 robot platforms.

Note: When programming and debugging the robot always make sure the robot wheels are elevated off of the bench.

Microchip MPLAB-ICD.PDF development system manual

Running Mplab-ICD:

    1. Setup- Connect the ICD interface box to the +5V DC power supply and the 9 pin serial cable. Note: The red LED inside the box should be blinking.
    2. Click on desktop shortcut to Mplab
    3. If the prompt to open project appears select NO
    4. Select "Project" then "Open Project" then "EE201" or "EE350" finally select "P201.PJT" or "P350.PJT"
    5. Using "files" Open the C source code program to work on. In this case hello.c. (See changing source code below)
    6. Select make project. Software should prompt in build status window that Target is current. This means the source file has not changed from the last time the project was compiled.
    7. In Mplab-ICD window click on Options. Note in new menu Enable Debug mode box. If this box is checked then the robot or target system will not operate on its own but in a debug mode with the host computer. For now make sure the box is not checked.
    8. ICD options window settings (For reference only):

Device

PIC 16F877

Oscillator

HS

Watchdog timer

Off/Disable

Power Up timer

Off/Disable

Brownout detect

Off/Disable

Low Voltage Program

Disable

Code Protect data EE

Code Protection Off

Flash Memory Write

Memory written to by EE rom

 

 

Connect robot to PC as shown:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Download program:

  1. Connect the telephone type connector to the robot jack. Turn the robot power on.
  2. Click on the Program button in the Mplab-ICD window.
  3. Monitor the Status line in the Mplab-ICD window. When it indicates "Program ID / Pass" then the robot is ready. If it indicates " Waiting user command" then the Debug box discussed above is checked. If this is the case then make the box blank and click on Program again.
  4. Remove the telephone style cable to the robot and the program should start to run indicating the word "Hello" on the LCD display. (If the program does not automatically start then press the reset button on the robot.)

Changing the source program:

  1. Edit the word "Hello" in the hello.c file.
  2. To save this as a new source file, click on source code (program) window then click on file, save as, "????.c" Where ???? is any file name you want to use.
  3. Click on Project, Edit Project
  4. Click on hello.c
  5. Click on delete node
  6. Click on add node
  7. Select new file (The one you just saved) Click "OK" to register change.
  8. Click on project then Make project.
  9. The build status window indicates if any problems occur.
  10. You can then test your code by downloading as indicated above.
  11. This is how a new or modified source file can be used with your project. In this way you can keep the same project name but just update the source files and edit the project as you move along in development.

Saving your "C" code:

  1. Save all versions of your C code to a floppy disk or to your pantheon account.
  2. Once you have left the computer workstation your programs will be lost.

Running in Debug Mode:

Note: When using the debug mode the robot will not run on its own, it must be connected to the telephone style connector.

  1. Check the debug box in the Mplab-ICD options window.
  2. Download the program to the robot.
  3. Click on debug, run. The lower bar on the screen should change to yellow when the code is running.
  4. To stop the program click debug, halt. The program stops where it is.
  5. To reset the program click debug, reset. The program returns to power on reset and stops.

Break Points:

  1. Break points are places where you can make the code stop. To set a break point click on Debug, Break settings.
  2. Click on Start and a list of functions and labels from your source code will appear. Any of these can be designated as a break point. Or you can modify your source code to put a break point where you want by placing a label there. A label can be any text followed by ":" If you create a new label in your code then you must do a new make. After the source is compiled the label should appear in the start list under break points. When this label is selected as a break point the program will run until that point is reached then stop.
  3. Break points can be enabled and disabled with the debug, break settings window.

Watch Windows:

  1. Watch windows are used to monitor the value at a particular location such as a variable. When used with break points they are a usefully tool to help in determining why a program is behaving in a certain way.
  2. For example a break point could be set in a loop with a watch window looking at a variable in the loop. At the first break the initial state of the variable is displayed. Then by using the step function in the debug menu you can single step through the code and watch the variable change.
  3. Watch windows can be saved to your project and recalled.

 

After the debug mode is used to solve a problem with your program, you must clear the debug box and re-download the program to the robot. Then you can remove the telephone style connector and go test your robot.