Default compile is for 16Mhz, 16F876/7, 19200bps.

Questions:

Q. How do I compile?
Q. Which hex file do I use?
Q. How to change to 20Mhz
Q. How to compile (it *can not* be done with MPLab, use HPDPIC)
Q. How to change to 16F873
Q. The bootloader is too slow to drop into the program - how do I speed it up?

*******
Q. How do I compile?

Use Hi-Tech C v7.86pl2 or higher.  This is the latest one off their website, 
www.htsoft.com.

******* 
Q. Which hex file do I use?

Look at your circuit.  For example, use "61619 - bootldr-16F876-77-16Mhz-19200bps.hex" 
for a 16F876 or 16F877, with a 16Mhz crystal, communicating at 19200bps.

*******
Q. How to change to 20Mhz

Open up bootldr.c, and find the line:

#define PIC_CLK 16000000UL	//in Hz

Change it to:

#define PIC_CLK 20000000UL	//in Hz

Note: if you're using any clock speed other than 3.6864, 4, 16 or 20, alter 
delay.h as well.

*******
Q. How to compile
A. Read on ...

> -----Original Message----- 
> From: 
> Sent: Saturday, June 24, 2000 6:36 AM 
> To: shane@keyghost.com Subject: PIC Bootloader
>  
> 
> Hi Shane,
> 
> I recently downloaded the PIC16F877 bootloader  source code from your web 
> site. You web site is a very good resource for any PIC programmer/developer. 
> Thank you for your effort.
> 
> I am currently trying to set up my environment  to run the bootloader 
> example, and ran into some problem. Most of the problem I got is related to 
> my lack of experience with the HT-TECH tools. In any case, since you have 
> run the source code successfully many times, you would have most of the 
> answer handy.
> 
> I started out trying ot set up the MPLAB and  HPDPIC to compile the source 
> code for the bootloader. As you have pointed out in your source code, you 
> mentioned that I have to do a custom compile in order to generate the HEX 
> file correctly. Can you tel me how would I go about doing that custom 
> compile. As I was using the regular compile option, I got error when the 
> MPLAB is trying to link up the Bootldr.obj and the Delay.obj. It complaints 
> of undefined symbols ( ?_DelayUs; _CLRWDT; _DelayUS ). SO I was not able to 
> generate a HEX file from using the MPLAB.
> 
> Then I went ahead to try the HPDPIC, I was able  to compile the files and 
> obtain the HEX file with no problem. After turnning on the Optimization, I 
> got the HEX file of 250 bytes. But the adddress location for the HEX file 
> soes not match up to the HEX file you included in the example. My question 
> is how do I set up the linker to link the address for the bootloader to 
> address 0x1F00 to  0x1FFF. Do I add additional control to the LINKER option 
> in the HPDPIC ? If so, do you have the command line you use to generate the 
> reference hex file.
> 
> Thank you very much for your attention and your reply.
> 
> Paul

Dear Paul,

You *can not* use MPLab to generate the correct .hex file.  

To compile, do the following:

Use Hi-Tech C.  See www.htsoft.com.  This is a commercial compiler.

Load up HPDPIC. Load the project with alt-M then select Load Project.  Press F10 
then select bootldr.prj.  Select File, then Open, press F10 and select 
bootldr.c.

Then, press F3 to compile the project.  This will produce the correct hex file, 
linked 0x1F00 to 0x1FFF.  This is the final version, and will be identical to 
the supplied .hex file.

Program up the target board PIC16F876/7 with this .hex file.  Connect the 
appropriate hardware (see FAQ at http://www.keyghost.com/htpic).  Check that the 
crystal speed is 16Mhz.  Plug in the serial port, then download the new program.  
The new program is then executed.  Next time you reset the circuit, within 2 
seconds the new program will be executed, or else it will load the new program.

This version has be be linked to 0x1E00 to 0x1EFF to work with a ICD debugger, 
but this is only necessary when debugging or developing the code.  You should 
never need to worry about this.

To answer the offset question, each instruction in a PIC micro is 14 bits.  This is 
2 words in the byte file.  So, linking it to 0x1F00 to 0x1FFF results in 
file address offset of double this in the .hex file.  

I hope this helps,
Regards,
Shane.

*******
Q. How to change to 16F873

> Hi Shane,
> 
> I found your *very* nice bootloader on your webpage and want to know 2
> things :
> 
> How easy is it to change to 16F873 ?  ( The one I'm using ! )
> How to tell MPLAB 5.11.00 that I'm using your bootloader ?
> 	If MPLAB/HiTech compiler doesn't know that I'm using a 
> loader, it
> 	will load from 0 and uses all the memory spaces.
> 
> Regards, Antoon

> Hi Shane,
> 
> I just went through your bootldr.c file to see if I can 
> change it to 16F873.
> You mention 5 places in the 'LINK-->' section that needs to 
> be changed, I
> only can find 4 places.
> Can you help me ?

Step 1: In bootldr.c, find the line:

#define LoaderStart 0x1f00

and change to:

#define LoaderStart 0x0f00

Step 2: Change linker options

The 16F876/7 has 8k of memory, 0 to 1FFF hex, and the 16F873/4 has 4k of 
memory, 0 to 0FFF hex.  

If you're looking at the .hex file, note that each 14-bit word is 2 bytes, so 
address 1FFF hex is 3FFF hex in the hex file.

In HPDPIC, select menu 'Make' then 'Linker Options'.  Initially, you should see 
options as below:

-ppowerup=0,intentry=01f04h,intcode,intret,init,end_init,clrtext,stringtable
-ABANK0=020h-07Fh
-prbss_0=BANK0,rdata_0=BANK0,idata_0=CODE
-ABANK1=0A0h-0EFh
-prbss_1=BANK1,rdata_1=BANK1,idata_1=CODE
-ABANK2=0110h-016Fh
-prbss_2=BANK2,rdata_2=BANK2,idata_2=CODE
-ABANK3=0190h-01EFh
-prbss_3=BANK3,rdata_3=BANK3,idata_3=CODE
-ACOMBANK=070h-07Fh
-ptemp=COMBANK
-ACODE=01f04h-01fffh
-ACONST=01f04h-01fffh
-pconfig=2007h
-pidloc=2000h
-pfloat_text0=CODE,float_text1=CODE,float_text2=CODE
-pfloat_text3=CODE,float_text4=CODE
-pnvram=BANK0,nvram_1=BANK1,nvram_2=BANK2,nvram_3=BANK3
-Q16F877

Change all 01f?? to 00f??, as below: (there are 5 values to change)

** this next line changed 010f04h to 0f04h
-ppowerup=0,intentry=0f04h,intcode,intret,init,end_init,clrtext,stringtable
-ABANK0=020h-07Fh
-prbss_0=BANK0,rdata_0=BANK0,idata_0=CODE
-ABANK1=0A0h-0EFh
-prbss_1=BANK1,rdata_1=BANK1,idata_1=CODE
-ABANK2=0110h-016Fh
-prbss_2=BANK2,rdata_2=BANK2,idata_2=CODE
-ABANK3=0190h-01EFh
-prbss_3=BANK3,rdata_3=BANK3,idata_3=CODE
-ACOMBANK=070h-07Fh
-ptemp=COMBANK
** this next line changed 010f04h to 0f04h and 01fffh to 0fffh
-ACODE=0f04h-0fffh
** this next line changed 010f04h to 0f04h and 01fffh to 0fffh
-ACONST=0f04h-0fffh
-pconfig=2007h
-pidloc=2000h
-pfloat_text0=CODE,float_text1=CODE,float_text2=CODE
-pfloat_text3=CODE,float_text4=CODE
-pnvram=BANK0,nvram_1=BANK1,nvram_2=BANK2,nvram_3=BANK3
-Q16F877

Recompile, and you're finished!

Q. The bootloader is too slow to drop into the program - how do I speed it up?

A. The timeout for getting a single byte is set to a few seconds.  Reduce i=48 
to something smaller.  Note that the smaller i is, the less of a time window to 
click 'write' in the windows downloader.  If i<48, the dos bootloader (from an 
earlier version) will not connect properly, as it only sends initialization 
bytes every few seconds.

unsigned char getbyte(void)
{
	unsigned char i;
	unsigned int timeout_int;

	// retrieve one byte with a few seconds timeout
	for (i=48;i!=0;i--)	<--CHANGE i=48 to a smaller value
	{
		//48 * 100ms is about right for a few seconds timeout
		//we are only checking msb of int it is shortened to 3 sec
		timeout_int=timeout_int_us(100000);
