Contents

 
Introduction

 
New Project

 
Compiling Project

 
Communication Links


Editing the
Source File

 
Programming
the Target

 
Debugging Programs

 
Printing Variables

 
About the Author

 
Contact the Author
MPLAB-ICD Operating Instructions
 for

Compiling, Programming and
Debugging 'C' Programs

by


Harvey
Twyman

Introduction

The MPLAB-ICD system is a combination of:
    • Hardware
    • Software


    Hardware
     

      The hardware consists of a PIC16F877 Microprocessor which contains special firmware that communicates with the ICD pod and software in the PC to enable device programming and program debugging.


    Software
     

      The MPLAB software runs on the PC and communicates with your target PIC via its ICD pod. The software isn't very intuitive so the remainder of this web page discusses how to set up and use it successfully.


    The following procedures MUST be carried out in sequence in order to work correctly.


Creating a New Project
The following steps for creating a new project are only required ONCE as all this information is saved within the .PJT Project File.
    • Select Main Menu:Project
      • Select:Install Language Tool
      • Select:HI-TECH in the Language Suite Box
      • Browse to: C:/HT-PIC/BIN/PICC.EXE
      • Click OK

      •  
    • Select Main Menu:Project
      • Select: New Project
      • Select a working folder on one of your Remote Drives
      • Enter: Name (No More than 8 Characters for DOS Compatability)
        with the Extension PJT. This MUST be the SAME NAME as the C Source file you intend using.


    • Select Menu: Options/Development Mode
      • Select MPLAB-ICD Debugger
      • Select Change
      • Select Processor: PIC16F877
      • Click OK

    The Edit Project Box should now appear.
     
    • Select HI-TECH in the Language Tool Suite Box
    • Click ONCE on the .HEX File in the Project Files Section
    • Click Node Properties
    The Node Properties Box should now appear.

    MPLAB needs to know about the whereabouts of the 'C' Source File:
     

    • Select Node Properties
      • Click on Generate Debug Info
      • Enter the word Microchip in the box where the Cursor is Pointing
      • Enter the string -icd in the Additional Command Line Options Box
      • Click OK

    Now Add Node  should now appear.
     
    • Select Add Node
      • Select your C-Source File ( This MUST be the SAME as the Project Name

      • used above but with a'.C' Extension ) from your Own Remote Folder
      • Click OK Twice

    Now Save the Project:
      • Select Main Menu: Project
      • Select Save Project

Compiling a Project

    • Select Main Menu: Project
      • Select Make Project or F10

      •  
    Check for the message: Build Completed Successfully appears. Any compiler errors MUST be corrected before continuing.

Starting the Communication Link to the Target PIC Hardware

      The Dialog Box should look like this:


    ICD Window

       
      • Click Reconnect
        • The LED on the MPLAB-ICD's Hardware Pod should stop flashing and remain on.

      • If it does then communication with the target was successful and the EstComm message should appear on the Status Line.

      •  
      • If it fails then a message saying something like MPLAB-ICD Cannot Establish Communication will appear.

      •  
        • CHECK the connection and power to the Target Hardware as this also supplies power to the ICD Pod Hardware.

        •  
      • Click Options

      •  
        • This Dialog Box above is the Actual Task that communicates with the Target Hardware so the box can be Minimised but NOT CLOSED as this breaks communication and you will need to repeat this section again to re-establish communication.
      For successful operation the Dialog Box Options has to have all the correct ones ticked. Compare the image below with yours...


ICD Options

Note these:
    • Watchdog Timer
    • Power Up Timer
    • Brown out Detect
    • Low Voltage Disable

    MUST be either OFF or DISABLED
Also the Enable Debug Mode MUST be Ticked.

Editing the C-Source File

  • Select: File/Open
  • Select: C Source File
  • Click OK
The editor looks a lot like "NotePad" but has several relevant features:
    • Match Braces
      • Place the cursor JUST BEFORE a curly bracket
      • Type either CTRL-B or select Match Braces from the Edit Menu
      • The editor with then move the cursor to indicate the matching curly bracket

Programming the Target Device

The Program Button in the Dialog Box will transfer the compiled program setup in the project to the Target Device. The Status Window of the Dialog Box displays progress.
The PC is Inoperative During This Time - You Just Have to WAIT for it to Finish!

Running and Debugging Programs

Running and Debugging options are within the Main Menus: Debug and Debug/Run
Observe the Function Key Shortcuts as they make the system much quicker to use.
When running a program (Shortcut: F9) the Status Bar at the bottom of the MPLAB's screen turns YELLOW.

Printing Variables

One of the simplest ways of debugging is to print variables. This involves inserting a statement into your program to display the information you require when the program runs.
In 'C' this would involve adding a line e.g.:

printf("Variable time = %x",time);

The Time Variable will be displayed as a Hex Number (%x operator)

BEWARE the printf statement takes a considerable amount of the CPU's Program Memory. Therefore it may be impossible to use when your program gets large.

The alternative is to use the:

putch(time);

which takes up very little memory.

The question you may now be asking is what will the variable be displayed on?

If your hardware has a Liquid Crystal Display then it could be displayed there but if it hasn't, then where?

The answer is to use the PIC's USART Serial Port and to connect it via an RS232 Interface to a PC's Comms Port.

The information can then be viewed via a seperate window using the the HyperTerminal Program.

An extra #include statement is required at the top of the program when any I/O function like this is used:

#include "c:\ht-pic\include\stdio.h"


Compiling Programs using printf and putch Statements

The PIC Microcontroller needs its USART Interface initialising BEFORE the putch and getch functions will operate.

Once set up the higher level fuctions that call these can then be used.

These include:

    • the printf statement
      • uses putch to transmit individual characters on its serial port.

    • the scanf statement
      • uses getch to receive individual characters on its serial port. 
 Contact the Author for full details of the program code required.