Introduction.
Please note that this discussion is intended for people who have purchased our Olimex Serial ICD Package. It discusses the compatibility of the ICD with the Microchip $159 DV164001 Package, the capabilities and tradeoffs of using the ICD, connection of the Olimex ICD main board to the target and to the PC COM Port, configuring the MPLAB software and presents a simple example which is intended to familiarize the user with most capabilities of the Serial ICD.
Note that the figure numbers refer to the figures which were shipped with the ICD.
Compatibility
Note that the Olimex Serial ICD Package is functionally equivalent to the Microchip ICD (DV164001 and similar) except it does not include a Demo Board, nor a complex carrier board for the target PIC.. Rather, the intent of the Olimex ICD Package is to use a solder less breadboard or similar which provides a whole lot more flexibility in prototyping your designs.
Our approach is to interface the six conductor cable from the ICD main module and simply plug in 22 AWG solid wire leads which are connected to your target PIC on your solder less breadboard. In taking this approach, we eliminated the "header" or chip carrier which is a rather complex and costly mechanical design, but in fact does no more than hold your target chip along with two components; a resistor and diode. Note that in our approach, the series limiting resistor and anitireversing diode to protect the ICD is incorporated in the ICD module. The result in my mind is a much better design, with no compromises at a fraction of the price.
It is important to note that our package is fully functional and has exactly the same capabilities as the package marketed by Microchip. Thus, you can use the same MPLAB software and Microchip's documentation.
Documentation and Software
The documentation for the MPLAB ICD may be downloaded from the . Click on "Development Tools" and then on "In Circuit Debugger". Recognize that the only difference with our package is there is no "header" (chip carrier). Rather, simply connect the five leads from the Olimex ICD connector to the target PIC as illustrated in Figure #1 shipped with your unit.
[Note that there is a strap on the Olimex unit which should be set for "TAR". That is, the +5 VDC to power the Olimex ICD is provided by the target. Although there is a power connector on the Olimex unit, leave it unconnected].
I recommend you download the latest version of MPLAB which is compatible with the PIC16F87x family. Be sure to specify the modules for the "In Circuit Debugger".
Capabilities and Penalties of using the ICD
The Serial ICD permits you to debug your source code in real time. This includes the ability to set one breakpoint, to watch all special function registers, all RAM, and specified user variables.
This is really quite a step up for a hobbyist who has been using a "blow go" approach. Of course there are far more powerful and expensive emulators but my personal experience with emulators has been that I rarely use the additional capabilities. There is a theory that the more expensive the tool, the longer the development. Long about the time, I think I need a more sophisticated tool, I try to lean back and take a good hard look at my code. The most expensive emulator is no substitute for common sense.
The Olimex ICD may also be used as a programmer. Once you have debugged your design, use the ICD to program the target PIC in the "non-debug" mode, remove the ICD and add a pull up resistor to +5 VDC on the /MCLR PIC terminal. This is illustrated in the Figure #1 which was shipped with your unit.
The penalties are;
Note that in meeting some of these restrictions it is necessary to configure your compiler to indicate you are using the ICD. In the case of the CCS PCM C compiler this is accomplished with a statement;
#device PIC16F877 *=16 ICD=TRUEThis will cause the compiler to place a NOP at program location 0x000, reserve the six RAM locations and the 256 program memory locations.
Connecting to the ICD to the Target
Connect the five leads from the ICD connector to your PIC as illustrated in Figure #1. You might stabilze this witha cable tie.
A suggested physical layout on a Jameco JE25 solder less breadboard is presented in Figure #2.
Note that the ICD main module is powered via the red and black leads from the same +5 VDC source used to power your PIC and peripherals. The current drain of the ICD main module is nominally 70 mA. A suggested +5 VDC supply using a 7805 voltage regulator with a DC wall power transformer is presented in Figure #3. This may be used to power your PIC, the ICD and a good deal of peripheral circuitry.
When connecting the +5 VDC to the ICD exercise some care. Although there is a zener protection diode on the Olimex ICD main board it is long term protection against the accidental application of +12 VDC or reversing the polarity.
Thus, if you should detect that faint but tell-tale burning smell, quickly disconnect power and take a good hard look at your circuit.
When power is supplied to the ICD, an LED on the main MPLAB ICD module will continually flash. (When communication is established between the PC COM port and the ICD, this LED will stop flashing and remain turned on.)
Connecting the ICD to the PC
Connect the ICD main module to a PC COM port using the serial cable which is supplied.
Some notes.
Over the years I have sold thousands of devices that interface with a PC COM port and although most work, I occasionally receive messages of the form, "My PC is brand new, so I know the COM Port is working", and after several days, they conclude the COM Port is not working.
Thus, be sure your COM Port really is working and is not currently being used by another application. One easy test is to tie TxD to RxD and use HyperTerm, distributed with Windows, or other terminal emulator. Configure for a direct connection to the desired COM Port, 9600 baud with no flow control. Type a character, and verify it is being received.
The serial cable which is supplied with our ICD package consists of simply straight through connections. Note that many cables flip the TXD and RXD leads and these will not work with the ICD. If you happen to have a DB25 connector on your PC and use a DB9 to DB25 adaptor, be sure it is not NULL Modem adaptor.
Using the MPLAB Software
Launch MPLAB.
>From the "Tools" Menu, select "Development Mode" and then specify your target PIC and select the MPLAB ICD development mode. (When working with a new PC, I have found it best to first select the processor in the Editor mode and then repeat the process to select the development mode).
Note that if the MPLAB default for the COM Port differs from that which you are actually using, you may have to fiddle a bit before getting the ICD Window to appear. Then, from the ICD Window, select the appropriate COM Port and then Connect.
(When using the ICD, you may occasionally lose the connection and for some reason, not be able to reconnect. I often specify a non-existent COM port and then go back to the correct COM port which is a lot less frustrating than rebooting the PC).
>From the ICD Menu, select your clock speed.
From the ICD Menu, select "Options".
I usually configure as;
Device: PIC16F877 (or as appropriate)
Oscillator: XT (or as appropriate)
Watchdog Timer: OFF (at least for initial debugging)
Power Up Timer: ON
Brown Out: OFF
Low Voltage Prog: Disabled
Code Protect EE: OFF
Flash Memory Write: Memory Written to by EECON
Code Protection: OFF
Note that many of these will vary depending on your application. MPLAB has become quite good at snapping at you if you have set an option which is inconsistent with the use of the ICD as a debugger.
Most of the remainder of the "Options" menu is pretty intuitive. One point is to be sure to check the "Enable Debug Mode". When you are completed with the debugging effort, you may program the PIC in the non debug mode by not selecting this. Then remove the ICD from your breadboard and add a pull up resistor to +5 VDC on the /MCLR PIC input as illustrated in Figure #1.
Normal Program Development
Normally, you will use any of a number of compilers in conjunction with MPLAB to ultimately produce a .hex file which is downloaded to the PIC using the ICD. Although I use the PCW package's integrated development environment for initial development, I ultimately move to the MPLAB package for debugging and correcting errors. This involves installing a language tool, editing a project and compiling and possibly linking files. All of this is beyond the scope of this discussion.
Clearly, you will have to do this for the particular programming tools you are using, but at this juncture, I will simply note that the final end product is the .hex file. You then download the .hex file to the ICD and proceed to debug your design.
Debugging Using the ICD
In this discussion, I have sidestepped the issue of building a project by providing the source code for a C language program (ICD_TST.C) along with the supporting files which you may use to test the ICD and become familiar with its various features. Click Here to Download the C source and supporting files.
The source code for this test file appears at the end of this discussion. Note that the program configures PORTB.0 as an output and brings the output high and low five times followed by a three second delay. The timing was developed for a 4.0 MHz clock and will run correspondingly faster on your target if you are using an 8.0, 10.0 or 20 MHz clock.
Connect an LED (with an external 330 Ohm series limiting resistor) from PIC Output RB.0 to ground. Output RB0 is terminal 33 on a PIC16F877.
From the Main MPLAB Menu, select "File" and "Import" the file "icd_test.hex".
From the Main MPLAB Menu, select "File" and "Open" the file "icd_test.c".
From the ICD Window, "Program" the PIC. You should see various status messages, "Checking for Target", "Erasing", "Programming", "Set Debug Mode", "Reset" and finally "Waiting for User Command".
You may wish to simply run the program by clicking on the Green Light icon and verify that RB.0 (Terminal 33 on a PIC16F877) is indeed flashing five times with a pause. Click the Red Light icon the halt. Look at the source code and verify there is a bar at the point where the processor stopped.
From the MPLAB Main Menu, select "Window" and experiment with each of the various windows; "Program Memory", "Special Function Registers", and "File Registers" (RAM).
Set a break point at the location identified in the source code as "Break Point 1" by positioning the cursor on this line and right clicking the mouse. The line should turn red.
Click on the "Reset" icon and then run by clicking on the Green Light icon. The ICD should stop at the first executable line at or after the setting of the breakpoint. In this case, a break point was set at a call to delay_ms() and thus the processor will halt at the first executable line in the delay_ms() function.
View Window "Special Function Registers". Verify the least significant bit of TRISB is at "zero" and that the least significant bit of PORTB is at "one".
Set a breakpoint at the location identified as Break Point 2. View the "Special Function Registers" and verify the least significant bit of PORTB is now a zero.
From the "Windows", open a "New Watch Window". Note that all of the variables appear in the form of function.var_name. That is, flash.num_flashes and flash.n. Add each of these to the watch window and continue to click on the Green Light icon. The processor will halt each time it encounters the break point and you should see flash.n increment as it proceeds around the "for" loop.
Set a break point at the line identified as "Break Point 3" and click on the Green Light icon. Go to the watch window and locate variable delay_ms.t. Unlike the above which are bytes, delay_ms.t is two bytes. Thus, first, click on "Properties" and select "decimal", "16-bits", "low:high".
You may wish to "reset" and then "run". On encountering this break point, you should verify delay_ms.t as being 500.
Conclusion.
All of this has been very hard to write and of course, equally difficult to read. The best advice I can give is to "tinker" with it. There are many capabilities I haven't discussed.
But, if you have made it this far, you may agree with me that the ICD is the greatest thing since sliced bread. Go and do great things with it.
Program ICD_TEST.C
// ICD_TEST.C
//
// Continually flashes an LED on PORTB.0 in bursts of five flashes.
//
// This is intended as a demo routine in presenting the various features
// of the Serial In Circuit Debugger.
//
// Although this was written for a 4.0 MHz clock, the hex file may be used
// with a target processor having 8.0, 10.0 or 20.0 MHz clock. Note that
// the time delays will be 2, 2.5 and 5 times faster.
//
// copyright, Peter H. Anderson, Baltimore, MD, Nov 9, '00
//
#case
#device PIC16F877 *=16 ICD=TRUE
#include <defs_877.h>
void flash(byte num_flashes);
void delay_10us(byte t);
void delay_ms(long t);
void main(void)
{
while(1)
{
flash(5);
delay_ms(3000);
}
}
void flash(byte num_flashes)
{
byte n;
for (n=0; n<num_flashes; n++)
{
trisb0 = 0;
rb0 = 1;
delay_ms(500); // Break Point 1
rb0 = 0;
delay_ms(500); // Break Point 2
}
}
void delay_10us(byte t)
// provides delay of t * 10 usecs (4.0 MHz clock)
{
#asm
BCF STATUS, RP0
DELAY_10US_1:
CLRWDT
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ t, F
GOTO DELAY_10US_1
#endasm
}
void delay_ms(long t) // delays t millisecs (4.0 MHz clock)
{
do
{
delay_10us(100); // Break Point 3
} while(--t);
}