               
               PEPE: Running PP.EXE with the EPE PIC programmers
               =================================================

                               David Tait
                           david.tait@man.ac.uk
                      http://www.man.ac.uk/~mbhstdj

It doesn't take much hardware to program PIC16X8X microcontrollers with
the aid of a PC.  The simplest design of all (the so called "quick-and-dirty" 
programmer) forms the basis of both Derren Crome's hardware described in 
Everyday Practical Electronics (February 1996) and the board used to support 
John Becker's PIC tutorial series (EPE March-May 1998).  I'm sure the 
simplicity of the EPE programmer has gone a long way to popularise the PIC 
in the UK but it has one drawback: the EPE programmer software, send.exe, 
is not compatible with the file format of the "Industry Standard" assembler, 
MPASM from Microchip.  The send.exe program was designed for a shareware 
assembler called TASM but as MPASM is actually free I'm not sure why.  
As I wrote some software to allow send.exe to use MPASM files a couple 
of years ago (available from EPE's own ftp site as sendhex.zip) the recent 
decision to base EPE's excellent PIC tutorial on TASM saddened me.  I'm now 
having another go at getting people to use MPASM.  This time I've adapted 
my own MPASM-compatible PIC programmer software (called pp.exe) for use
with quick-and-dirty programmers.  To make the switch from send.exe easier
I've written a wrapper for the pp.exe program: the batch file pepe.bat is 
used as a preprocessor to set the appropriate command line parameters
and convert between file formats as necessary.

As mentioned, The EPE programmer is designed to use files produced by TASM 
and pp.exe is designed for the hex files produced by MPASM.  The program 
obj2hex.exe is used to convert between the TASM and MPASM formats.  To 
convert a TASM file example.obj to example.hex you can use:

    obj2hex example.obj example.hex epeflag

The EPE programmer loads files into the PIC starting at location 4 and 
always puts a GOTO 5 instruction at location 0.  This rather quirky decision 
has little merit as far as I can see.  In fact, it has three detrimental 
effects: you must always write your program to agree with the decision; you 
lose a few words of program memory (OK, not many); and interrupt routines 
(which start at address 4) are forced to jump around the new program start 
location (at address 5) which introduces latency (OK, just a small amount).  
Anyway, the optional epeflag parameter is used to force obj2hex to construct 
a compatible hex file.  

Though not needed by pepe.bat, converting between hex and TASM format is
accomplished using hex2obj which is included here for completeness.  The 
inverse conversion to the one just mentioned is done by:

    hex2obj example.hex example.obj 4
    
The optional parameter 4 tells hex2obj to skip 4 words for compatibility 
with the EPE programmer.  Without their optional parameters both programs 
simply convert between the two formats by assuming they start at location 0.

The batch file pepe.bat is written as a replacement for Derren Crome's 
send.exe program or my modified version from sendhex.zip.  To use pepe.bat 
the programmng software pp.exe must be in the same directory. The batch 
file is run like this:

    pepe example

The filename is given WITHOUT the extension (just example not example.obj 
or example.hex).  If all is well you will then be asked whether the file is 
in TASM or MPASM format (a TASM file is converted to MPASM format assuming
it was written for the send.exe software); then the batch file prompts for 
the configuration word and the type of device (16C84 or 16F84) before 
running pp.exe with the appropriate command line.  When pp.exe asks you to 
"Insert PIC ...", connect the programming voltage and when it exits remove 
the programming voltage and reset the PIC.  The most reliable way to do that
is to press the reset swich, connect the programming voltage, release 
the reset switch at the "Insert PIC ..." message, press it again when pp.exe
exits, remove the programming voltage and finally release the reset
switch at which point the PIC should start running.  You can use pepe.bat 
to simply update the config word by running it with the file null.hex which 
is a null program hex file.  If you decide to use MPASM rather than TASM 
you can write your programs in free format without adhering to the EPE 
programmer conventions described above.  In fact, if you decide to use MPASM 
I would encourage you to embed the configuration word in your source 
program because then you can simply type:

    pp example.hex
    
and everything is done for you (make sure you set the environment variable
ppsetup=3 before running pp.exe on it's own).  My programmer software itself 
was not really written to support the EPE hardware and it would be possible 
to make it more compatible.  Alternatively a few mods to the EPE programmer 
would make it a lot easier to use: the addition of a transistor to control 
/MCLR and one to allow reading back from the PIC are a good idea.
If there's enough interest I'll produce a modified pp.exe that is able
to control such an enhanced version of the hardware using either the 
PC parallel or serial ports.

It would be a good idea to get the full documentation for pp.exe from:

http://www.man.ac.uk/~mbhstdj/files/pic84v05.zip

Amongst other things this will help if you have problems with "out
of environment space" errors when running pepe.bat.


V-0.1  22 April 1998
