ICD vs. ICD 2






















  • Home

  • MPLAB

  • Contact Us

































  • Home

  • MPLAB

  • Contact Us















































































  • Home

  • MPLAB

  • Contact Us



























  • The original Microchip ICD and the newer ICD 2 perform similar functions, but they are NOT the same. The ICD was designed to be used with the 16F87x devices (only) and to be used in conjunction with MPLAB 5.xx (the current version at the time the ICD was introduced and, subsequently, up to and including v5.70.40). The ICD 2 was designed to be used with the 18 series devices (initially) under MPLAB 5.xx or 6.xx. Support for specific 12F and 16F series devices with ICD capability (including the 16F87x devices) was added very recently with the requirement that MPLAB 6.xx or subsequent be used. We will refer to MPLAB 6xx in this discussion meaning MPLAB or later (now 8.xx).

    The following ICD 2 information is designed for ICD 2 users who have a copy of Easy Debug'n (replaces pages 25 to 42) or Microcontrol'n Apps, Version 2.0 (replaces bottom half of page 407 and pages 411 to 428). This material is copyrighted and is included in Microcontrol'n Apps, Version 3.0. It is posted as a service to purchasers of our books and is not to be reproduced by anyone who does not own a copy of either book. This is our way of helping our readers stay up to date. We can't borrow their copies overnight, update them, and give them back the next morning. This is as close to that kind of service as we can get.

    MPLAB 6.xx instructions are also available to purchasers of our books on this web site on the same basis.

    MICROCHIP ICD 2

    Description The newer Microchip in-circuit debugger (ICD 2) consists of software which runs on a PC (included in MPLAB 6.xx) and hardware which looks like a colorful hockey puck.


    With the ICD 2, you can step through assembly source code on-screen while observing what the hardware is (or is not) doing. You can select registers to watch (view) by their labels (names) as you step through the program. You can set a breakpoint (place to stop program execution) and run the program at normal speed and exercise the hardware up to that breakpoint. Then you can look at the contents of the registers of your choosing.

    The unit has a USB connector for serial communication with a host PC and a 6-conductor modular phone jack for communication with a flash PIC microcontroller. The PIC microcontroller resides on a so-called "target" board which is the user's (your) board.

    Microchip strongly recommends using USB and NOT the RS-232 connection which is built into the ICD 2 for communications between the host PC and the ICD 2.

    Following the current version of the Microchip USB Port Setup instructions is a MUST. Refer to the "Readme for MPLAB ICD 2" contained in the Readmes folder in the MPLAB 6.xx folder.

    I recommend purchasing the ICD 2 Simple Suite version (DV164005) plus a power supply (transformer)(AC162039) or you can purchase the full kit with power supply (DV164007) and store the RS-232 serial cable somewhere.

    The ICD 2 can operate in two operating modes:

  • Debugger mode
  • Programmer mode

    In both the debugger and programmer operating modes, the user code is programmed into the PIC microcontroller. In the debugger mode, the PIC debugger code used by the ICD 2 is also programmed into program memory locations reserved for the purpose.

    To say it another way, in the programmer mode, only your code is programmed into the device for stand alone (without the ICD 2 connected) operation.

    The ICD 2 can operate in two hardware configurations:

  • Debugger/programmer for working with flash devices with in-circuit debugging capability. The PIC microcontroller resides on the user's application board called the "target" board. The PIC microcontroller may be programmed for testing and debugging (debugger mode) or programmed for stand alone operation (programmer mode).
  • Device programmer for programming flash devices with in-circuit debugging capability. Microchip offers a universal programming module (UPM would you believe!)(PN AC162049) which connects to the 6-conductor modular cable. It has a 40-pin zero insertion force (ZIF) socket. The ICD 2/UPM combination allows users to program devices in a ZIF socket rather than on a target (user) board.

    For debugging low pin count devices, interface boards are required:

  • 8-pin devices 8-pin header interface board (AC162050) required
  • 14-pin devices 14-pin header interface board (AC162052) required

    We will discuss only the debugger/programmer configuration using 18-pin or larger 16F devices.

    MPLAB 6.xx is required for use:

  • With the ICD 2 and 12F and 16F devices (MPLAB 5.xx will not work).
  • With USB connection to host PC.

    MPLAB 6.xx instructions are available on our web site.

    Selecting the best options for powering the ICD 2 and the target are critical. Based on my experience and that of others, I recommend powering the ICD 2 using Microchip's wall transformer power supply and NOT via the USB port. I also recommend powering the target (your circuit) with your own power supply.

    Review:

    After some experience and help with problems from Microchip tech support, I have reached the following conclusions:

  • You will need a PC with a USB port. Forget about using an RS-232 serial port.
  • Use MPLAB v6.xx with the ICD 2. This is required for USB and for using the 12F and 16F devices.
  • Power the ICD 2 with a Microchip wall transformer power supply, not from the USB port.
  • Power your circuit (target board) with your own power supply, not from the ICD 2.

    This will eliminate some hassles and frying of brain cells.

    USER BOARD = TARGET BOARD

    The 87s board described earlier is set up to be used with the ICD 2. You can easily set up your own board in a similar way by providing the modular phone jack and using the 47 K pull-up resistor on _MCLR (reset).

    ICD 2, 87s Board, and 87s Companion Board

    USING THE MICROCHIP ICD 2 - PIC F870 AS EXAMPLE

    GENERAL CONSIDERATIONS

    When Microchip's ICD 2 is employed, the following F870 resources are utilized by the ICD 2:

  • The _MCLR/Vpp pin is used for programming.
  • Port B bits 6 and 7 are used for ICD 2 serial communication with the F870.
  • Lose 2 stack levels when ICD 2 is used.
  • Address 0x0000 in program memory must contain NOP instruction.
  • File registers used by the ICD 2:
      0x70, 0xB5 - 0xBF, 0xF0, 0x170, 0x1B5 - 0x1BF,0x1F0
  • Program memory locations used by ICD 2:
      0x0700 - 0x07FF

    In MPLAB, use Help>MPLAB Help ICD 2 to determine what file register and program memory resources are used by the ICD 2 for the specific device you will be using.

    For porting F84 applications to the F870 where the F870 will be programmed by the ICD 2, the following must be done:

  • Move start of general purpose file registers from 0x0C to 0x20
  • Configuration bits:
        - LVP disabled, RB3 is digital I/O
        - DEBUG enabled (ICD 2 mode enabled).
  • A/D does not exist on the F84, so ADCON1 must be written to during initialization to disable A/D on pins RA0, 1, 2, 3, and 5. Writing 0x06 to the ADCON1 register at address 0x9F (bank 1) will do the trick.
  • Cannot use port B bits 6 and 7 (used by ICD 2).
  • Lose 2 stack levels when ICD 2 is used.
  • Address 0x0000 in program memory must contain NOP instruction.
  • File registers and program memory locations listed above must not be used by your program.

    FIRST PROJECT

    For our first ICD 2 project, we will modify pict1.asm from Easy PIC'n or Easy Microcontrol'n. It will be necessary to turn off the A/D converters on port A and move the 8 LEDs to port C as only 6 lines are available to us on port B.

    First F870 Program For Use With The ICD 2

    We will modify the example program designated pict1.asm which simply writes a bit pattern to the eight port B pins which are connected to 8 LEDs.

    ;=======PICT1.ASM===========================10/14/97==
            list    p=16F84a
    	__config   h'3ff1'
            radix   hex
    ;-----------------------------------------------------
    ;       cpu equates (memory map)
    portb   equ     0x06
    ;-----------------------------------------------------
            org     0x000
    ;
    start   movlw   0x00    ;load W with 0x00
            tris    portb   ;copy W tristate, port B
    ;                          outputs
            movlw   0x0f    ;load W with 0x0F
            movwf   portb   ;load port B with contents
    ;                           of W
    circle  goto    circle  ;done
    ;
            end
    ;-----------------------------------------------------
    ;at device program time, select:
    ;       code protection off
    ;       watchdog timer disabled (default is enabled)
    ;       standard crystal XT (using 4 MHz osc for test)
    ;       power-up timer on
    ;=======================================================

    Not all of the 8 bits of port B are available for your use as RB7 and RB6 are used by the ICD 2. We will use port C instead.

    With the F870 , we can ignore a lot of the fancies, but we cannot ignore the A/D converters and must turn them off if they are not to be used. In order to do that, we must use file register bank switching in order to reach the A/D control register ADCON1 which resides in bank 1. To do this, we will need to add the address of the ADCON1 register to the equates. Since we have to use bank switching to write to the ADCON1 register, we might as well add equates for the TRISA, TRISB and TRISC registers and write to them directly instead of using the TRIS instruction.

    Type the following example in MPLAB (or copy and paste it). 

    ;=======2ICD1.ASM===========================4/25/03==
            list	p=16f870
            __config   h'3731'
            radix	hex
    ;----------------------------------------------------
    ;       cpu equates (memory map)
    status	equ	0x03
    porta	equ	0x05
    portb	equ	0x06
    portc	equ	0x07
    trisa	equ	0x85
    trisb	equ	0x86
    trisc	equ	0x87
    adcon1	equ	0x9f
    ;----------------------------------------------------
    ;	bit equates
    rp0	equ	5
    ;----------------------------------------------------
    	org   	0x000
    	nop
    start	bsf	status,rp0	;switch to bank 1
    	movlw	b'00000110'	;turn off A/D, port A
    	movwf	adcon1
    	movlw	b'00000000'	;inputs/outputs
    	movwf	trisa
    	movwf	trisb
    	movwf	trisc
    	bcf	status,rp0	;back to bank 0
    	movlw	0x0f		;load w with bit pattern
    	movwf	portc		;load port C with contents of W
    circle	goto	circle		;done
    ;
    	end
    ;-----------------------------------------------------
    ;at device debugging time, select:
    ;	memory unprotected
    ;	watchdog timer disabled (default is enabled)
    ;	standard crystal (using 4 MHz osc for test) XT
    ;	power-up timer on
    ;	brown-out reset disabled
    ;	lvp disabled
    ;	debug mode enabled
    ;=====================================================

    Put it in the same directory/folder as MPLAB. Call it 2icd1.asm. Create a new project called 2icd1.pjt using the MPLAB instructions available on this web site.

    Assemble (Project>Make Project) 2icd1.asm to create the .hex file 2icd1.hex.

    Note the following:

  • NOP instruction at beginning.
  • The __CONFIG assembler directive is included.
  • When using the ICD 2 (as opposed to a device programmer), brown-out reset is disabled and debug mode must be enabled.

    Since bits 7 and 6 of port B are used by the ICD 2 for communication with the host PC, we are left with 6 of the 8 port B lines for our applications. When writing your application code, it is alright to use instructions which write to all 8 bits of port B and TRISB. The MPLAB ICD 2 takes care of the house keeping so that ICD 2 communications on bits 7 and 6 are not affected by these instructions.

    MPLAB OPERATIONS

    Setting Up The ICD 2

    Connect the ICD 2 to your PC and power as shown.

    Connect the ICD 2 to your 87s board using a short 6-conductor modular phone cable. Connect your 87s board to a suitable +5 volt DC power supply.

    When powering-up the ICD 2 and target board the first time or for use with a new project, use the following procedure:

    1. At start-up, NO power should be applied to the 87s board.
    2. Power-up the host PC.
    3. Power the ICD 2 . The green "Power" LED in the ICD 2 should be on.
    4. Start MPLAB. Close the Untitled Workspace. At this point, it is assumed that you have a .hex file suitable to be programmed into the F870 on your 87s board. Remember to put in the NOP instruction at 0x000.
    5. Select ICD 2 as the debugger to be used. Debugger>Select Tool>MPLAB ICD 2
    6. Click OK in the Invalid Device warning dialog box.
    7. The Output window will indicate that the ICD 2 self test failed. Ignore the message.
    8. Close the output window.
    9. Select Debugger>Settings.
    10. The ICD Debugger dialog box will open. Click the Power tab and ensure that the check box for "Power target circuit from ICD 2" is NOT checked. Click OK.
    11. With the F870 in the ZIF socket, power-up your 87s board.
    12. Open the output window. View>Output.
    13. Select Debugger>Connect.
    14. Observe the activity in the output window. On completion, the last text line should read "MPLAB ICD 2 Ready".
    15. You should now be able to debug and erase the F870 on your 87s board.

    Close the output window.

    Reverse the procedure to power-down (87s off, ICD 2 off, PC off).

    Open your project (2icd1.pjt.mcp in this case).

    To check status, use Window>Output.

    To get back to the assembly source file window, use Window>MPLAB\2icd1.asm. The __config directive followed by h'3731' included in the source code makes the following selections:

  • Oscillator type XT.
  • Watchdog timer off/disable.
  • Power-up timer on/enabled.
  • Brown out detect off/disabled (must).
  • LVP disabled (must).
  • Flash memory write enabled.
  • Background debug enabled.
  • Data EE read protect off.
  • Code protection off.

    Be sure that debug mode is enabled.

    Configure>Configuration Bits.

    Then close the configuration bits window and go back to the assembly source code window.

    Window>MPLAB\2icd1.asm.

    At this stage, it is convenient to have the configuration word set up the microcontroller for debugging because each time you reassemble your code, the configuration word will override any selections you change using the Configure>Configuration Bits window. More specifically, if the configuration word in the source code were h'3f31' (background debug disabled for stand alone operation), it would be necessary to manually change from debug disabled to debug enabled each time the code is reassembled.

    Click on Debugger>Program to program the F870. The ICD 2 will put the debug code in the F870, program your code into the F870, and put the debug code used by the ICD 2 in the F870.

    Stuff happens. Window>Output to check programming status. When programming is complete, "Programming succeeded" will appear in the MPLAB ICD 2 output window followed by "MPLAB ICD 2 Ready".

    Note that each time your code is changed, it is necessary to reprogram the chip as described above. A dialog box will pop up to remind you.

    Select Window>MPLABxx.2icd1.asm and go back to the assembly source code window.

    Toolbar

    To debug programs using MPLAB ICD 2, we will use four buttons on the debug toolbar at the top of the MPLAB window. You can discover the rest by "hacking" as the need or curiosity arises!

    Click on the run button on the toolbar.

    Hex 0x0F should now be displayed at the port C LEDs.

    To Halt The F870 Via The Toolbar

    Click on the halt button on the toolbar.

    The first line of code after the NOP instruction will have a yellow arrow pointing to it.

    To Reset The F870 Via The Toolbar

    Halt first. Then click on the reset processor button on the toolbar.

    The first line of code after the NOP instruction will have a yellow arrow pointing to it.

    Watch Window

    To create a watch window:

    View>Watch.

    A Watch window called "Watch 1" appears. "Watch 1" is indicated by the highlighted button in the lower left hand corner of the screen.

    Special function registers (SFR) may be selected for viewing. Scroll up and down the menu and select the registers you would like to watch as your program executes.

    In this case, select W by highlighting WREG. Click on the Add SFR button.

    General purpose registers you are using may also be selected for viewing.

    Scroll up and down the Add Symbol menu and select the general purpose registers you would like to watch as your program executes.

    In this case, select port C by highlighting portc. Click on the Add Symbol button.

    The menus are made up from two sources. One is a standard list of special function registers for the device you are using contained in MPLAB. The list is narrowed down to the ones you are actually using in your application. The other is the general purpose registers identified in the equates in your source code.

    The watch window Watch 1 is now on-screen almost ready for use.

    I find it helpful to have the contents of a port displayed in binary. Let's customize (edit) Watch 1. Right click on the value for Port C in Watch 1.

    A drop-down list appears.

    Click on Properties.

    The Watch dialog box appears. The symbol "portc" is already selected under the Watch Properties tab.

    Under Format, select Binary.

    Click on Apply.

    Close the Watch dialog box.

    The watch window now displays the contents of the W register in binary.

    To delete a register from a watch window, highlight the register's symbol name in the watch window. Press the right mouse button. A drop-down list will appear. Click on Delete.

    Notice that clicking on Window (menu bar) shows that "Watch" is checked.

    If you close this watch window and then want to open it later, use View>Watch.

    If the project is saved, the watch window will be saved as part of the project.

    Watch windows may be saved as a file. Click the right mouse button in the window to open a menu. Select Save Watch to save the the currently selected watch window to a file.

    To delete a watch window, the file must be deleted using the usual Windows file management procedure.

    Single Stepping

    Reset the processor via the toolbar icon. Notice that the first line of your program (not counting NOP) is highlighted. The processor is stopped at the point where the highlighted line is the one about to be executed. Click on the single step button on the toolbar.
    The next instruction is executed. Notice that some time is required for communication between the PC and the F870 to fetch the contents of the selected F870 registers for display. You can single step your way through 2icd1.asm to the instruction labeled "circle". Observe the changes of the contents of the W register and port C in the watch window.

    As you single stepped through the code the first time, the LEDs were all off until movwf portc was executed. Now step through the second time. Four of the LEDs will come on after movwf trisc is executed (sooner than the first trip through). The reason is that the contents of the port C register is 0x00 after reset and remains so until some other data is written to it. Writing to the TRISC register to make port C outputs results in the contents of the port C register being output immediately. On the first trip through the code, the contents is 0x00. On the second trip through the code, the contents is 0x0F.

    If you want to play with this, add the following line of code and move the "start" label.

    	org 0x000
    	nop
    start	clrf		portc	;LEDs off
    bsf	status,rp0		;switch to bank 1
    etc.

    Test for results.

    To quit single-stepping, click on the reset button in the toolbar.

    Break Point

    Break On Address Match

    One breakpoint may be set. The processor breaks after executing the instruction stored at that address.

    To set a breakpoint on address match:

    Halt the F870 and reset it using the buttons on the toolbar.

    Place the I-beam (I) cursor on the last line of code you want executed.

    Click the right mouse button.

    A dialog box will appear.

    Select Set Break Point.

    The line of code selected will now have a red "B" next to it in the left margin.

    Click the toolbar run button to run to the breakpoint.

    The F870 will stop at the address you selected and the line of code will have a yellow arrow next to it.

    Clear Breakpoint

    Debugger>Breakpoints.

    A dialog box appears.

    Select Breakpoint.

    Click Remove.

    Click OK.

    After code execution stops at a breakpoint, you may single step forward from there.

    Powering Down

    The power-down sequence is the reverse of the power-up sequence

  • Turn off power to the target board.
  • Power-down the ICD.
  • Turn off power to the host computer.

    Starting Up - Opening An Existing Project

    When powering-up the ICD 2 and target board, use the following procedure:

    1. At start-up, NO power should be applied to the 87s board.
    2. Power-up the PC.
    3. Power the ICD 2 . The green "Power" LED in the ICD 2 should be on.
    4. With the PIC microcontroller in the ZIF socket, power-up your 87s board.
    5. Start MPLAB, close the untitled workspace, and open your project.
    6. The output window will be open for a short time. If all is well, "MPLAB ICD 2 Ready" will be displayed just before the output window closes (on it's own).

    The ICD 2 selections will be the ones you made the last time the project was saved.

    You are now ready to go to work.

    Operating 87s Board Stand Alone After Debug'n

    During the debugging process, background debugging is enabled via one of the configuration bits. This causes code to be written into the program memory space used by the debugger which tells the F870 to look for the debugger on reset. When operating the microcontroller stand alone, the debugger will not be found and your program will not be executed. To get around this, you will need to:

  • Debugger>Select Tool>None
  • Programmer> Select Programmer>MPLAB ICD 2 (programmer mode).
  • Configure>Configuration Bits. Background debug enabled is shown *.
  • Click on "Enabled" and change the selection to "Disabled" *.
  • Reprogram the F870. Programmer>Program.
  • Open (select) the Output window to check programming status. Look for ... Programming Succeeded".

    * Sometimes this change is made for you when changing tools from debugger to programmer. Sometimes it is not (!).

    Since port lines RB7 and RB6 will not be used by the ICD 2 when the 87s board is operated in stand alone mode, you may want to connect them to pullup resistors.

    Reconnecting The ICD 2 After 87s Board Stand Alone Operation

    To reconnect the ICD 2 to do more debugging or test the hot new feature you now want to add to your project, you will need to reverse the procedure outlined above:

  • Programmer>Select Programmer>None
  • Debugger>Select Tool>MPLAB ICD 2 (debugger mode).
  • Configure>Configuration Bits. Background debug disabled is shown *.
  • Click on "Disabled" and change the selection to "Enabled" *.
  • Proceed with debugging.

    * Sometimes this change is made for you when changing tools from programmer to debugger. Sometimes it is not (!).

    Since port lines RB7 and RB6 will be used by the ICD 2, remember to remove the pullup resistors (if any).

    Conclusion

    You will find that, when using MPLAB, the sequence or selection of dialog boxes that come up and the selections made in them are somewhat dependent on what you did last, perhaps going back to a project you did last month. Also, Microchip likes to make software changes. Be prepared to hack a little!

    If you have questions, contact us by eMail at sqone@pacific.net

     [Home]  [MPLAB]   [Contact US ]

       [TOP OF PAGE]


    (c) Copyright 1996-2016 Square 1 Electronics, last updated April 14, 2016