You are searching for a free and easy bootloader? You can find it here.



What is a bootloader for the pic18fx52?

A bootloader is a small piece of firmware (max 512 bytes for the pic18fx52) in the beginning of the program memory to quickly and easily download your own developed firmware in the pic micro. Usually the comport of the pc is used for the communication between your PC and your picmicro application.

My application at this moment: a servo motor controller for positioning
an axis of a milling machine.

Why should I program my pics via a bootloader?

A programmer can do this also. Yeah right but when you are developing an application you need to test many times the new written code. To do this you need to take the micro out of his socket, place it in the programmer, programming it and removing it back to place him again in the application socket. After a few times you have broken pins, painfull fingers and wasted a lot of time. Now you just need to start the download software. Download your program to the pic and doing a reset. So you have more time to spent on your project then change all the time the pic micro. Believe me once you did it this way you will not doing it otherwise again.

The bootloader itself

The bootloader I'll show you is the application note AN851 from microchip, but when you do it like it's described in the app note you still need to make some changes in the sourcecode before it will work. For this reason and because I've read on some forums that many people have problems with it I show how you can do it. And downloading a working hex file and assembler file on this page.

The bootloader sourcecode that I changed a little bit.

I've changed the original sourcecode because when you download it from microchips website it will not work. The firmware likes to be written for a microcontroller with 2 serial ports. And at the end before the subroutine waitrise they placed an org 0x00A. Why I don't know, but this is wrong and the code does not work with this. So I removed it. To start the bootloader software the data on the last internal eeprom address must be FF, when it is another value it jumps to the new reset vector at 0X0200h. I changed this and used the RA,0 input pin to select wether to start the bootloader firmware or the user program. When RA,0 is high it starts the bootloader when low it starts the userprogram. This way it is easy with a jumper to select this and a reset button to reset the processor.

Click here to view the changed sourcecode.

Click here to view the hexfile.

How to get the bootloader in the chip.

You just need one more time using your old programmer to programing it into the pic. I'm using an jdm programmer with my selfmade adapter for 40pin devices. (don't laugh with me but this is the way i'm doing, see the foto). But it works and its the cheapest adapter.

You just connect with wires the pins on the 18pin socket to the 40 pin socket.

-----18pin-----40pin-----

MCLR-pin4-------pin1-----
GND--pin5-------pin31----
+5V--pin14------pin32----
Data-pin13------pin40----
Clk--pin12------pin39----


Don't forget also to set the config bytes because they are not included in the hex file: For an Xtal oscillator of 20Mhz I set, Config 1 (hex) FAFF, config 2 FEFC, config 3 FEFF, config 4 FFFA, config 5,6,7 FFFF

The download software.

To communicate with the bootloader firmware in the pic, you need also software that runs on your pc. Microchip added a little and simple but effective program to download the userprogram into the pic.

Click here to download the user software.

The memory organisation.

At this moment the pic18 devices are using the first 512 bytes of program memory as the boot block. Future devices may expand this but however this bootloader fits in the first 512 bytes. The bootblock can be write protected to prevent accidental overwriting.

REMAPPED VECTORS
Since the hardware RESET and interrupt vectors lie within the boot area and cannot be edited if the block is protected, they are remapped through software to the nearest parallel location outside the boot block. Remapping is simply a branch for interrupts, so PIC18F users should note an additional latency of 2 instruction cycles to handle interrupts. Upon RESET, there are some boot condition checks, so the RESET latency is use additional instruction cycles.

WRITING CODE The bootloader operates as a separate entity, which means that an application can be developed with very little concern about what the bootloader is doing. This is as it should be; the bootloader should be dormant code until an event initiates a boot operation. Under ideal circumstances, bootloader code should never be running during an application’s intended normal operation. When developing an application with a resident bootloader, some basic principles must be kept in mind:

Writing in Assembly When writing in assembly, the boot block and new vectors must be considered. For modular code, this is generally just a matter of changing the linker script file for the project. If an absolute address is assigned to a code section, the address must point somewhere above the boot block. For those who write absolute assembly, all that is necessary is to remember that for PIC18F devices, the new RESET vector is at 200h, and the interrupt vectors are at 208h and 218h. For PIC16F87XA devices, the RESET vector is at 100h and the interrupt vector is at 104h. No code, except the bootloader, should reside in the boot block.

Writing in C When using the MPLAB® C18 C compiler to develop PIC18F firmware for an application, the standard start-up object (c018.o or c018i.o) must be rebuilt with the new RESET vector. Like modular assembly, the linker file must be changed to incorporate the protected boot block and new vectors.
Back to homepage