BootPic18 1.0 (27 November 2004)
Copyright (c) 2004 S. Simon

Click here to download BootPic18

Introduction

BootPic18 is a bootloader program for the PIC 18f1320
microcontroller. The purpose of this bootloader is to
download application code from the developer's computer
to the PIC microcontroller.

I have created BootPic18 because other bootloaders did not
meet my requirements.

Contents

  • License
  • Features
  • Compiling the bootloader
  • Customising the bootloader
  • Using the bootloader
  • Compiling the utilities xsend and hextoldr
  • Known problems
  • Web links

    License

    Copyright (C) 2004 S. Simon
    You may use this software for any purpose without restrictions. This software comes with no guarantee of any kind.

    Features

  • BootPic18 is written "C". Most other pic bootloaders are written in assembler. It is much easier to understand and maintain C source code than assembly source code.

  • No custom software is required to upload code to the bootloader. You can use the Windows HyperTerminal for both programming and debugging.

  • The bootloader uses the Xmodem-CRC protocol to communicate with the PC. Xmodem-CRC uses a robust 16 bit CRC error detection mechanism. Many other bootloaders only use simple 8 bit checksums, or use no error detection at all.

  • All data is verified after programming.

  • The bootloader resets the pic before jumping to the user code. This ensures that the user application always starts in a consistent and predictable state. Most other bootloaders simply jump to the start of the user code on completion.

  • The bootloader fits into the 512 byte boot block of the 18f1320. There is room to spare for another 50 bytes of user code within the boot block.

  • The bootloader will work on other 18f devices such as the 18F452 with little or no change.

  • Programming and verifying a 18f1320 takes about 10 seconds. If only the program memory is programmed it takes only 5 seconds to program the device. (these numbers assume a 115Kbaud connection)

  • And last but not least this bootloader is free.

    Compiling the bootloader

    I chose the CC8E Demo C compiler for this project simply because it was free and it works. The demo version of the compiler can generate up to 1000 instructions. The CC8E compiler generates surprisingly efficient machine code.

    1. Download and install CC8E. Read the documentation.

    2. Edit the file bootpic18.bat, modify the file paths as required.

    3. Run bootpic18.bat at the command prompt.

    Customising the bootloader

    1. Edit the file bootpic18.c and change the device configuration bytes as required. The bootloader will not be able to reprogram the configuration bytes.

    2. Change the values for OSC_FREQ and BAUD_RATE as required.

    3. You may have to change the oscillator and USART set up code at the start of function main depending on your requirements.

    Using the bootloader

    The bootloader is located between address 0 and 0x1ff. The reset vector is relocated to address 0x200. Interrupt vectors are relocated to 0x208 and 0x218. Your application will have to start at address 0x200 instead of address 0. Different compilers have different means of achieving this. Read the manual of your compiler, assembler, or linker.
    1. Program the bootloader into the pic chip.

    2. Connect the pic to the serial port of your PC using a suitable interface.

    3. Run and configure HyperTerminal

    4. The terminal should be displaying the character 'C' in about half second intervals. (If the bootloader does not receive a response in about 10 seconds, it will execute the application code.)

    5. Use the hextoldr utility to convert your hex file to a format compatible with the bootloader. The hextoldr utility is included in the download package. Type hextoldr at the command prompt to display the command line options.

    6. Upload the file generated in the last step to the bootloader. In HyperTerminal choose Send File from the Transfer menu. Select the Xmodem protocol. If you see no error messages the pic has been programmed and verified successfully.

    It is possible to automate the programming process using the command line utility called xsend. You can use xsend to upload files to the bootloader. xsend is included in the download package. Type xsend at the command prompt to display the command line options.

    On power up the bootloader decides wether to jump to the user application, or execute the bootloader code. The following conditions must be met for the bootloader to execute:

    1. 'power on reset' flag is activated (POR=0) (Set the POR flag in your application if you only want the bootloader to execute on cold power up.)

    2. 'reset instruction' flag not activated (RI=1) The bootloader uses the RESET instruction on completion. At boot time the RI flag is checked if the reset was caused by the RESET instruction.

    3. serial input line is high (RB4=1) The bootloader only executes if the RX line is connected. Pull the RX line (RB4) to ground with a 100K resistor.

    Compiling the utilities xsend and hextoldr

    BootPic18 was developed using VisualC++ 6.0 You may also use VisualC++ Express 2005 to compile the source. You can download VisualC++ Express free from www.microsoft.com/vstudio

    Known problems

  • The internal oscillator of the 18f1320 is not accurate. Serial communications may not be reliable or may not work at all at the factory set oscillator frequency. The internal oscillator can be calibrated using the OSCTUNE register. The frequency should be adjusted to be within 1% the required frequency. Read the data sheet carefully about the internal oscillator if you plan to use it.

    Links

    Microchip
    The manufacturer of the PIC microcontrollers.

    CCE8E Compiler
    PIC18 C Compiler. Free demo version generates up to 1000 instructions.

    'Tiny Bootloader'
    A simple bootloader. The author provides a good introduction to bootloaders. This site has a list of links to various other boot loaders. There is also a circuit diagram for interfacing a PIC to the serial port.

    X-MODEM protocol
    Description of the X-MODEM protocol.

    X-MODEM protocol
    Another good description of the X-MODEM protocol.



    Last updated 27 November 2004 1