
TO WORD WRAP THIS TEXT:

Click Edit on this screen's above toolbar and then click on Word Wrap.

TK3 PIC CONFIGURATION NOTES - 22FEB03

Some of this information may update that given in the published EPE TK3 text.

Always check the Updates file for any information that affects these notes. It is normally issued whenever an update to TK3 is released and is accessible via the "Latest Updates" button at the bottom of the main TK3 screen.


Before any attempt at communication with the PIC is made from any function button, and if the Verifying option is in use (see Verifying notes viewable via the Check PCB button on the main screen), a check is made to determine if the printer port cable is connected and the PCB power is on. A message box appears if either of these conditions is false.

All PICs must have their in-built control features "configured" (the MPASM __CONFIG directive) to suit the use to which they are to be put. Such configurations include the settings for crystal or RC clock generators and various types of code protection. For full details see Microchip's data sheets specific to the PIC in question. The config value is held in the PIC at location H'2007'. 

TK3 allows all 14 configuration options to be selected individually (previous Toolkit versions prevented access to Code Protect bits). Whilst the PIC16F87x family requires that CP bits 13/12 are set to the same as CP bits 5/4, TK3 does not automatically enforce this, allowing a degree of "future-proofness" in the event that Microchip may not include this requirement with future PICs. The same principle applies to PIC16F87x config bit 10, which is currently "unavailable" according to Microchip, and control of this bit has been retained. 

Bits 0 to 4 are common to PIC16C84, PIC16F8x and PIC16F87x.

Bits 5 to 13 are not implemented for the PIC16C84 (read as 1), but are marked as CP (Code Protect) for the PIC16F8x devices. However, they seemed to have no effect with an 'F84, which still allowed the author's codes to be read back irrespective of the logic set for these pins. Only CP Bit 4 (CP0) was found to set/clear Code Protection for the 'F84.

Bit 3 for PIC16C84 has inverted POR logic (1=On, 0=Off) to the PIC16F8x and PIC16F87x devices (1=Off, 0=On).

Consult specific data sheets for more information on the Config settings for PIC16x8x, PIC16F87x and PIC16F62x devices, and for that of other 14-bit PIC families.

CONFIG SETTING

Before configuring a PIC, it is necessary to first ensure that the Config screen is set to the desired PIC Family (see the Select PIC Type notes). An on-screen option button allows direct access to Family selection, either PIC16F84 family or PIC16F87x family. Check data sheets for the Config bit logic for other devices not specifically catered for.

To configure a PIC click on the oscillator option required, confirmed by a dot appearing in its option window. To set or clear the other configuration bits click in their rectangular option boxes. The word On appears when the function is selected for the relevant PIC family (but see the above note for the 'C84), and the box's background colour changes from grey to green. Repeated clicking on the same box toggles between On and Off. You may also set the oscillator type via boxes 1 and 0 (RHS).

Under most programming circumstances, you will normally only need to use the Oscillator, POR and Watch Dog Timer buttons (and it is rare for the latter to be needed).

The actual code that will be sent to the PIC is shown in bit order in mid screen, with the oscillator selected confirmed to the right.

To send the configuration data click the Send PIC Config Data button. The code is immediately sent and a check is then made that it has been received. If the read-back code is different to that sent an error message box appears, giving details.

Clicking on the Read PIC Config Data button "interrogates" a PIC (via locations H'2000' to H'2008') to read how it has been previously configured, from which you can determine whether or not Code Protection has been applied. This information is shown in another selection of rectangular boxes which appears lower screen. If you click on Send Config while the readback code is still shown on screen, the Config code actually sent is that which you have previously set via the upper click-boxes. It is not possible to send the readback code to the PIC (unless you have copied its details into the click boxes). The readback boxes remain on screen until you click on Hide Readback, change the PIC type or resend config data.

Be aware that the PIC16C84 (note the "C") is differently manufactured to the PIC16F84 (note the "F") and cannot have its configuration settings accurately read back when Code Protection is On (see Microchip's data sheets). The C version, incidentally, is now out of production and the F version should be used in place of it. The latter accepts all code written for the C version and is a superior device (again see the data sheets).

It is recommended that only in exceptional circumstances, where it is imperative that other people can never gain access to your code, should Code Protection ever be set on.

Clicking on the Reset Config box resets all option boxes to the author's settings for the PIC family selected. However, the action does not actually send the data to the PIC, you must click the Send PIC Config Data button in order to send it.

Sending configuration data to a PIC does NOT erase all program codes held within it, unlike earlier versions of Toolkit. Nor does it erase the Eeprom data memory. Clearing of program and Eeprom data memory codes can be done using the Erase PIC button on the main screen, which takes you to a sub-window allowing choice of whether program or Eeprom memory is cleared. The Erase Program function uses an erasure code that reads back as a value of 63 when the PIC is disassembled to an ASM file. The Erase Eeprom function uses an erasure code that reads back as a value of 0 when the PIC is read back to an MSG file. Erasing the memory does not affect the PIC's Config settings.

Unlike its Toolkit Mk2 predecessor, TK3 also allows the Config value, when embodied in the HEX file, to be automatically sent when the main program code is sent.

ID LOCATIONS

TK3 allows you to also set a PIC's ID at locations H'2000' to H'2003' with values of your choice via the Set PIC ID sub-window. Microchip recommend that the four hex nibbles are set as 3F8x where x is the least significant nibble having a value between 0 and F. It is physically possible to set all four nibbles, but Microchip state that not all nibbles can be read back when some PICs have code protection set. Enter the full value as four hex digits with no spaces, and without prefix or suffix, e.g. 3F8A.

PIC locations H'2004', H'2005' and H'2008' are allocated as "Reserved" by Microchip, with H'2006' holding the Device ID for the PIC type. It is not known how Microchip intend these locations to be used, although TK3 does allow data to be sent to them if desired. H'2007' is the Config location which can also be programmed from the sub-window (code protection permitting).

PICs that are code protected can have their protection (CP) bits cleared using the Clear CP button. This resets the PIC's entire memory contents to all 1s, including program, Eeprom, ID (etc) and Config locations.

OBITUARIES UNLIKELY

Reports have been received at EPE stating that some PICs seem to become inaccessible under some (unknown) conditions of use. It seems that in such situations one or more Code Protect bits may have become erroneously set. If this happens to one of your PICs, try reconfiguring it with all Code Protect bits off, and then reprogram it with the required HEX or OBJ code. If this does not work and you are sure that you have not killed the PIC in some way, advise us at EPE of the circumstances under which the PIC originally failed, and of its type.

The only time that the author has had a PIC die was when it was inadvertently powered at 9V. He did have a "scare" with a 16F877, though, which appeared to have died, but it turned out that Low Voltage Programming (LVP) had accidentally been set On, and not noticed!

Another tale worth relating here is a caution about setting the Data Direction Registers for PORTE of a 16F877. It may seem natural at first sight to send a binary value of 11111111 (decimal 255) to TRISE if PORTE needs to be set for all three pins as inputs (RE0, RE1, RE2). On one occasion, the author spent considerable time examining why PORTD of two newly purchased 16F877s did not work as expected. On the verge of regarding them as dead, the data book was turned to in desparation - to be reminded that PORTD becomes a Parallel Slave Port (PSP) when TRISE bit 4 is set high, as it had on that occasion.

Frankly, the PIC16F87x family has so many (too many?) different functions for their pins, it is easy to overlook some crucial aspects and have doubts about the PIC's or the program's validity. Don't regard a PIC as dead until you have checked all aspects, including Configuration and Initialisation settings!

Another PIC problem tale is related in the Programming Notes (regarding a single bit dying).

ADDING OTHER PIC TYPES

If a PIC type is not included in TK3's list, it may be added as stated via the Select PIC Type screen.

ADDING YOUR OWN NOTES

These notes are displayed via an "Active" text editor and you may add your own notes to them, saving them to disk in the usual way.
