No Frames. Direct to: Dontronics Shop What's New? or Dontronics Shop

Dontronics Home Page  PICLOADER
 
Back to Free Files - Don's Download Dungeon

Oct-2005
4D Systems Micro-LCD Module is equivalent to a Micro-VGA Adapter with a tiny 1.5 full colour LCD module attached. It supports the same command set as the Micro-VGA Adapter. There are possibly thousands of applications for the embedded market where the microVGA and the display are integrated all into one. Display text, graphics, images all in full colour. We can also have a touch screen option etc.
http://www.dontronics.com/micro-lcd.html

Sep-2005
PC-USB to Micro-VGA Adapter. The MicroVGA is a graphics adaptor that allows the display of text characters & an unlimited number of graphic patterns. This new version connects your PC-USB to a standard VGA monitor. TTL and RS-232 Versions available.. Now with a selection of  64/256 colours, and the following resolutions: 256x200, 320x220, 420x350, 620x420, 640x480, and 720x500
http://www.dontronics.com/micro-vga.html

Aug-2005
The Micro-USB is based on Silicon Laboratories CP2101-CP2102 I.C.'s, and has the world's smallest footprint for this type of device. It uses a standard USB B connector (same as all of the other modules that Dontronics sells) to connect to your PC using a standard AM to BM cable, and an 8 pin footprint at .1" centers on your target board, to allow simple connect to your breadboard or Micro board. The CP210x chip has a UART,  and on-board EEPROM built right it.
http://www.dontronics.com/micro-usb.html
 

Rick Farmer's PICLoader modified to work with mEL PICBasic.
Rick Farmer's PICLoader modified for the CCS compiler and MPLAB
Rick Farmer's PICLoader modified to 1.3a by Antonio (Nino) L. Benci
Rick Farmer's PICLoader modified to 1.3b by Angelo Fraietta

Please Note **** This page is provided as is by Dontronics. We don't support any code or products associated with this page. You will need to contact the individual Author for more information.

PICLOADER

Rick Farmer

Release Rev 1.5

Last Updated 24-Aug-2002

Don, I've gone back and cleaned up the source code for the bootloader. There are some minor functional changes, but the main reason for the new version was to make the source code more hacker freindly. I've also  released the code under the GPL.

Introduction

PICLOADER is a resident bootloader for the Microchip PIC16F87x series of FLASH based microcontrollers. It allows you to reprogram a new code image into the chip with any computer that has a standard RS-232 serial port. If you're familiar with the "buffalo" bootloader in the Motorola 68HC11 series processors, or the SPI based bootloader in the Atmel AVR series processors, you probably already have a good idea of how useful a bootloader can be. The main difference is that PICLOADER has a user-friendly interface that can store a user program to the onboard FLASH memory without using any special hardware or software.

PICLOADER uses the on-chip UART to communicate with a computer running a terminal program to upload user code into program memory. The purpose is to allow designers to update their code image without having to remove the processor from the board. If you design embedded systems for a living you're painfully aware of the havoc that a code bug in deployed units can cause. This also allows a board to go into manufacturing while code issues are still being worked out.
 

Design Goal

The design goal for this project was to generate a generic program that would have the widest possible appeal. For that reason I designed the program to have the least possible impact on the user's code and hardware design. I also decided that the only external hardware need to use the program would be a standard straight through 9 pin serial cable. The intent was that anyone with a laptop or PDA would be able to upgrade a device in the field. Simply put, the thought of having to upgrade thousands of deployed OTP based units is an embedded systems designer's worst nightmare. In this document I assume that the user is running Win9x on a PC and is using the HyperTerminal COM program because it is the lowest common denominator.
 

Overview

When the processor boots, PICLOADER hooks the reset vector and send a splash screen. If there is a valid user code image, it will wait 15 seconds for a response. If there is a response (any character input) PICLOADER will start, otherwise the user code is booted. A valid user image is determined by examining the program location 0003h, the user code reset vector. If this instruction is a "goto" it is considered the start of a user program. PICLOADER will go immediately to the command prompt if there is no user code image. If the command prompt is left idle for 10 minutes, PICLOADER will jump to the user image if one is present.
 

Writing Code for Use with PICLOADER

PICLOADER's impact on user code is quite small. The only restrictions are that the user code reset vector moves from 0000h to 0003h and the last bank of program memory is reserved for the PICLOADER code. PICLOADER does not use interrupts, so aside from the restrictions in code space you can pretty much write your code as if the PICLOADER did not exist. In addition, PICLOADER can be invoked by the user code at any time to initiate a code reload. Note that PICLOADER always returns control to the user reset vector when it exits, regardless of how and where a user program calls it. Also check to make sure that the default configuration fuses do not conflict with your design. For example, the watchdog timer and brown out detector are enable by default. A complete list of the fuse setting is described at the end of this document and you can change them as needed when you program the bootloader into your target chip. Here is a checklist for converting code to run with the bootloader.
 

Theory of Operation

PICLOADER sets up the serial port for 9600 baud 8-N-1 with no flow control on the assumption that a 4.00MHz clock is being used (SPBRG = 25 decimal and TXSTA, BRGH = 1). Using standard crystals that are an even multiple of 4MHz will also give standard baud rates. For example, using a 16MHz crystal yields a 38.4k baud rate. If the clock used in your design would result in an oddball baud rate you have the option of loading the SPBRG register and the TXST, BRGH bit to whatever you like and jumping to 1805h to bypass the PICLOADER initialization of these registers. Otherwise jump to the start of PICLOADER at 1800h (this example assumes that the target is a PIC16F877 or PIC16F876, if a PIC16F874 or PIC16F873 is the target the last bank of memory starts at 0800h, not 1800h). When control is returned to the user code the serial port is left initialized. If an RS-232 serial port is not needed in your design, the two serial port pins, power, and ground can be brought out to a 100 mil four-pin header. This will allow you to use of an RS-232 to CMOS converter dongle I've designed to reprogram the unit while minimizing board space and direct material cost. I often use this approach as an aid to debugging on designs that do not need a serial port. If you elect to use this option, use the following pinout for the connector and put 10K pull-up resistors on the RX line. If there is sufficient interest, I will manufacture and sell the needed RS-232 level shifter dongle. Otherwise users can make they're own based on this dongle schematic.

Pin1 = VSS (system ground)

Pin2 = RX (PIC RX line, input)

Pin3 = TX (PIC TX line, output)

Pin4 = VDD (power to dongle)
 

Using PICLOADER

Assuming that you have a target board with the serial port hardware shown in the accompanying evb schematic and that it is connected to a serial port on your computer with a serial cable or dongle, all you need to do is start HyperTerminal. First open a terminal session and set it up as a direct connection to the appropriate COM port. Next, set the terminal to ANSI mode with no flow control 9600-8-N-1. Make sure that the function keys are set to be terminal keys, append line feeds is off, local echo is off, line delay is set to 100ms, wrap long lines is set, and that the backspace key sends a "control H" char (08h). You should now be ready to download your image. Reset the target or use the terminal to tell you application to invoke the PICLOADER. When PICLOADER starts you'll see a splash screen that displays information on the current revision of both PICLOADER and the user code. If there is already a user program in memory it will display hash marks as the boot timer counts down waiting for a keystroke. If there is no user code image loaded, PICLOADER will skip the timer and jump straight to the command prompt just as if you had pressed a key. Next you will get a message that says if you press "?" at the command prompt you'll get a list of commands. The command set is explained in the next section.
 

PICLOADER Commands

? - Display this list

Q - Quit and jump to user code

U - Upload user code to program memory

D - Download user code from program memory

W - Write to EEPROM, "W DD @ AA"

R - Read from EEPROM, "R AA"

V - Display user code rev string

"?" is the command to get a help screen. Commands are not processed until the "enter" key is hit. You can backspace just like a standard computer command line.

The Q command quits PICLOADER and jumps to the user image. If there is no user code, the command is ignored and you get a message that states that there is no user image loaded.

The U command initiates a code upload. You will be prompted to confirm the upload. Type "y" to proceed with the download. Any other input will cancel the download. When "y" is entered you will be given the prompt "ready" once all of user FLASH and EEPROM memory has been erased. It takes 10 about seconds to erase a 4K (2K-user space) part and about 30 seconds for an 8K (6K-user space) part. At this point open the hex file that you want to upload with Wordpad (LCD) and "Select All" (control A) and "Copy" (control C) to copy the file to the buffer. Then switch back to terminal program and "Paste" it (control V) into the terminal window. PICLOADER reads in the file one line at a time and checksums each line before programming the data the line contains. If there is an error, PICLOADER will issue one of the following messages: invalid record type, checksum error, FLASH or EEPROM programming error, attempting to overwrite PICLOADER, trying to program the CONFIG fuses (not allowed), and non-hex characters in the hex file. The offending line number (in decimal) of the hex file being uploaded is included in the error message to aid debugging. A programming error will give the address of the bad memory location. A successful upload will result in a success message and a prompt for a code revision string. An error will abort the upload and the rest of the file will be sent to the bit bucket. An unsuccessful upload will also erase the partial user image and previous revision string. An image is not marked as valid until the last line is checksummed and the last byte is programmed. A loss of power or reset during upload will leave garbage in memory, but it will be marked as such, and the part will be reported as blank.

If all you want to do is erase the part hit "enter" when the "ready" prompt is given. It will give you an error message because it was expecting data, but memory will be completely blank.

The D command dumps the current use code image to the terminal in INHX8M format. Storing a downloaded image is essentially the reverse of uploading an image. This allows you to verify a code upload and retrieve data stored in user program space. EEPROM memory is also included in the dumped image.

The W and R commands are basically PEEK and POKE commands. They read or write a single byte to the EEPROM data memory. Entering non-hex values, invalid addresses, or an EEPROM programming error are rewarded with an error message to the same effect and the operation is aborted.

The V command displays the code revision string for the current user image or a memory is blank message as appropriate.

The code revision string is stored in the PICLOADER's program space as a data table and does not use any EEPROM. The string can be up to 32 characters in length and is also displayed when PICLOADER first starts. You do not have to enter a revision string, but it is highly recommended. The code string command will display whether or not a user code image is present, and if so, the revision string entered when it was uploaded. The revision string can only be changed after a successful code upload.

See the doctored example hex file that shows how to add a rev string to the hex file so that it is automatically entered when an image is uploaded. Don't forget the carriage return at the end of the rev string (last) line.
 

Downloading the Source code and Hex Files

I've released 2 hex files, one for the 8K PIC16F877/876 parts and another for the 4K PIC16F874/873 parts. This is necessary because PICLOADER must know how much memory the part has to perform proper boundary checking during memory operations. The source is available now that the code is stable. PICLOADER is freeware. Do whatever you like with
it.
 

EVB

Is the eval board available? Yes, the bare board is $20. The board supports 28-pin parts in addition to the 40-pin parts. The 28-pin footprint is nested inside the 40-pin footptint. Here's the PCB artwork, BOM, JPEG image, and the schematic of the board. Here is the native Protel source for the schematic and PCB files for anyone interested.
 

Troubleshooting, FAQ, and Errata

PICLOADER just jumped to user code on it's own, what happened? PICLOADER has a 10-minute activity timer. If it expires, PICLOADER jumps to user code provided an image is present. This prevents a user code lockout if PICLOADER is inadvertently activated or left running for any reason.

What file formats are supported? PICLOADER expects an INHX8M format file, as this is the default for all of the Microchip compilers and assemblers.

Uploading hangs at the end, why? All lines must be terminated with a CR. If you cut and pasted a hex file and didn't get the last carriage return PICLOADER will spin waiting for it. Just hit enter to finish the line and remember to get the CR next time.

The value 3FFFh is considered a blank memory location for the purpose of downloading the current image. If your program stores data tables in it's own program memory, guard against this value, as the downloader will skip these locations if you try to retrieve it using the download command. The reason I did this so that you can download an image, diffit against what you uploaded and get identical files. EEPROM data is dumped unconditionally. You can easily spot these lines in the hex file (or the diff output) because they all start with ":1042" or ":1043".

When uploading an image, all user memory locations and EEPROM are pre-erased to 3FFFh or FFh respectively so that garbage left over from a previous image is not read back on a subsequent download.

All commands and hex file characters are case insensitive. The password string and the user code revision string are case sensitive.

What are the other chips on the schematics? One is an RS-232 line driver made by Maxim, the other is a 5-volt linear regulator made by National Semiconductor.

Are versions of PICLOADER for the other peripheral interfaces available? Not currently, but I may develop a version for the slave parallel or SPI ports in the future. Having a reprogrammable slave on a host processor bus would be quite useful, a few years ago I would have given my left arm for one. Other interfaces will only be developed on a custom basis for commercial users, or as I need them for my own designs.

Are other baud rates or clock speeds going to be supported? Not likely, I don't want to support a million versions of the code. Custom baud rates aren't a problem for commercial users though.

How do I include EEPROM data in my source code? As per the example in the Microchip MPASM documentation, EEPROM data is specified in the source code with the DE command and is located between 2100h and 20FFh/21FFh for parts with 128/256 bytes of memory respectively. Note that the data byte is stored in the hex file in the same way as a program data table byte. This means that it is stored as a word, just that the high byte is 00h instead of 001101xxb, as is the case with a retlw XX instruction.

The configuration bits cannot be programmed by PICLOADER. Changing the configuration fuses requires the part to be erased in a programmer. Here are the settings used: debug is disabled, brown out reset is enabled, the power-up timer is enabled, the watchdog is enabled, standard xtal mode, copy protect is off (unfortunately PICLOADER can't program memory if this fuse is set), and (external) low voltage programming is disabled. You can change them when you program the part if you like. Again commercial users can specify any fuse combination they wish.

If you're looking for a good book in Microchip uC's see http://www.picbook.com. I took Prof. Peatman's class when I was at Georgia Tech. He also has a good book on the Motorola 68HC11, which is what he was using when I took his class.

I've gotten a good bit of email asking how to write C code that moves the reset vector so that it will work with the bootloader, so here's an example that works with Hi-Tech's PIC C compiler.
 

Revision History

Rev 0.1 was developed before silicon was available. It never ran outside of the MPLAB simulator.

Rev 0.2 was a port to the PIC16C74. At this time the target silicon was still not available, so the four routines that handle EE and FLASH reads and writes are IFDEFed to return dummy status and data.

Rev 0.3 was mainly a clean up and testing phase. In this revision I added the ability to upload and download EEPROM data as part of the hex file.

Rev 0.4 added a missing 128 vs. 256-byte EEPROM size check for the different size parts. Added Xon/Xoff software flow control support. This is only used to throttle the host. PICLOADER sends all Xon/Xoff characters from the host to the bit bucket. This option will free the RTS and CTS pins for general-purpose use in the host system. Cleaned up command line parsing.

Rev 0.5 tightened up data parsing which made GETHEX redundant with HEXQ.

Rev 0.6 added addressing, half-duplex and multi-drop support for RS485 networking.

Rev 0.7 removed OTP emulation code and began testing on target silicon.

Rev 0.8 tightened up the UI for first release.

Rev 0.9 fixed a bug that would consider the partial user image left in memory after a reset during an upload to be valid. Changed the configuration fuses to WDT on, power-up timer on, and BODEN on.

Rev 0.A dead code.

Rev 0.B changed the clock from 3.58MHz to 4.00MHz. Removed all flow control. The host must now use a line delay to prevent buffer overrun during an upload. Removed the line status echo during upload. The code has been stable for 2 months now. If things stay on track I'll rev the code to 1.0 in about a month. I may make a cosmetic change or two, but otherwise it's looking solid.

Rev 1.0 added the echo of #'s during erase and upload to let you know it's doing something instead of having to look at a blank screen for 30 seconds or so.

Rev 1.1 fixed a range check bug in the hex file upload routine. Classic checking the Z bit instead of the C bit after a subtraction. This bug only affected large hex files that had EEPROM data imbedded in them.

While I've made several minor updates to this page for the sake of clarity, the itself code hasn't changed since 8/16/99. -RJF 6/5/00



17-Mar-2006  From Antonio Benci

In recently tried updating our 16F876/7 projects with V1.5 of PicLoader. After some minor headaches I was directed to the following WWW site,

http://www.dunmire.org/projects/MEEPS/software/index.html

Therein I found QwikLoader. QwikLoader is based on PicLoader1.5 with some improvements and bug fixes. I just thought that this would be of interest to anyone that uses PicLoader and that your WWW site is the one that provides access to PicLoader.

Cheers.
Antonio Benci.

PS: QwikLoader works very well with the MicroMint PicStic5 module. A very minor mod needs to be made to the code. The change has to be added to the 'BOOTLDR' code section, as shown below...

********************* EXAMPLE HERE *******************************
SENA    equ     01h             ;TX/RX enable for PicStic5

BOOTLDR bcf     STATUS,RP1      ;page 0 or 1 (org x800h)
        bsf     STATUS,RP0      ;switch to memory page 1

        ;configure the UART
        movlw   BAUDSET
        movwf   SPBRG           ;load baud rate reg

        movlw   B'00100110'     ;8bit, TX on, asynch, BRGH high
        movwf   TXSTA           ;load TX control reg

        ;configure I/O pins
        bsf     PORTC,TX        ;(TRISC,TX) TX can now be used for UART
        bsf     PORTC,RX        ;(TRISC,RX) RX can now be used for UART
        bsf     CTSPORT,CTS_D   ;(TRISx,CTS_D) ensure CTS_D pin is an input

        ;added for PicStic5 Transmitter module.
        bcf     PORTC,SENA      ;(TRISC,DRV ENABLE) ensure drivers are enabled



Subject: PICBasic & PICLoader
   Date:         Fri, 29 Dec 2000 06:38:16 +1030
   From:         Deano <deanoc@camtech.net.au>
     To:         Dontronics <dontronics.com>

Don,
    as promised I've  been playing with PICBasic and managed to modify the PICBasic Code so that the resultant code can be loaded using Rick Farmer's PICLoader (on your site)

The following two  highlited lines of code must be placed in a copy of PICBasic's PBH.inc (Make a backup copy of the original before modifying. The two line place  a jump at location 0003 as per Rick's instructions.

Find the location near the end of PBC.INC (In the INC directory) that contains the startup Code section as shown below. Insert the two lines shown in red, in the same location shown.
Save the PBC.INC file in the same directory (This is why you save a copy)
___________________________________________________________________________

;****************************************************************************
; Startup Code & Low Code Items
;****************************************************************************

  CODE

;==========================================================
; Power Up/Reset/Watch Dog Timeout Vector
;
; INPUT  :
;          None
; OUTPUT :
;          None

;Put in by Deano for the PICBasic to work with the PICLoader.  Rem these two next line to revert back to normal
                org     3
                jmp     start           ; Jump around interrupt handler at 0004

start        btfss   TO              ; If WD Timeout, Return to Caller
return

  @PINS@0                 ; Zero PINS
___________________________________________________________________________

If a program is compiled and an attempt to load into the 877  via PICLoaderan error will occur. This is because Rick's
program won't alow Config words to be put into the PIC.   The error is generated by the PICLoader which won't accept
config info at any address at 4xxx. (One of Rick's parameters). For this reason, I have written a routine which extracts any line
from the Hex file which begins with an address of 4000.
File is attached called "Remove4000.exe"  a simple QBasic generation.
Source code is also attached.
remove.zip

The sequence to write and use the PICBasic file is as follows.

Write the Basic program for PIC877 using the -P16F877 on the command line when running PBC
Run     Remove4000.exe Filename.hex    to remove the 4xxx lines from the hex code.
Run Hyper terminal and set the parameters as per Rick Farmers instructions.
Press reset on the PICLoader Hardware and enter on the computer to establish communication.
(Should come up on hyperterminal)
Open the hex file using  wordpad (this should come up as lines of hex code.
Use "CTRL A" to Highlite the hex
Use "CRL C" to copy it to the clipboard
Click back to hyperterminal
Press "U" for upload & "Y" to confirm erase.
When it's finished & say's ready, press "CTRL V" to paste to hyperterminal screen. The uploading should commence.
When it's finished press enter. Then press "Q" & enter to run the code.
This does work and works well.
Deano.


  Subject:    PIC Loader modified for CCS compiler
    Date:          Tue, 9 Jan 2001 15:11:28 +0100
    From:         "Richard PERDRIAU" <richard.perdriau@eseo.fr>

Hello Rick, I'm very interested in your bootloader, but since I use the CCS compiler, I noticed that the "long" reset vector (3 words) used by the compiler wasn't compatible with your implementation, and that it would be nice to use a HEX file coming right from the compiler or MPLAB. That's why I modified your code :- the loader copies a 3-word reset vector (0x0000 to 0x0002) to 0x0EFC or 0x1EFC (depending on memory)- the Intel-HEX loader automatically strips any CONFIG bits information from the downloaded file- the UART works at 9600 bps with a 20 MHz crystalBy doing this, you should be able to download any file generated by MPLAB or CCS without any modification.The modified loader should detect either short (1 word) or long (3 words) vectors now located at 0x0000 as usual, but if you use assembly language but don't useninterrupts, please avoid writing your code right from 0x0000 ("no RESET vector").Please find enclosed the modified source. It should work, but I haven't got enough time to check it out carefully (the basic tests were successful).Hope this helps. Best regards, Richard PERDRIAU
picldr13.zip



   From:              Antonio L Benci <Nino.Benci@
 Organization:          Monash University
         To:              dontronics.com
I've attached a modified version of Rick Farmers/Richard Perdriau PicLoader1.3 software. I was wondering if you could add it to the current page that you provide.

Brief description follows...

Version 1.3 modified to version 1.3a . If no user image is found the standard copyright message is displayed. If a user image is found the copyright message is held back until user intervention. The BOOTIMER process is always displayed until either user intervention is detected or time-out occurs. When user intervention is detected the copyright message is displayed, else the user code is run. Also the RS232 setting have been altered to permit 9600 baud @ 8 MHz.

These modifications were done for a particular project.

The ZIP file contains The ASM file, an HEX file created from the project and an MPLAB PRJ file.
Cheers.. Nino.
picld13a.zip


Subject:         PIC Bootloader
   Date:         Wed, 03 Oct 2001 16:12:27 +1000
   From:        Angelo Fraietta <angelo@
     To:         dontronics.com

I have made a modification to the Pic boot loader located at http://www.dontronics.com/rfarmer.html
It suppress the compiler messages and warnings. Please find attached the modified source

Angelo Fraietta
PO Box 859
Hamilton NSW 2303
Home Page
http://www.users.bigpond.com/angelo_f/

picld13b.zip
 
 

Dontronics Home Page


Copyright © 1996-2006 Dontronics