                 PIC84PGM Version 1.08b by Nigel Goodwin 1996

This software is copyright Nigel Goodwin 1996, but may be freely distributed
for non-commercial use. It may not be distributed on BBS's that charge via
premium-rate phone numbers, or on charged for PD/Shareware disks without
first obtaining permission.
I may be contacted via the Internet as 'nigelg@lpilsley.demon.co.uk'.

PIC84PGM is software for programming the MicroChip PIC 16C84 microcontroller
using serial programmers based on the design by David Tait. The software
was written using Turbo Pascal 7.0, and was particularly written for the
Don McKenzie variant of the programmer, as such it includes built-in
defaults for the Don McKenzie board. The printer port is now detected
automatically on startup, for this to work you MUST have the hardware
plugged-in and powered-up. If you wish to use an alternative programmer
design, you may use a configuration file called 'PICPROG.CFG'. Three samples
are included, one for the Don McKenzie board, and two for the variants of the
original David Tait design. If you rename either of these files to
'PICPROG.CFG', the program will use those settings instead.

Using the program.

When the program is run, you will be confronted by the main screen. At the
top is a display of the various configuration settings, the bottom line
is used for messages, and the main part displays a simple menu.

Menu options.

H) As of this version, this option now pops up a file requester window,
   this window lists only the files ending in '.HEX'. All you need to do
   is move the cursor over the required filename and press Return. If you
   should not wish to load a file, pressing Esc will abort the load and
   return to the main menu. The rest of the requester allows you to move
   directories, or change to a different disk, in the usual MSDOS way.
   Once a filename has been selected the file will be loaded, and the
   configuration display updated accordingly. The file should be of INHX8M
   format, as created by the current MPASM assembler, and may include
   program, data, ID settings, and fuse settings. Any such settings will
   override the normal defaults.

   To include EEPROM data in the HEX file, use the following type of code:

   ORG 2100h  ;Set EEPROM data
   DATA 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
   DATA 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
   DATA 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17
   DATA 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
   DATA 'N','i','g','e','l'

   To include ID and fuse information, use the following code example,
   the assembler will generate a warning, but assembles OK.

   ORG 2000h  ;Set ID locations
   DATA  0x00, 0x01, 0x02, 0x03

   ORG 2007h  ;Set config fuses
   DATA 0x03

O) Due to popular demand (Don McKenzie!), I've added an option to load
   '.OBJ' files created by the older assemblers and the Parallax assembler.
   This works in exactly the same way as H), but only displays files
   ending in '.OBJ'.

P) This option programs the target PIC with the loaded code, it only
   programs the required area of the PIC, this makes it nice and fast.
   If you have no program, data, or ID's loaded, this option will now
   update only the configuration fuses. This allows you to alter the
   fuse settings and write them to the target PIC.

V) Fairly obvious, this verifys the loaded program and data against the
   target PIC. Option 'P' calls this option automatically after programming
   the target chip.

R) This option reads all data from the chip, Program, EEPROM data, ID's,
   and configuration fuses. The configuration display is updated as
   required, and the data from the PIC can be displayed using the next
   options.

S) This now shows the data buffer first, and then prompts to see if you
   wish to view the program buffer, answer 'Y' or 'N' to chose.

   [Data Buffer]
   Displays the EEPROM data, ID's, and configuration settings. Hit any key
   except 'Y' to return to main menu. If there is no EEPROM data loaded,
   only the ID and fuse settings are displayed.

   [Program Buffer]
   Right, this displays the program memory as a hex dump in 256 byte pages,
   to change pages use cursor up and down. To return to the main menu,
   press ESC. If no program is loaded, return to the main menu is instant.


Alt-W) Pressing this toggles the Watchdog Timer on or off.

Alt-P) This toggles the Powerup Timer on or off.

Alt-C) And this one toggles the Code Protection on or off.

Alt-O) This toggles the Oscillator type, keep pressing until the desired
       oscillator type is reached.

W) This prompts you for a filename and saves the program data to disk as
   an INHX8M file. If there is EEPROM data or ID settings present, this
   will be saved to the file as well. Configuration fuse settings are
   always saved. This allows the file to be reloaded and all settings to
   be restored to their previous state.

D) This option invokes a 16C84 disassembler, it then displays the resulting
   code on the screen. It may be moved through using the cursor up/down
   keys, Page Up/Down keys, and Home/End. To quit the display routine, hit
   ESC as usual, you are then asked if you wish to save the source code. If
   you answer 'Y', you are then prompted for the filename, if this name
   already exists, you are offered the choice to overwrite it or not. As
   of this version all used areas of the PIC are disassembled and can be
   saved to disk. Please remember, the MPASM assembler will generate
   'address error' warnings when compiling this sort of code - it does
   however compile it without any problems.

E) Recently added, this option just blanks the target 16C84.

C) Used to clear the programmer buffers, prompts to make sure you really
   want to do this.

A) Latest addition, displays brief details, and a help line or two.

Q) Quits the program, all data in buffers is lost.

COMMAND LINE OPTIONS:
  The current version now accepts a number of command line options, if
  the program is started with just the program name it runs the main menu
  as before.

  If you use '/D' or '-D' as a command line switch, this turns on a
  debugging mode. This displays various helpful (hopefully) details as the
  program initializes, in particular it lists the 'PICPROG.CFG' settings,
  and the resultant values. This option may be used in conjunction with
  any of the following options.

  'FILENAME.HEX/OBJ', If a valid filename is found on the command line
  this file will be loaded and programmed directly to the target PIC. The
  program will then return straight to DOS. If the HEX/OBJ file includes
  any ID or Fuse settings, these will be used, otherwise the defaults set
  in 'PICPROG.CFG' will be used.

  '/E' or '-E', this allows you to Erase a target PIC directly from DOS,
  the PIC will be erased and you are returned back to DOS.

  Examples:
  'PICPROG /D TEST.HEX', this will display the debugging information, and
  then program the target PIC with the code included in 'TEST.HEX'. You
  are then returned to DOS.

  'PICPROG /E', this will erase the target PIC, and return to DOS.

  '/T' or '-T', this new option 'Test Mode' is intended to help sort out
  any problems with connections to the programmer. When this mode is
  used, all four output lines may be toggled high or low. The single
  input line is also monitored, and it's status displayed. With the
  circuit diagram and a meter (or logic probe) it should help to sort
  out any problems.

CONFIGURATION FILE:
  With the extra features a number of extra lines have been added to the
  configuration file. A sample, commented, file if shown below. Any line
  beginning with a semi-colon is considered a comment and ignored. To be
  considered a valid line, the keyword MUST start in the very first
  column, then be followed by an equals sign, finally the value must be
  next. Anything else on the line will be ignored. If you follow this
  sample, you can't really go wrong.

  As of this version, the printer port no longer needs to be specified,
  the software searches the usual PORT addresses looking for the programmer
  hardware. If the hardware isn't found, you may still use the software to
  load, display, and disassemble PIC16C84 code - all options which require
  the programmer to be present are disabled.

;SAMPLE PICPROG.CFG FILE
;Default settings for Don McKenzie board.
;If number prefixed with $, number is hexadecimal
;else all numbers are decimal
DataInv = 0      ;Settings for the in/out lines,
VppOn   = 0      ;keywords as used in the original
VppOff  = 8      ;David Tait Basic source code.
VddOn   = 0
VddOff  = 4
ClkHi   = 2
ClkLo   = 0
OutHi   = 1
OutLo   = 0
DataIn  = $40   ;A '$' signifies hexadecimal, this is decimal '64'
DelayTime = 10  ;Sets the programming delay time in milliseconds,
                ;default is 10ms, mine works down to 6ms, but fails at 5ms.

; Added default configuration details.
ID1 = $7F       ;These are the default settings for the four
ID2 = $7F       ;ID settings in the 16C84. MicroChip advise
ID3 = $7F       ;that you use a maximum of '7F', this allows
ID4 = $7F       ;reading them through Code Protection.

;OSC can be 'XT', 'HS', 'LP' or 'RC'
OSC = XT        ;Set the default oscillator to Xtal.

;Following options can be 'ON' or 'OFF'
WATCHDOG     = OFF
POWERUPTIMER = OFF
CODEPROTECT  = OFF

;This was added specially for Don McKenzie, he didn't like the way I
;displayed the PORT address, with a leading '$' to signify hexadecimal.
;If this is set to 'ON', the PORT address is displayed with a trailing
;'H' instead.
DONMAC       = ON

PROBLEMS:
  Erasing a PIC doesn't seem to always erase the EEPROM data, I'm using
  routines based on the original David Tait Basic source code. After
  lengthy discussions on the MCHIPBBS, the general feeling is that the
  16C84 has problems erasing the EEPROM data area. The other available
  programmers have the same problem, apparently the new version of the
  16C84 now includes routines for 'bulk erasure' whilst in serial mode
  programming (the older version didn't).

  Anyway, it's not a problem, any new EEPROM data will simply overwrite
  the existing data.

UPDATES:
  2-Sept-1995, added command line options.  '/D' invokes a debugging
  mode to help with any configuration problems. As the 'PICPROG.CFG' file
  is read, various settings are displayed on screen. This includes the
  printer port addresses as reported from the BIOS table.
  Example 'PICPROG /D'.

  If a valid file name is entered on the command line, the program will
  now write this to the target PIC and return to DOS.
  Eg. 'PICPROG TEST.HEX', will program the target with the contents of the
  hex file 'TEST.HEX'. If there are no fuse settings in the hex file, the
  defaults of XT, No code protect, no WDT, and no PUT will be used.

  4-Sept-1995, added command line option '/E' to erase a chip from DOS.
  Added file requesters for loading files. Added extra lines to PICPROG.CFG
  as listed above. Added the 'S' menu option, which then prompts for which
  buffer you wish to display.

  9-Sept-1995, cleared a few minor cosmetic bugs, altered the Fuse settings
  to use the ALT keys. Added the 'A' option, and altered the 'S' option to
  display the Data Buffer by default.

  13-Sept-1995, minor bug fix, corrected error that limited size of
  disassembled program to less than maximum available size.

  15-Feb-1996, added DelayTime to config file, default is 10ms, but my
  particular programmer and 16C84 will work down to 6ms. Added this option
  to see if it will help people who have problems with some fast machines.

  5-May-1996, command line option '/T' to improve hardware debugging.

  23-July-1996, altered the program to cure problems reading hex files
  produced by the PBasic compiler - it appears to have a bug, and produce
  the fuse settings at the incorrect address (one too high). The modification
  simply writes to the correct fuse address if part of the hex file addresses
  this unused address $2008.

  28-July-1996, after further discussions over the PBasic fuse problem, it
  turns out that the extra data word is for telling Parallax programmers
  which PIC is being programmed. The problems are due to the fuse value
  having the leading 9 bits set to '1', I've modified the file routines to
  strip off the leading 9 bytes of the fuse settings. This should cure the
  verify problems when using PBasic hex files.

And that's about it!. The software is now looking pretty well finished, If
you find any problems, or have any suggestions for improvements, please
E-Mail me.

I can be contacted at 'nigelg@lpilsley.demon.co.uk', this would be the
quickest way as I get my mail at least once daily. If you have no Internet
access, you can mail me as 'Nigel Goodwin' on the MCHIPBBS.

Lastly, many thanks to David Tait for the original design, and to
Don McKenzie for supplying high-quality PCB's for building the programmer
circuit on. If you're wanting to start programming PIC 16C84's the
combination of Don's programmer board and PICME board make an excellent
development system for very little money.

Extra thanks to Don McKenzie for all his helpful advice on the operation
and required facilities for this program.

I've had a couple of reports of the software not working on peoples 'new'
machines, in one case a Pentium (the 'old' 486DX4/120 worked OK), and in the
other a 486DX4/100 (the old 286 worked OK). In both cases I've suggested
trying the old I/O board in the new machine, I suspect some of the new
'enhanced printer ports' may be giving trouble. The speed of the machine
should not be a problem, I'm using Turbo Pascal 7.0 and this doesn't have
the problems with fast processors. I've just fitted a Vesa Local Bus I/O
card with an enhanced port in my 486DX4/100, and it works fine. If you have
problems please feel free to mail me, and I'll see if I can help.
In the last version, I added an extra config line 'DelayTime', this can be
used to alter the default (10ms) programming delay time. Hopefully this might
help problems of this sort. This version now includes 'Test Mode', again I
hope it will help to cure any problems.

Nigel Goodwin, August 1996.
