PicPuter

  Home
  Products
  Contact

Using

  Download
  Manual
  Examples
  UserGroup

Development

  Revision
  Future
  Bugs

Other

  DLHexRec
  Modd Audio
  Veracity
  DSP
  Blinky

Miscellaneous

  Links
  Search
  Obsolete
  Site Design
  Disclaimer

 
.
Other : Intel Hex Record Downloader

Note: This is not the same bootloader as picputer. Its bootloader is a bit more advanced, but is also larger.

This small PIC16F87x program allows you to program your micro controller via the serial port. It interprets _HEXREC_ and performs the writes to the internal flash memory. You simply take your file.hex, created by the assembler, and send the file through the serial port. This program will interpret the file and perform the writes to flash. I use Hyper Terminal to program my PIC16F876 micro controller by using the "Send Text File" menu option!

It was designed to be easy to use and features a small 128 instruction footprint. It is placed at $0780 to $07FF, although it is easily relocated. As long as your program avoids these 128 memory locations you can incorporate it in with your programs. To run the download routine simply "CALL 780H".

The sample main.asm file, provided with the source, in the download uses a 2-statement bootstrap that runs the download only if PORTC.4 is LOW at reset. This pin is commonly used for a button on many pic boards.
  ORG     0
	BTFSS	PORTC,4
	goto	780h ; goto download routine if PORTC.4 LOW
	GOTO    Main
You may need a pull up resistor so PORTC.4 reads HI, try using a 2.2K resistor connected from +5V to PORTC.4.


 
Hardware Requirements


You MUST implement hardware __FLOWCONTROL__ on the serial port, or half of it anyway. The RS232 CTS pin allows you to suspend the sender.

It will also work it you add a delay at the end of each record even without CTS.

The way this program works is it reads in a line containing a record from the serial port, stops transmission using the CTS signal, flashes its internal memory, restarts transition using the CTS pin, waits for next line. The CTS signal is hook up to pin 24 micro controller, through the MAX232 chip, to pin 8 on the UART port. The RTS signal is unused and should be left floating.

Unfortunately most PIC hardware does not implement the CTS signal, but the modification is usually quite easy. I modified a Dontronics DT003 and DT001 board using only 2 jumpers.

The terminal program should be set to:
 Baud        : 57600
 Data Bits   : 8
 Parity      : None
 Stop Bits   : 1
 Flow Control: Hardware



 
Download


The download is available, free of charge. It is released under The GNU Lesser General Public License. It contains the source code and a pre built hex file used to program a chip running at 18.432 MHz. PicPuter uses a more advanced version of this code which is ok under the Lesser GNU License. This code is the bare minimum hex rec downloader and does not verify or use the checksum.


 
Using


Once the chip is programmed and running, you should see a spinning cursor on the terminal program. If you do not see it, check your TX wiring. Once you see the cursor spin you simply send the _HEXREC_ file through the serial port. Every valid record will print an asterisk, so if everything went ok you should see something like this.
|******************|
If you did not see any * check your RX or CTS wiring. Also make sure the terminal program is set to hardware flow control.

Only the addresses in the _HEXREC_ are altered, no erase is performed. So the download routine only needs to be flashed once.


 
Modifications


The firmware must know the frequency of the crystal in order to set the baud bate for the serial port correctly. The following lines in the source file download.asm can be modified to select the frequency of the crystal. Other frequencies are possible, especially at lower baud rates, but the equation x = (frequency/baud)/16 should result in an integer to prevent clock error.
XTAL_FREQ   EQU  D'18432000'

You can change the baud rate for the serial port by modifying the BAUD_PERIOD equate.
BAUD_115200 EQU ((XTAL_FREQ/D'115200')/D'16')-1
BAUD_57600  EQU ((XTAL_FREQ/D'57600')/D'16')-1
BAUD_38400  EQU ((XTAL_FREQ/D'38400')/D'16')-1
BAUD_19200  EQU ((XTAL_FREQ/D'19200')/D'16')-1
BAUD_9600   EQU ((XTAL_FREQ/D'9600')/D'16')-1
BAUD_PERIOD EQU BAUD_57600

 
DLHexRec.hex


Here are the hex records for the entire program. Once you flash this into the PIC16F87x chip, you can begin using the serial port to download similar files!

(These hex records assume a crystal frequency of 18.432 MHz)
:06000000071E802F0029FD
:02020000802F4D
:100F00008B0183019801831698019F30870013306D
:100F10009900243098008312981718160A30990007
:100F20000D309900FA277C309C275C309C272D30AF
:100F30009C272F309C27932FA000A101A2016400C1
:100F40008C1ABB2FA10B9F2FA20B9F2F083099004B
:100F500020089900080000088016001BA93E001A0E
:100F6000D03E0F39840308000313AB27A100A10E64
:100F7000AB27210708001A088000F33E031C080075
:100F80000319C42F8403080087166F3084000008FB
:100F9000C63E031DFA2F8403B427A200A20C031936
:100FA000FA2FB42703178F00C039031DFA2FB42777
:100FB00003178D00003E8F0C8D0CB427B427031748
:100FC0008C000313B42703178E0083168C170C159F
:100FD0008B1355308D00AA308D008C14000000005A
:100FE0000C1183128D0A03198F0A0313A20BDE2F33
:100FF0002A30990003136F308400800187120800A3
:02400E00763FFB
:00000001FF

This webpage is © Copyright 2001,2002,2003 by Todd Modjeski - All Rights Reserved - built Tue Nov 4 20:38:51 2003