📄 boot51.doc
字号:
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-----+-----------------------------------> Resetground 7 o-----------------------------------------> groundShortening the modem control signals is absolutely required for batchoperation under MS-DOS! If the CTS-, DSR-, or DCD-input is not set tologic low (+12V), the PC will hang during character output to the serialport.For shell script operation under Linux, only the Tx-, Rx-, and groundlines are required, and the handshake inputs may be left open.The same is true for interactive operation with most terminal emulationprograms. (For further information refer to the documentation of yourterminal emulation program.)If there is a spare RS-232 line receiver on your MCS-51 board, it can beemployed as a reset input! In this case, the target system can be resetin batch (or script) files with the reset program provided, and from terminalemulation 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-----------------------------------------> groundIf you own a 9/25-pin mouse adaptor with all pins connected, the 9-pinversion of the cable should be preferred!If your MCS-51 board has no spare RS-232 line receivers, but a TTL resetinput (or you can establish one), the target system can also be reset inbatch (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-----------------------------------------> groundIn practice, only one of the two reset lines will be required.When the reset program is invoked, a positive reset pulse appearsat 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 intoaccount as soon as possible. That is why MCS-51 prototype boards shouldalways be armed with a download RAM in the hardware design phase, even ifthe 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 essentialto understand the memory organization of the MCS-51 architecture.First of all, there is an 8-bit address space for internal RAM. Parts ofit are directly addressable (DATA space), indirectly addressable (IDATAspace), or bit-addressable (BIT space). These address spaces are fully orpartly overlapping. Furthermore, the four register banks and the SpecialFunction Registers (SFR) are mapped into this internal address space. Thisis hard to understand for newbies, but plays no role for program download.Aside of the internal memory, the MCS-51 architecture provides a businterface for external memory. There are two separate 16-bit address spacesfor 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 MOVCinstructions. The -RD and -WR signals become active during read and writeoperations with MOVX instructions.The obvious problem is: a downloaded program can only be stored in externalRAM, mapped into the XDATA space, whereas program code can only be executedfrom memory in the CODE space.There must be a way to execute a downloaded program, although it is storedin 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 ofthe -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 0000Hto 7FFFH, containing BOOT-51 at address 0000H.A 32K static RAM (e.g. 62256) is mapped into both the CODE and XDATA spacesfrom address 8000H to FFFFH.After reset, the MCU starts program execution at address 0000H, and BOOT-51is running, waiting for commands. When it receives an UPLOAD command fromthe host computer, it reads an Intel-HEX file and stores it at its startaddress in the external RAM (e.g. 8000H). If BOOT-51 receives a GO TO 8000command, it jumps to the specified address 8000H, and the downloaded programis 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 signalrespectively, to avoid bus conflicts in the CODE space.The -OE (output enable) input of the EPROM must be driven by the -PSENsignal 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 famouslogical AND of the -RD and -PSEN signals of the MCU, to map the RAM intoboth the XDATA and CODE space. That's it!Because this is so simple, cheap and (in contrast to many in-circuitemulators) absolutely reliable, most MCS-51 family evaluation boards areworking like this or similar.In most cases, it is easy to establish a suitable memory map, even ontarget boards that do not originally support it.If there is no spare AND gate, it may also do, to simply connect the -OEinput of the RAM to the -PSEN signal of the MCU only. In this case, the RAMcan still be written, but no longer be read with MOVX instructions. Sinceprogram code can also be executed from it, this minimized version can stillbe 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 tothe host PC with the cable(s) described above, we can start to upload andrun application programs. There are two possible modes of operation: - interactive operation - batch operationIII.1 Interactive Operation---------------------------BOOT-51 implements a simple ASCII user interface for serial communication.The bootstrap program can be operated interactively with a terminal emulationprogram 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 forthe 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 isready 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 programperforms serial I/O. This can easily be supervised with the terminalemulation program. In interactive mode, only an RS-232 reset output isapplicable. (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 bethe most convenient way of testing with the shortest turn-around cycles.The sample batch job below, shows the principles of operating BOOT-51 froma 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 >COM2In this example, serial I/O is done over serial port COM2, and the targetsystem can be reset over printer port LPT1.First of all, the serial port COM2 is initialized to the desired baudrateof 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 viaprinter port LPT1. After that, the SLEEP program waits until BOOT-51 hasfully 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 isnow invoked to assemble the application program.When finished, the BOOT-51 upload command 'U' is ECHOed to COM2, and theIntel-HEX file is also simply copied to the serial port.Finally the application program is started at address 8000H with thecommand "ECHO G 8000 >COM2".To test an application program MYPROG.A51 with the above batch job (storedin a file TEST51.BAT), simply type TEST51 MYPROGat the DOS prompt, and see what you get.Of course this was only a minimized example! In general you will not onlyhave to modify serial port, baudrate, reset port, and start address foryour local requirements, but also to do something for plausibility checkingand 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 ASCIIeditor. 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 MYPROGIII.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, butcan 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, whichcan be generated by the 16C450 UART of the PC (and the 8051 board), butare not supported by the PC BIOS or the MS-DOS MODE command.Baudrates that cannot be generated exactly are accepted as long as thedeviation doesn't exceed 5.0 %. COMPORT displays the "real" baudrate andthe 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 8data 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 outputsof 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, NULPRN 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 negativepulse at D1 (pin 3) of a PC printer port, or a "high" pulse (-12 V !!!) atthe DTR output of a serial port respectively. If the NUL device is specifiedas <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 + -