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

Initialization of additional memory segments in programs for microcontrollers of the MCS-51 family. 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

Modern microcontrollers have a built-in non-volatile data memory (EEPROM), information in which sometimes needs to be entered before the device starts working. The image (firmware) of this memory must be formed during the development of the program. This can be done, for example, assemblers for microcontrollers of the PICmicro and AVR families. They give the programmer the opportunity to organize an additional memory segment and set the initial data in it for writing to the EEPROM.

Assemblers for microcontrollers with the MSC-51 core also allow you to divide the memory into several parts, but only in one of them - the executable code segment - initialization is possible. In all others, it is only allowed to reserve memory cells and write data to them only during the execution of the program. The way out of the situation can be the reception, which is described below. Its essence is the use of conditional assembly, as a result of which the initialization of the code segment occurs in different ways, depending on the translation conditions. The resulting HEX files can be used to program not only the internal EEPROM of the microcontroller, but also external memory chips.

Artificially created additional segments (any number of them is allowed) are placed in the program text before the real code segment. Labels defined in one of them will be known in all of the following, including the actual code segment. But links in the opposite direction are not allowed. There are no restrictions on the type and physical location of additional memory.

An example of a program with two additional initialized segments, conventionally named EEPROM and FLASH, is shown in Table. 1. After saving it in the example.asm file, we will use the ASEM-51 assembler, which can be "downloaded" for free at .

First of all, run the assembler on the command line

asem example.asm eeprom.hex/define:EEPROM

Processing the first lines of the program text, it will place the idEeprom, ptrWord and prtBufE labels in its symbol table, and the data specified by the DB and DW directives in the output file eeprom.hex (Table 2). The segment length will then be checked. If the value of the program counter exceeds the physically existing EEPROM size (in this case - 640 cells), an error message will be displayed. If the volume of the segment is obviously small, the check can be excluded. Similar checks can be envisaged in other segments.

Initialization of additional memory segments in programs for microcontrollers of the MCS-51 family
(click to enlarge)

Next, the assembler will encounter the IFNDEF EEPROM directive. Since a symbol with this name is defined on the command line ( /define:EEPROM parameter), all following lines of the program, up to the ENDIF directive, will be ignored and the translation will end there.

Run the retransmission of the same program from the command line

asem example.asm flash.hex/define:FLASH

It differs from the previous one only in the definition of the FLASH symbol instead of EEPROM. The first stage of translation will proceed exactly as described above, and the data of the EEPROM segment will be written to the output file. However, the IFNDEF EEPROM directive will not interrupt the process this time, and the following ORG 0 directive will reset the program counter. The assembler will start writing the data destined for the FLASH segment into the output file from address zero. The broadcast will be interrupted by the IFNDEF FLASH directive. The final form of the flash.hex file is shown in Table. 3.

We set the translation of the true segment of the executable code by the command

asem example.asm

First of all, additional segments will be re-compiled, and all labels defined in them will be entered into the assembler symbol table, which will allow them to be referenced from the code segment. The directive ORG 0 at the very beginning of it will once again reset the program counter. The broadcast will continue as usual. In the resulting file example.hex (Table 4), the executable code of the program starts from the fourth line, being after the lines identical to those contained in the previous HEX files.

The presence of redundant information usually does not interfere with the correct loading of the code into the appropriate memory areas of the microcontroller. In the buffer of the program that controls programming, the correct data, when the addresses match, "displace" the previously entered ones. And only if the new segment is shorter than the previous one, its "tail" will be stored in the buffer. For this reason, it is desirable to describe segments in the program in ascending order of their length.

Some programmers do not have an intermediate buffer or strictly control the input data, not allowing address overlaps. In the first case, the programming will be wrong, in the second case, it will not start at all until the "errors" are eliminated.

You can manually remove extra lines from a HEX file using any text editor. You can also do this automatically by running two commands in a row:

hex2bin example.hex bin2hex example.bin

The first will create a binary image of the data contained in the example.hex file and place it in the example.bin file. The second one will do the reverse transformation and create a new example.hex file with no frills. The necessary programs can be "downloaded" at the addresses And .

Author: S. Chekunov, Izhevsk

See other articles Section Microcontrollers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Machine for thinning flowers in gardens 02.05.2024

In modern agriculture, technological progress is developing aimed at increasing the efficiency of plant care processes. The innovative Florix flower thinning machine was presented in Italy, designed to optimize the harvesting stage. This tool is equipped with mobile arms, allowing it to be easily adapted to the needs of the garden. The operator can adjust the speed of the thin wires by controlling them from the tractor cab using a joystick. This approach significantly increases the efficiency of the flower thinning process, providing the possibility of individual adjustment to the specific conditions of the garden, as well as the variety and type of fruit grown in it. After testing the Florix machine for two years on various types of fruit, the results were very encouraging. Farmers such as Filiberto Montanari, who has used a Florix machine for several years, have reported a significant reduction in the time and labor required to thin flowers. ... >>

Advanced Infrared Microscope 02.05.2024

Microscopes play an important role in scientific research, allowing scientists to delve into structures and processes invisible to the eye. However, various microscopy methods have their limitations, and among them was the limitation of resolution when using the infrared range. But the latest achievements of Japanese researchers from the University of Tokyo open up new prospects for studying the microworld. Scientists from the University of Tokyo have unveiled a new microscope that will revolutionize the capabilities of infrared microscopy. This advanced instrument allows you to see the internal structures of living bacteria with amazing clarity on the nanometer scale. Typically, mid-infrared microscopes are limited by low resolution, but the latest development from Japanese researchers overcomes these limitations. According to scientists, the developed microscope allows creating images with a resolution of up to 120 nanometers, which is 30 times higher than the resolution of traditional microscopes. ... >>

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 ... >>

Random news from the Archive

Samsung Connect Tag Smart Keychain for Tracking People and Objects 26.10.2017

Samsung Electronics introduced the Connect Tag tracker, which allows you to know where your loved ones are, as well as track the location of any valuables. According to the company, it is the world's first mobile device to use NB-IoT (Cat.M1), a specially created low-power mobile communications standard for small data transfers. The tracker uses an electronic SIM card (eSIM).

Using a secure internet connection, Samsung Connect Tag detects your location and sends smart notifications. The device uses GPS, cellular networks, and a navigation system that allows you to determine the location using Wi-Fi hotspots to ensure the accuracy of the device's operation indoors and outdoors.

The Samsung Connect Tag can be attached to a child's backpack to always know where the child is, or attached to a dog's collar so as not to lose a pet. Samsung Connect Tag can also be hung on a keychain.

Like many other Samsung IoT devices, the new tracker will be linked to a special SmartThings platform to interact with the user's smart home appliances. So, thanks to the Geo-fence function, Samsung Connect Tag will inform the selected devices that the user is nearby. You can set the lights or TV to turn on automatically when you enter your home, set certain zones to receive notifications, for example, when a child enters the school grounds or a dog runs out into the backyard.

Finding a car in a large open parking lot is no longer difficult - the On-demand function will help you determine the location of the car. All you need to do is press a button on your smartphone.

Another feature allows the tracker holder to submit their current location themselves. Even a small child will be able to tell exactly where he is. In addition, thanks to notifications, you can get a record of all the movements of loved ones.

Dimensions Samsung Connect Tag only 42,1 x 11,9 mm, weight 25 g. The device is protected from dust and moisture thanks to a special protection system according to IP68 class. It holds charge up to 7 days. The kit includes a special ring that allows you to attach the tracker to bags, collars, key rings.

Other interesting news:

▪ Music tunes the child's brain for speech

▪ Massive natural source of greenhouse gases discovered

▪ New VoIP chip for Wi-Fi telephony systems

▪ Recovery of lithium iron phosphate batteries

▪ Smartphone ZTE Grand S3 with an iris scanner

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site Radio - for beginners. Article selection

▪ article Apparent figures. Encyclopedia of visual illusions

▪ article Due to what did the ancient Greek laws of Zalevka operate for 300 years with almost no amendments? Detailed answer

▪ article Lemon mint. Legends, cultivation, methods of application

▪ article Color-musical installation with pulse-number control of trinistors. Encyclopedia of radio electronics and electrical engineering

▪ article Standards for testing electrical equipment and devices for electrical installations of consumers. Test rectified voltage of power cables. 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