skip navigational linksPJRC
Shopping Cart Checkout Shipping Cost Download Website
Home Products Teensy Blog Forum
You are here: 8051 Tools Development Board Example Code Auto Startup

PJRC Store
8051 Board, $79
LCD 128x64 Pixel, $29
LCD 16x2 Char, $14
Serial Cable, $5
9 Volt Power, $6
More Components...
8051 Tools
Main Page
Software
PAULMON Monitor
Development Board
Code Library
89C2051 Programmer
Other Resources

Automatic Start-Up Of Your Application

Eventually, you will want to make your own application run automatically when you boot the board, instead of PAULMON2's menus. To accomplish this, you must do two things:

  1. Compile your application for the flash rom.
  2. Download the autostart code from this page.

When you reboot the board, the autostart code will run automatically. It will configure the baud rate, set up the interrupt vectors, and then jump to your code. The board will be permanently dedicated to run your application, unless you use the flash erase jumper to restore it to the original, erased condition.

Default Settings: Code at 0x8000, Baud Rate is 115200 Bits/sec

If the default settings are ok, then you can use the autostart example code without any modification. Just download the autostart.hex file (zip format).

This code resides in the memory from 0xF600 to 0xF7FF (the last 512 bytes of the flash), so your application must not use that memory. Of course, the full source code is available if you need that memory, or the default settings are not correct for your application.

Configuring Your Code's Build Location

If you are using SDCC, just change the --code-loc parameter in the Makefile, so that your application is built to reside entirely inside the flash rom, and rebuild the code (often times "make clean" or deleting the .hex file is needed). Usually 0x8000 is the best choice, so that your code begins at the beginning of the flash rom and has the maximum amount of space available. It should look like this:

--code-loc 0x8000

If you are using AS31, you will need to place a ".org" directive at the beginning of your code. For example:

        .org    0x8000

Before downloading the autostart.hex file, try using PAULMON2's "J" (Jump) command to jump to your code at 0x8000. If that works and you are ready to permanently dedicate the board to automatically running your application, then you are ready to download the autostart.hex file.

Erasing The Flash

After you have downloaded this "autostart.hex" file, your board will be permanently dedicated to running your own application code and PAULMON2's interactive menus will no longer be available.

jumpers
Figure 1: Once you've downloaded AUTOSTART.HEX, this FLASH ERASE
jumper is the only way to return to PAULMON2's interactive menus.

If you wish to return to PAULMON2's menus, you must use the flash erase jumper to erase the flash rom. Short the upper two pins together and keep them shorted while you press the RESET button. When the board resets, the flash rom will be erased and you will be returned to the PAULMON2 prompt, where you may further develop your application or use the board for a new purpose.

Customizing Baud Rate Setup

When you boot the board, a portion of the autostart code inserts some bytes into memory to configure the baud rate that PAULMON2 will use to initialize the serial port. Several common baud rates are defined in the code, so you can simply uncomment one if your baud rate in listed:

.equ    baud_const, 255         ;115200 baud w/ 22.1182 MHz          
;.equ   baud_const, 254         ;57600 baud w/ 22.1182 MHz
;.equ   baud_const, 253         ;38400 baud w/ 22.1182 MHz
;.equ   baud_const, 250         ;19200 baud w/ 22.1182 MHz
;.equ   baud_const, 244         ;9600 baud w/ 22.1182 MHz

If you need a different baud rate, you must compute the value for "baud_const", using this formula:

baud_const = 256 - (115200 / baud_rate)

Customizing Application Startup

The default setting is to configured for your application code to begin at 0x8000, which is the beginning of the flash memory. The autostart code is located from 0xF600 to 0xF7FF, the end of the flash memory. However, it is easy to change these by editing constants in the code:

; set this to the location where your application code begins.
; With SDCC, this is the value you used for --code-loc
; With AS31, this is the .org locations where your code was built

.equ    application, 0x8000


; set this to where you'd like these two auto-startup routines
; to be placed in the flash.  Normally 0xF600 is a good choice,
; to place this at the end of the flash (where it is least likely    
; to conflict with the space for your application).

.equ    location, 0xF600

Of course, the complete source code is provided, so you can edit the code to perform any customized startup you need. The normal code simply writes seven LJMPs into RAM in the 0x2000, so that the interrupts will jump to your interrupt code in the flash rom, and then jumps to your program's starting location.

For example, if the additional LJMP interrupt latency is not acceptable, you could modify the code to instead copy your interrupt handler to the RAM. Or perhaps you are not using interrupts and you want to avoid writing to the RAM during a reboot, in which case you could simply delete that section.

Download The Autostart Code



8051 Development System Circuit Board, Paul Stoffregen
http://www.pjrc.com/tech/8051/board5/autostart.html
Last updated: February 24, 2005
Status: finished
Suggestions, comments, criticisms: <paul@pjrc.com>