PIC-Bootloader for 16F87xA

This bootloader for the "A"-Type PIC's is based on the bootloader for PIC16F870/871/873/874/876/877 Vers. 2.60 written by Petr Kolomaznik and modified by Shane Tolmie avalilable on www.microchipc.com. The "A"-Type PIC's need a special way for writing into program flash memory because program words are written definitely only in blocks of 4.

The bootloader is implemented and tested with PIC16F873A , PIC16F876A and PIC16F877A. 
The full source code is available and can be adapted to other PIC's.

How to use

First the bootloader code must be programmed into the PIC (e.g. with PIC Start Plus). Select the suitable Bootloader-Hexfile for your Processor/Clock/BaudRate.

For example the File "bootldr-16F877A-20MHz-38400bps.HEX" is good for PIC16F877A with 20MHz crystal and 38400 baud. The same file is also suitable for 10MHz crystal and 19200 baud. If there is no Hexfile for your configuration, you have to reassemble the source (with MPLAB) with the correct definitions.

;================== User setting section ======================================

list p=16f877a              ; <<< set type of microcontroller (16f873a or 16f876a)
                            ; set same microcontroller in the project
#define ICD_DEBUG 0         ; <<< if using MPLAB ICD Debugger, moves bootloader down 256 bytes to make room for it [0|1]
#define FOSC D'20000000'    ; <<< set quartz frequence [Hz], max. 20 MHz
#define BAUD D'38400'       ; <<< set baud rate [bit/sec]
#define BAUD_ERROR D'4'     ; <<< set baud rate error [%]
#define TIME                ; <<< set method of bootloader start PIN/TIME
                            ; PIN : start on low level of trigger pin
                            ; TIME: start on receive IDENT byte in TIMEOUT
#define TRIGGER PORTB,7     ; <<< only for PIN - set PORT_X,PIN_NR
#define TIMEOUT D'2'        ; <<< only for TIME - set time [0.1s], max. 25 sec
#define WATCHDOGTIMER 0     ; <<< Watchdog timer default OFF/ON [0|1]

 

The download of the application code (HEX-File) is to be done under Windows with the "PICdownloader" program, which is available from Shane Tolmie.

Important Note:

The first 4 Programwords in the Code (Addresses  0000H - 0004H) must be as follows:

0000        00049             org 0      ; RESET vector location
0000   0183 00050 RESET clrf  STATUS
0001   3000 00051       movlw 0x00
0002   008A 00052       movwf PCLATH
0003   2804 00053       goto  start
            00054 
0004        00055 start                  ; Begin of user program

This code is nescessary, because the bootloader uses the first 4 words by himself and copies the address-range 0000H to 0004H of the downloaded program to high memory and jumps from this position to the user program start (anywhere in memory).

If you are using a C-Compiler you must take care, that the resulting code meets this requirements.

 

Version History

V1.2   (2004-07-07)

There is no more need for "quad alignment". Now it's also easy to use the bootloader with C-Compilers.

The bootloader occupies 400 bytes at top of memory.

Download Version 1.2 of bootloader

V1.1   (not available)

V1.0  (2003-11-12)

Code must be "quad aligned"  (quad aligned means:  address modulo 4  = 0 !!)

mandatory "quad aligned" start address of each code segment (use ORG-directive)

add 3 NOP's at the end of each memory segment, if you cannot be sure, that the last segment address is xxx11

This bootloader is primarily written for use with assembler coding (Microchip MPLAB). Quad alignment with C-Compilers is not so easy to do.

The bootloader occupies 288 bytes at top of memory.

Download Version 1.0 of bootloader

 

                   

2004-12-17   Peter Huemer

 

kostenlose counter @ www.counter-kostenlos.net