⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot51.doc

📁 一份51的编译程序,dos版本的. 英文名字MCS-51 Microcontroller Family Macro Assembler
💻 DOC
📖 第 1 页 / 共 4 页
字号:

   PC serial port:                                  MCS-51 target system:

        pin

    Tx   2  o----------------------------------------->  RXD

    Rx   3  o----------------------------------------->  TXD

   RTS   4  o-----+
                  |
   CTS   5  o-----+

   DSR   6  o-----+
                  |
   DCD   8  o-----+
                  |
   DTR  20  o-----+----------------------------------->  Reset

ground   7  o----------------------------------------->  ground


Shortening the modem control signals is absolutely required for batch
operation under MS-DOS! If the CTS-, DSR-, or DCD-input is not set to
logic low (+12V), the PC will hang during character output to the serial
port.
For shell script operation under Linux, only the Tx-, Rx-, and ground
lines are required, and the handshake inputs may be left open.
The same is true for interactive operation with most terminal emulation
programs. (For further information refer to the documentation of your
terminal emulation program.)
If there is a spare RS-232 line receiver on your MCS-51 board, it can be
employed as a reset input! In this case, the target system can be reset
in batch (or script) files with the reset program provided, and from terminal
emulation programs (by dropping the DTR output with the hang-up function).


   RS-232 cable with 9-pin female D-Shell connector:
   -------------------------------------------------

   PC serial port:                                  MCS-51 target system:

        pin

    Rx   2  o----------------------------------------->  TXD

    Tx   3  o----------------------------------------->  RXD

   RTS   7  o-----+
                  |
   CTS   8  o-----+

   DCD   1  o-----+
                  |
   DTR   4  o-----+----------------------------------->  Reset
                  |
   DSR   6  o-----+

ground   5  o----------------------------------------->  ground


If you own a 9/25-pin mouse adaptor with all pins connected, the 9-pin
version of the cable should be preferred!
If your MCS-51 board has no spare RS-232 line receivers, but a TTL reset
input (or you can establish one), the target system can also be reset in
batch (or script) files over a printer port of the PC.
For this, a suitable reset cable must be tailored as shown below:


   Reset cable with 25-pin male D-Shell connector:
   -----------------------------------------------

   PC printer port:                                 MCS-51 target system:

            pin

        D0   2  o----------------------------------------->  Reset
                                                             _____
        D1   3  o----------------------------------------->  Reset

    ground  25  o----------------------------------------->  ground


In practice, only one of the two reset lines will be required.
When the reset program is invoked, a positive reset pulse appears
at D0 (8031, 8032), and a negative pulse at D1 (80C535, 80C537).
For detailed information on the reset program, refer to chapters
"III.2 Batch File Operation under MS-DOS", and
"III.4 Shell Script Operation under Linux".



II.4 Design of MCS-51 Evaluation Boards
---------------------------------------
When developing embedded systems, debugging aspects should be taken into
account as soon as possible. That is why MCS-51 prototype boards should
always be armed with a download RAM in the hardware design phase, even if
the serial model (probably) doesn't need an external RAM!
A $3 RAM can save a $3000 in-circuit emulator and weeks of trouble!

Before discussing the basic concepts of program download, it is essential
to understand the memory organization of the MCS-51 architecture.
First of all, there is an 8-bit address space for internal RAM. Parts of
it are directly addressable (DATA space), indirectly addressable (IDATA
space), or bit-addressable (BIT space). These address spaces are fully or
partly overlapping. Furthermore, the four register banks and the Special
Function Registers (SFR) are mapped into this internal address space. This
is hard to understand for newbies, but plays no role for program download.
Aside of the internal memory, the MCS-51 architecture provides a bus
interface for external memory. There are two separate 16-bit address spaces
for 64K of program memory (ROM) and 64K of data memory (RAM). Program memory
(CODE space) can only be read with the -PSEN bus signal, and data memory
(XDATA space) can be read and written with the -RD and -WR bus signals.
The -PSEN signal becomes active during instruction fetch cycles and MOVC
instructions. The -RD and -WR signals become active during read and write
operations with MOVX instructions.

The obvious problem is: a downloaded program can only be stored in external
RAM, mapped into the XDATA space, whereas program code can only be executed
from memory in the CODE space.
There must be a way to execute a downloaded program, although it is stored
in external RAM! Fortunately, there is a simple trick to solve this:
The -OE input of the (usually static) RAM must be driven by a logic AND of
the -RD and -PSEN signals of the MCU, rather than by -RD alone. That's all!
Then the external RAM can be read and written with MOVX instructions (using
-RD and -WR), and program code can be executed from it (using -PSEN).

For example, a typical 8051 evaluation board could be designed as follows:
A 32K EPROM (e.g. 27C256) is mapped into the CODE space from address 0000H
to 7FFFH, containing BOOT-51 at address 0000H.
A 32K static RAM (e.g. 62256) is mapped into both the CODE and XDATA spaces
from address 8000H to FFFFH.
After reset, the MCU starts program execution at address 0000H, and BOOT-51
is running, waiting for commands. When it receives an UPLOAD command from
the host computer, it reads an Intel-HEX file and stores it at its start
address in the external RAM (e.g. 8000H). If BOOT-51 receives a GO TO 8000
command, it jumps to the specified address 8000H, and the downloaded program
is running.
A memory map like this can be obtained with a minimum of hardware:
The -CE (chip enable) input of the EPROM must be driven by the A15 signal
(P2.7) of the MCU, and -CE of the RAM with the inverted A15 signal
respectively, to avoid bus conflicts in the CODE space.
The -OE (output enable) input of the EPROM must be driven by the -PSEN
signal of the MCU, as usual for CODE memory.
The -WE (write enable) input of the RAM must be driven by the -WR signal
(P3.6) of the MCU, as usual for XDATA memory.
Only the -OE (output enable) input of the RAM must be driven by that famous
logical AND of the -RD and -PSEN signals of the MCU, to map the RAM into
both the XDATA and CODE space. That's it!

Because this is so simple, cheap and (in contrast to many in-circuit
emulators) absolutely reliable, most MCS-51 family evaluation boards are
working like this or similar.
In most cases, it is easy to establish a suitable memory map, even on
target boards that do not originally support it.

If there is no spare AND gate, it may also do, to simply connect the -OE
input of the RAM to the -PSEN signal of the MCU only. In this case, the RAM
can still be written, but no longer be read with MOVX instructions. Since
program code can also be executed from it, this minimized version can still
be used as download RAM, but no longer as external data RAM.
(In cases of emergency, it can be read with MOVC instructions, however!)



III. BOOT-51 Operation
----------------------
When BOOT-51 is customized correctly, and the target board is connected to
the host PC with the cable(s) described above, we can start to upload and
run application programs. There are two possible modes of operation:

  - interactive operation
  - batch operation



III.1 Interactive Operation
---------------------------
BOOT-51 implements a simple ASCII user interface for serial communication.
The bootstrap program can be operated interactively with a terminal emulation
program running on the PC (e.g. TELIX under MS-DOS, or minicom under Linux).
To perform this, start your terminal emulation program, and configure it for
the correct baudrate, 8 data bits, 1 stop bit, no parity, and no handshake.
Then reset the MCS-51 target system.
(If you have established an RS-232 reset line, the target system can usually
 be reset by dropping the RS-232 DTR output with the "hang-up" function!)
Now the BOOT-51 sign-on message should appear on your screen:

        BOOT-51  V1.1           Copyright (c) 2002 by W.W. Heinz

        >

The '>' character indicates that the BOOT-51 command line interpreter is
ready for input. It implements exactly two commands:

1. The UPLOAD command:
   First press the 'U', and then the return key.
   Now the upload prompt ':' should be displayed. BOOT-51 is now ready to
   receive an application program in Intel-HEX format. Send an Intel-HEX
   file with the ASCII upload function of your terminal emulation program.
   (Be sure that it terminates every line with a CR and/or LF character!)
   Now the received Intel-HEX records are loaded to their start addresses
   specified in the record headers. If an EOF record is received, the upload
   is terminated and the command prompt '>' is displayed again. Now the
   command line interpreter is ready for the next command.
   When a format error is detected in the Intel-HEX file, BOOT-51 waits
   until no more characters are received for about two seconds, and then
   aborts with a corresponding error message.  (see Appendix C)

2. The GO TO command:
   To start an application program at address 8000H, enter "G 8000" and
   press return. BOOT-51 sets now all MCU registers to reset conditions
   (as far as possible), and jumps to the start address specified.
   Now the previously loaded application program should be running!

Any desired number of Intel-HEX files may be loaded, before entering the
'G' command. The commands may be entered in upper or lower case letters.
Interactive operation should be preferred, if the application program
performs serial I/O. This can easily be supervised with the terminal
emulation program. In interactive mode, only an RS-232 reset output is
applicable. (A printer port reset cable would be of little use!)



III.2 Batch File Operation under MS-DOS
---------------------------------------
If serial I/O is only used for program upload, batch file operation may be
the most convenient way of testing with the shortest turn-around cycles.
The sample batch job below, shows the principles of operating BOOT-51 from
a PC with MS-DOS batch commands:

        MODE COM2:9600,N,8,1,P
        RESET51 LPT1
        SLEEP 9600
        ASEM %1
        ECHO U >COM2
        COPY %1.HEX COM2
        ECHO G 8000 >COM2

In this example, serial I/O is done over serial port COM2, and the target
system can be reset over printer port LPT1.
First of all, the serial port COM2 is initialized to the desired baudrate
of 9600 Baud, 8 data bits, 1 stop bit, and no parity with the MODE utility.
Then the RESET51 program provided is executed to reset the target system via
printer port LPT1. After that, the SLEEP program waits until BOOT-51 has
fully output its sign-on message at 9600 Baud and is ready for a command.
To give the MCS-51 board some more time to recover from reset, ASEM-51 is
now invoked to assemble the application program.
When finished, the BOOT-51 upload command 'U' is ECHOed to COM2, and the
Intel-HEX file is also simply copied to the serial port.
Finally the application program is started at address 8000H with the
command "ECHO G 8000 >COM2".
To test an application program MYPROG.A51 with the above batch job (stored
in a file TEST51.BAT), simply type

        TEST51 MYPROG

at the DOS prompt, and see what you get.
Of course this was only a minimized example! In general you will not only
have to modify serial port, baudrate, reset port, and start address for
your local requirements, but also to do something for plausibility checking
and error handling.
For this, the more sophisticated batch file BOOT.BAT has been provided.
It allows an easy change of all configuration parameters with any ASCII
editor. For further information see the commentary inside BOOT.BAT.
In principle, BOOT.BAT contains only those configuration data!
(The actual work is done by another batch file UPLOAD.BAT provided,
 which is invoked by BOOT.BAT.)
A program MYPROG.A51 can now be assembled, uploaded and started with

        BOOT MYPROG



III.3 DOS Upload Utilities
--------------------------
The BOOT-51 package for DOS/Windows contains the utilities COMPORT.EXE,
RESET51.EXE, and SLEEP.EXE, which are usually invoked by UPLOAD.BAT, but
can also be used separately.


COMPORT
-------
sets <baudrate> and data format of a PC serial <port>:

        COMPORT <port> <baudrate> [<parity> [<databits> [<stopbits>]]]

Legal parameter values are:

        <port>:        AUX, COM1, COM2, COM3, COM4
        <baudrate>:    1.66 < baudrate < 121000
        <parity>:      N, O, E, M, S     (default: N)
        <databits>:    5, 6, 7, 8        (default: 8)
        <stopbits>:    1, 1.5, 2         (default: 1)

The port names AUX and COM1 are equivalent.
COMPORT allows to set very low, very high, and very odd baudrates, which
can be generated by the 16C450 UART of the PC (and the 8051 board), but
are not supported by the PC BIOS or the MS-DOS MODE command.
Baudrates that cannot be generated exactly are accepted as long as the
deviation doesn't exceed 5.0 %. COMPORT displays the "real" baudrate and
the relative deviation (if any) from the nominal value.
The parity can optionally be set to N (none), O (odd), E (even), M (mark),
or S (space). Furthermore, the data format can be set to 5, 6, 7, or 8
data bits, and 1, 1.5, or 2 stop bits.
Default settings are: no parity, 8 data bits and 1 stop bit.

Note:  only 6, 7 or 8 data bits may be combined with 1 or 2 stop bits.
       5 data bits are only possible with 1.5 stop bits!

Example 1:      COMPORT COM4 12800
----------
                Sets the serial port COM4 to 12800 Baud, no parity,
                8 data bits, and 1 stop bit.


RESET51
-------
forms a reset pulse of the duration <pulsewidth> at the D0 and D1 outputs
of a PC printer <port>, or at the DTR output of a serial <port>:

        RESET51 <port> [<pulsewidth>]

Legal <port> values are:  PRN, LPT1, LPT2, LPT3,
                          AUX, COM1, COM2, COM3, COM4,
                          NUL

PRN and LPT1 are equivalent, and so are AUX and COM1.
The optional parameter <pulsewidth> is the duration of the reset pulse in ms.
Legal values are:  1 <= <pulsewidth> <= 65535.  (default is 50)
When invoked without parameters, a help screen is displayed.
In case of error, RESET51 returns the ERRORLEVEL 1, 0 otherwise.
When executed, RESET51 forms a positive pulse at D0 (pin 2), and a negative
pulse at D1 (pin 3) of a PC printer port, or a "high" pulse (-12 V !!!) at
the DTR output of a serial port respectively. If the NUL device is specified
as <port>, RESET51 delays only for <pulsewidth> ms.
If the default pulse width of 50 ms is too short to reset the MCS-51 board,
specify a greater pulse width.

Example 2:      RESET51 LPT2 500
----------
                Applies a reset signal to the D0 and D1 outputs of the
                printer port LPT2 for 500 ms.

RESET51 is running under MS-DOS, and in the DOS-Boxes of Windows 3.1x and 9x.
Windows ME does no longer provide a DOS-Box.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -