Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Debug module for MCS51 series microcontrollers. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Microcontrollers

Comments on the article Comments on the article

The development of devices on microcontrollers (MC), as a rule, is carried out according to a simple plan: the MC in a typical inclusion is "weighted" with the necessary peripherals, then the software is written. In this case, you have to use various tools that take on routine work, leaving the programmer to solve creative problems.

The device described below is a "semi-finished product" of a microcontroller system, a tool for its debugging and an object of study at the same time. It is intended for acquiring programming skills and debugging programs for the MCS51, but it can also serve as a model of a real system, allowing debugging application software together with the control object. Having such a module, the developer will be relieved of the need to often use a programmer or ROM emulator, which is inaccessible to many due to the high cost.

Schematic diagram of the debug module for MK MCS51 series is shown in the figure. Most of the nodes are made according to standard schemes, and the interface device with the serial port of a personal computer (PC) is borrowed from the device described in the article by S. Kuleshov and Yu. Zaumenny "ROM programmer" ("Radio", 1995, No. 10, p. 22 -25). You can connect various peripheral devices to the free pins of the ports P1 and P3 of the microcontroller DD1 (they end with arrows in the diagram). The XP1 plug is connected with a cable to the socket of one of the serial ports of the PC, under which the module will operate.

Debug module for MCS51 series microcontrollers
(click to enlarge)

After the supply voltage is applied, the capacitor C3 is charged through the resistor R1. According to the reset signal RES generated by the DD3.4 element, MK DD1 goes into its initial state and performs preparatory operations, including setting the logic level 1 on all pins of the P3 port. The trigger on the elements DD3.1, DD3.2 is in a state when its output signal sets such a memory distribution that the program memory address area 0-7FFFH occupies ROM (DD5), and 8000H-0FFFFH occupies RAM (DD6). The program Monitor, located in the ROM, is being executed. By typing the Monitor commands on the PC keyboard, the operator can work with the RAM and peripherals of the module.

To transfer the trigger to another state, it is necessary to send the RESET Monitor command described below from the control PC, which sets the MOD=0 signal. The addresses of the RAM and ROM of the program memory are interchanged and the program, previously entered by the operator in the RAM of the module, starts working. This allows you to emulate the operation of a real device and check programs translated to lower memory addresses, for example, prepared for writing to ROM. The SB1 button is used to reset the MK to its original state without changing the memory allocation. The Monitor can only be restarted by pressing the SB2 button or by turning the power off and on again. This allows debugged programs to freely operate on the state of the P3 port (for example, working with peripherals) without fear of accidentally switching memory allocation.

The HL1 LED serves as the simplest means of displaying information and is very useful, especially if there is no connection with the PC for one reason or another. After power is applied, it blinks at a frequency of approximately 1 Hz, which indicates that the Monitor is working. The zener diode protects the device from reverse polarity or overvoltage of the +5 V power supply.

The Monitor program (Table 1) provides control of the module and its interaction via the RS-232C serial port with a PC, from which the commands and data necessary for working on a specific task are transmitted. Through the same port, the PC receives and displays the results of the module operation on its screen. The communication program "Telemax" from the widely used shell Norton Commander 5.0, "Hyper Terminal" from Windows 95 OSR2 or similar must be running on the PC. In extreme cases, you can do without a special program, simply by sending the MS DOS command files with prepared data to the PC serial port.

Debug module for MCS51 series microcontrollers
(click to enlarge)

When configuring the communication program, you should delete the modem initialization lines, set the "Local echo" and "CR/LF broadcast" modes, if necessary, select the ANSI terminal and the ASCII code table. The serial port operating mode should be as follows: speed - 4800 baud, number of bits per character - 8, parity control disabled, number of stop bits - 1. If everything is correct, the text typed on the PC keyboard will go to the debug module, and its responses - displayed on the screen.

Monitor commands can be typed in both upper and lower case keyboards. All characters must be in ASCII encoding. The [BackSpace] key removes the last entered character from the buffer of the debug module. Each instruction consists of a name and an operand. The name is terminated by a separator character: space, tab, line feed, or carriage return. Further, we will conditionally denote it with an underscore (_), but you can enter any of the named ones.

Having received the delimiter, the Monitor compares the first four characters previously received and located in the buffer with the contents of the instruction table in the ROM. Having found a match, it remembers the address of the command handler from the same table and starts accepting an operand - one or more hexadecimal numbers. We agree that one- and two-byte addresses of the internal and external memory of the MK will be designated XX and XXXX, respectively, the block length is YYYY, other data is ZZ or ZZZZ. For example, XXXX,YYYY is a block of external data memory starting at address XXXX, with a length of YYYY bytes. All leading zeros must be specified. The operand must also end with a delimiter, upon receipt of which the command handler is started. A delimiter entered into an empty buffer is ignored.

RESET_ ZZZZ_ - the second mode of memory allocation is turned on, the MC is reset, control is transferred to the address ZZZZ. The command requires good RAM for normal operation.

DATA_ XXXX:_ ZZ_ [ZZ_][XXXX:_ZZ_ [ZZ_]._- information is entered into successive cells of the external data memory, starting from address XXXX . You do not need to enter square brackets, they only indicate that the number of ZZ_ operands can be arbitrary. Data entry ends with a dot. In table. Figure 2 shows an example of using the DATA and RESET commands to enter a simple program into RAM and run it.

READ_XX_ or READ_XXXX_ - reads a word (two consecutive bytes) from memory cells of the internal or external data RAM. The result as a hexadecimal number (byte at high address first) is sent to the serial port.

WRITE_XX,ZZ_, WRITE_XX,ZZZZ_, WRITE_XXXX,ZZ_ or WRITE_XXXX,ZZZZ_ - writes byte ZZ or word ZZZZ at address XX or XXXX.

Note that the READ and WRITE commands are implemented using indirect addressing, so they cannot work with special function registers. To access registers, you should write exchange procedures with direct addressing specifically for each of them. An example is the SPEED command handler. If an MCU with 256-byte internal RAM is installed in the module, the READ and WRITE commands will be able to work with its additional 128 bytes at addresses 80H-0FFH.

LOAD_XXXX,YYYY_ - filled with information coming through the serial port, block of external data memory.

SAVE_XXXX,YYYY_ - the contents of the external data memory block are transferred to the serial port.

CALL_ZZZZ_ - a subroutine is called starting from address ZZZZ. To return to the Monitor, it must end with the RET command. Interrupts are disabled for the duration of the subroutine.

CHECK_XXXX,YYYY_ - the checksum is calculated - the low byte of the sum of all bytes of the external data memory block.

FILL_XXXX,YYYY,ZZ_ - fills the external data memory area with the ZZ byte and calculates its checksum.

COPY_XXXX,YYYY,ZZZZ_ or COPY_PXXXX,YYYY,ZZZZ_ - the block of external data memory is copied to address ZZZZ. The P symbol indicates that the area to be copied is in program memory. At the same time, the checksum is calculated.

TEST_XXXX,YYYY_ - the health of the external RAM block is checked. If there are no errors, the message "OK" is displayed, otherwise - "XXXX: YY<>ZZ", where XXXX is the address of the failed cell, YY is the value written to it, and ZZ is the value read. The command does not destroy the contents of RAM.

SPEED_ZZ_ or SPEED_ZZ+_ - changes the speed of data exchange through the serial port. It defaults to 4800 baud (determined by the Monitor program byte at address 2DH). The value equal to the ZZ operand is placed in the TH1 register of the microcontroller and determines the speed of its transceiver. A plus sign in the operand doubles the speed by setting the PCON.7 bit.

The PC serial port can operate at 110, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600 baud and above. The ability to accurately tune the serial port of the MSC51 series microcontroller to the indicated speeds depends on the frequency of the used quartz resonator. For example, if it is 12 MHz, the port can be set to 300, 600, 1200, 2400, and 4800 baud with the SPEED command with operands 98, CC, E6, F3, and F3+ respectively. With an 11 MHz resonator, 9600 baud could be achieved. However, when transferring files, the MK will probably not be able to keep up with the data arriving at too high a speed.

The described set of commands can be expanded and supplemented without retransmission of the Monitor and even without erasing the ROM. The new command handler is placed in its free area. The command name (the first four characters in uppercase) is written starting at address 5ABH, followed by a two-byte handler address and byte 0FFH. The handler must end with a jump to address 23FH.

All single-byte cell addresses mentioned below refer to the internal RAM of the MCU. The monitor uses register banks 0 and 2, as well as locations 20H-3FH. The stack grows from address 50H. When free from receiving and processing commands, the microcontroller continuously executes the subroutine located in the ROM at the address specified in cells 35H and 36H. By default it is 063H. This subroutine, periodically changing the status of the P3.4 bit, turns on and off the HL1 LED. The flashing frequency depends on the contents of the 3DH cell. If this bit is to be used for other purposes, the WRITE_35,006A_ command should be issued.

In cells 37H and 38H is the address of the interrupt handler from the serial port, which actually serves as the backbone of the Monitor and determines its response to operator commands. By default, 0 is written here, which corresponds to calling the standard handler located in ROM at address 081H.

By writing a code other than 3 to address 0BH, you can activate the "Echo" function. All data received through the serial port will be sent back to the Monitor. This will turn off "Local echo" in the communication program, and, if necessary, save in a text file all commands sent to the debugging module and its responses to them.

The number at address 3AH sets the pause between the receipt of a command by the Monitor and the response to it, necessary for switching some communication programs from transmission to reception (this is not required for "Telemax"). It is equal to the duration of the pause in seconds multiplied by 50.

One of the results of commands that operate on memory blocks (LOAD, SAVE, CHECK, FILL, COPY) is the checksum of the block, which is placed in cell 39H. It can be used to control the correct execution of the listed commands.

The monitor can directly accept Intel HEX format files generated by many assemblers. It is enough to send such a file to the serial port of the PC using a communication program or simply with the MSDOS COPY <file name> COM2 command. The pre-used port (in this case COM2) must be configured with the MODE COM2:4800,N,8,1 command. The information will be written to the external data memory of the debug module, and if the checksums do not match, a corresponding message will be displayed.

Each line of an Intel HEX file begins with a colon followed by bytes represented by two-digit hexadecimal numbers without spaces:

  • the number of bytes of data contained in the line;
  • the high and low bytes of the address of the first of the data bytes;
  • null byte;
  • data bytes (their number is given by the first byte of the string);
  • check sum
  • low byte of the usual sum of all bytes of the string, taken with a minus sign.

A HEX file always ends with a line containing a colon and zero data bytes and an address, followed by the last line character (01) and a checksum equal to FF. Table 3 shows an example of such a file containing the same data as entered by the DATA Monitor command according to Table 2.

Author: V.Ogleznev, Izhevsk

See other articles Section Microcontrollers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Air trap for insects 01.05.2024

Agriculture is one of the key sectors of the economy, and pest control is an integral part of this process. A team of scientists from the Indian Council of Agricultural Research-Central Potato Research Institute (ICAR-CPRI), Shimla, has come up with an innovative solution to this problem - a wind-powered insect air trap. This device addresses the shortcomings of traditional pest control methods by providing real-time insect population data. The trap is powered entirely by wind energy, making it an environmentally friendly solution that requires no power. Its unique design allows monitoring of both harmful and beneficial insects, providing a complete overview of the population in any agricultural area. “By assessing target pests at the right time, we can take necessary measures to control both pests and diseases,” says Kapil ... >>

The threat of space debris to the Earth's magnetic field 01.05.2024

More and more often we hear about an increase in the amount of space debris surrounding our planet. However, it is not only active satellites and spacecraft that contribute to this problem, but also debris from old missions. The growing number of satellites launched by companies like SpaceX creates not only opportunities for the development of the Internet, but also serious threats to space security. Experts are now turning their attention to the potential implications for the Earth's magnetic field. Dr. Jonathan McDowell of the Harvard-Smithsonian Center for Astrophysics emphasizes that companies are rapidly deploying satellite constellations, and the number of satellites could grow to 100 in the next decade. The rapid development of these cosmic armadas of satellites can lead to contamination of the Earth's plasma environment with dangerous debris and a threat to the stability of the magnetosphere. Metal debris from used rockets can disrupt the ionosphere and magnetosphere. Both of these systems play a key role in protecting the atmosphere and maintaining ... >>

Solidification of bulk substances 30.04.2024

There are quite a few mysteries in the world of science, and one of them is the strange behavior of bulk materials. They may behave like a solid but suddenly turn into a flowing liquid. This phenomenon has attracted the attention of many researchers, and we may finally be getting closer to solving this mystery. Imagine sand in an hourglass. It usually flows freely, but in some cases its particles begin to get stuck, turning from a liquid to a solid. This transition has important implications for many areas, from drug production to construction. Researchers from the USA have attempted to describe this phenomenon and come closer to understanding it. In the study, the scientists conducted simulations in the laboratory using data from bags of polystyrene beads. They found that the vibrations within these sets had specific frequencies, meaning that only certain types of vibrations could travel through the material. Received ... >>

Random news from the Archive

B flat black hole 01.04.2004

Astronomers at the University of Cambridge (England), studying a giant cloud of gas surrounding the cluster of galaxies in the constellation Perseus, 250 million light-years from Earth, found concentric circles in this cloud.

These densified and rarefied regions of gas are only visible in the X-ray range (heated gas generates X-rays).

In essence, the researchers say, we are seeing ultra-low sound emitted by a black hole that sits at the center of a cloud of gas. This is a B-flat note, it is 57 octaves below the middle octave audible to the human ear.

Other interesting news:

▪ Sport bracelet Realme Band 2

▪ Nintendo Switch

▪ Short daylight hours affect mental ability

▪ Portable speaker Sony Extra Bass SRS-XB33

▪ The Greenland ice sheet is melting catastrophically

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ site section Power Amplifiers. Article selection

▪ Soren Kierkegaard article. Famous aphorisms

▪ article Why do we walk in circles when we get lost? Detailed answer

▪ article From the history of geographical maps. Travel Tips

▪ article Portable electric spot welding machine. Encyclopedia of radio electronics and electrical engineering

▪ article Power supply, 60 volts 0,1 amps. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024