skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: 8051 Tools PAULMON Monitor Manual Program Headers

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

Program Headers For Use With PAULMON2

Programs developed to run with PAULMON2 may begin with a 64 byte header, which allows PAULMON2 to detect that a program is stored in memory. There are currently four types of program headers: These 64-byte headers must begin on a 256-byte page boundry.

Normal Programs

Placing this type of a header on a program makes it appear in the Run Command menu. For example, the lines to add at the beginning of the program:
.equ    locat, 0x8000           ;Location for this program
.org    locat
.db     0xA5,0xE5,0xE0,0xA5     ;signiture bytes
.db     35,255,0,0              ;id (35=prog)
.db     0,0,0,0                 ;prompt code vector
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;user defined
.db     255,255,255,255         ;length and checksum (255=unused)
.db     "Program Name",0	;max 31 characters, plus the zero
.org    locat+64                ;executable code begins here
Admittedly using the Run Command instead of the Jump Command isn't a big advantage. The most compelling reason to use the normal program header is because it is later quite easy to change it into the startup header.

Start-Up Program

By changing a byte in the header, a normal program can be turned into a startup program. After PAULMON2 has initialized the hardware, and after the baud rate and serial port are initialized, but before the welcome message and prompt are printed, PAULMON2 will run all of the startup programs.

Startup programs are really only useful when used with nonvolatile memory. With Flash ROM, programs may be written via the Download command, but they will remain in memory.

Instead of replacing PAULMON2 (at 0000), the final application program can be turned into a startup program by changing a byte in it's header. If Flash ROM is used, the board will always startup to the intended program. The lines to add to define a startup header should look like this:

.equ    locat, 0x8000           ;Location for this program
.org    locat
.db     0xA5,0xE5,0xE0,0xA5     ;signiture bytes
.db     253,255,0,0             ;id (253=startup)
.db     0,0,0,0                 ;prompt code vector
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;user defined
.db     255,255,255,255         ;length and checksum (255=unused)
.db     "Program Name",0        ;max 31 characters, plus the zero
.org    locat+64                ;executable code begins here
PAULMON2 has a feature where an erase pin may be defined. If this pin is held low after a reset as PAULMON2 starts up, it will attempt to erase the Flash ROM. By providing a jumper which pulls this pin low when installed, the application program (in Flash ROM) may be deleted and a new version may be downloaded without having to pull the EPROM, as would be necessary in a system without PAULMON2 and Flash ROM. The default erase pin is P3.5 (T1, pin 15).

The startup program header feature is intended work together with Flash ROM to provide a quick and easy way to make the application under development permanent, without pulling any chips, without having to worry if the program will correctly initialize the hardware without having run PAULMON2 first, and with a simple (and well tested) mechanism to erase and download a new version of the permanent startup program should changes become necessary.

In some cases, it may be desirable to install a startup program which initializes hardware or performs some startup function but then allows PAULMON2 to begin normally. In this case, the startup program must terminate with a RET instruction to return back to PAULMON2. Obviously the stack must point to the return address which PAULMON2 originally pushed before running the startup program.

Start-Up Program (hardware init)

It should be noted that normal (code 253) startup programs are run after the baud rate and serial port is configured, so that they may perform serial I/O with the 8051's hardware configured exactly as it would have been if the program were download and run normally. In most permanent applications, the automatic baud rate detection (requiring a carriage return after power is first applied) is not desirable. A second type of startup program is available (type 249 instead of 253) that PAULMON2 will run before doing automatic baud rate detection.

This type of startup program is normally only used to avoid the automatic baud rate detection. The fix_baud.asm example program shows how this should be done. The value for "baud_const" is required. This can be found by running the my_th1.asm, which will tell you the value that the automatic baud rate detection guessed at startup.

These two programs can also be downloaded in a ZIP File.

It is also possible to customize PAULMON2 with a fixed baud rate for use the hardware's crystal frequency.

Commands

Perhaps the most interesting use for program header is to add additional commands to PAULMON2. The List, Single-Step, and Memory Editor which come with versions of PAULMON2 that fit in 8k are actually examples of programs with headers that make them appear as commands within PAULMON2. A header for a command should look like this:
.equ    locat, 0x8000           ;Location for this program
.org    locat
.db     0xA5,0xE5,0xE0,0xA5     ;signiture bytes
.db     254,'A',0,0             ;id (254=command, key='A')
.db     0,0,0,0                 ;prompt code vector
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;reserved
.db     0,0,0,0                 ;user defined
.db     255,255,255,255         ;length and checksum (255=unused)
.db     "Command Name",0        ;max 31 characters, plus the zero
.org    locat+64                ;executable code begins here
In this example, the command will be executed when the user presses the 'A' key. The specified character must be uppercase, because PAULMON2 calls the upper function to make the user interface case insensitive.

For more detailed information about Adding Commands to PAULMON2, and some examples, please refer to that section.


PAULMON2 Documentation, Paul Stoffregen
http://www.pjrc.com/tech/8051/pm2_docs/headers.html
Last updated: February 24, 2005
Status: This page is finished
Suggestions, comments, bug reports??? <paul@pjrc.com>