ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING Initialization of additional memory segments in programs for microcontrollers of the MCS-51 family. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Microcontrollers 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. 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. Latest news of science and technology, new electronics: Machine for thinning flowers in gardens
02.05.2024 Advanced Infrared Microscope
02.05.2024 Air trap for insects
01.05.2024
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 Lemon mint. Legends, cultivation, methods of application
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |