As the C51 compiler is widely used in the development of 51 series microcontroller software, a large number of developers are freed from the tedious assembly language programming. C51 not only shortens the software development cycle, but also makes the application software have better structure and maintainability. In the application design using the C51 compiler, most program codes do not exceed the maximum addressing space of 64K of the 51 series microcontroller, but in actual applications, there are also cases where the program code exceeds 64K. Although this situation can be solved by replacing high-end CPUs, when the product batch is large and the CPU performance requirements are not high, it is not desirable to use high-end CPUs because this will increase the cost of the product. So can we break through the limitation of 64K code space in the cheap 51 series microcontrollers and develop products? The BANK mode of the C51 compiler is designed to solve this problem. The author summarizes a set of usage methods of the C51 compiler BANK mode by using it. This article explains this usage method and introduces the special usage of BANK for mixed code and data.
How 2BANK works
The BANK mode of C51 has special requirements on the code memory structure of the application system. Figure 1 shows the physical structure of the code memory in the BANK mode of C51.
The upper half of the code address space overlaps the physical address space of BANK0. The hardware designs n memory pages to store program code. At any time, only one BANK in BANK0~n can be active. When BANKi is active, its physical address space is BankBaseAddr~0xFFFF. Only when BANK is active can the program code in BANK run. In order to address the procedure code in any BANK, the C51 compiler generates the following BANK address for the procedure call:
The base address is variable, but for the convenience of decoding, it is generally selected as 8000H. When a procedure calls any other procedure that is not in the same bank, the bank number in the bank address is sent to the decoding circuit that switches banks, and the 16-bit offset address is sent to the address bus, thereby realizing the process call in different banks. The code space in the lower half is not processed as a bank, and it is called ROOTBANK. This is because the C51 compiler only generates bank addresses for procedure calls, and does not generate bank addresses for all other parts outside of procedure calls, such as CONST, and ROOTBANK is used to store this part of the code. In addition, ROOTBANK is generally used to store the following code: C51 library functions, all variable initialization data, interrupt service program code, and CSTARTUP code. The compiler always operates this type of code in NON-BANK mode.
3 Steps to use C51BANK mode
Assuming that the software has been designed according to the large mode of C51, in order to use the BANK mode of C51, the following three steps should be performed.
3.1 Design Hardware
The BANK mode of C51 requires hardware support. The hardware must be designed with appropriate decoding circuits to support the memory page structure. Although the C51 compiler system can support 256 memory BANK pages, 4 to 8 memory pages are sufficient for general application systems. After determining the number of required memory pages, the decoding address bits of the BANK page are also determined. Assuming that the decoding address is n bits, the relationship between n and the number of BANK pages satisfies equation (1).
2n≥The maximum number of BANK pages required n takes the minimum value (1)
The decoding circuit supporting the page structure memory varies depending on the size of the memory chip and the number of chips used. There are two methods for latching the n-bit decoding address. The simplest method is to directly use the extra port lines of the CPU. If there are no extra port lines available, the second method is to use the extended latch to latch the BANK decoding address. At this time, the latch address of the latch can be generated by decoding in the external RAM space or in the external ROM space. If the ROM space decoding is used, it should be noted that the address cannot conflict with the address space that the code may occupy.
3.2 Write the source program of BANK mode
The source program in C51BANK mode is not much different from that in large mode. However, the following points should be noted in BANK mode:
(1) Reasonable planning of code space
Planning the code space is to decide which part of the code is placed in the ROOTBANK and which part of the code is placed in the BANK. As mentioned above, there are several types of code that must be placed in the ROOTBANK, while other codes can be placed in either BANK or the ROOTBANK. However, in order to improve the operating efficiency of the system, the frequently called public program modules should be placed in the ROOTBANK as much as possible to reduce the switching of the BANK. For the program modules written in assembly language, if they are placed in the BANK, it is necessary to manually add the operation of switching the BANK in the assembly program, which is very cumbersome. Therefore, the program modules written in assembly language are generally placed in the ROOTBANK.
(2) Check the source program module size
Each C program module will generate a CODE segment when it is compiled, and the linker cannot distribute the CODE of a module to multiple BANKs. Therefore, the size of each program module must be less than or equal to the space of a BANK, otherwise a program module must be divided into two or more modules. As long as it does not exceed the space of the BANK, the linker can put the code of multiple program modules into one BANK. It can be seen that minimizing each program module can make full use of the space resources of the BANK. [page]
(3) Make full use of non-BANK calls
In BANK mode, when the compiler does not know whether the caller and the called are in the same BANK, it will generate program code according to the BANK call method. However, in the following four cases, the compiler can know whether the caller and the called are in the same physical BANK. In this case, the compiler will generate program code for non-BANK calls with less space and faster speed.
The first case is when the calling and called procedures are in the same source module, the compiler knows that they are in the same physical bank. In this case, the compiler generates function call code using a non-bank method.
The second case is that when the procedure is declared as a static type, the compiler determines that all calls to the static procedure are within the current program module, and the compiler generates a non-BANK calling method.
The third case is that for the interrupt procedure described as interrupt, the compiler always generates a non-BANK calling method to call it, because the interrupt procedure must always be placed in ROOTBANK.
The fourth case is to use non-banked compilation conditions to describe the process in the source program according to the allocation of BANK, and artificially control the compiler to generate non-BANK calls.
(4) Check whether there is a call to the procedure in BANK in the assembly language program module
When switching from a large mode program to a bank mode, check whether there is a call to a C procedure in the bank in the assembly language program. If there is a call to a C procedure in the assembly language program, the call must be rewritten, that is, an operation for bank switching must be added.
3.3 Changing compilation, linking switches and function libraries
3.3.1 Changing the Compilation Switch
Changing the compile switch means modifying the compile options in the makefile. Here we need to change ml to mb. For modules placed in ROOTBANK, we need to add RCODE to the compile options.
3.3.2 Change the link switch
To change the link switch, you need to do it in the .XCL file. First, add RCODE in the link switch-Z option, that is:
Z(CODE)INTVEC,RCODE,D_CDATA,I_CDATA,CONST=0
This switch is used to list the order in which all segments except the CODE segment are emitted.
In addition to the above changes, add the following link options:
A means the starting value of bank_number is 0
B indicates that the starting value of the 16-bit offset address of the bank is 8000H
C means the CODE segment should be placed in a 2000H byte length BANK
D means bank_number should increase in steps of 0001H
E indicates that the 16-bit offset address of the bank increases by 0000H, which means that for any bank, its 16-bit offset address is always 8000H.
3.3.3 Changing library functions
Changing the library function means changing the library CL8051L.R03 required for linking in the large mode to the library function CL8051B.R03 in the BANK mode. The most important thing is to rewrite the L18.S03 assembly language module in CL8051B.R03. This program module is the core of realizing BANK switching in the BANK working mode. It completes the process of sending the bank number to the decoding circuit for BANK switching. This module should be rewritten according to the specific decoding circuit.
4. Hybrid Bank Technology of Code and Data
There are some applications that not only have program codes exceeding 64K, but also have a large amount of constant data. The author encountered this situation when developing an electric typewriter with spelling check. In order to check the correctness of the typed words, the typewriter must be equipped with a dictionary. The dictionary must occupy ROM space, so BANK pages must also be allocated for the dictionary. However, the problem cannot be solved in the BANK compilation mode of C51. For this purpose, the BANK technology of mixed code and data is used. The operation steps of this technology are as follows:
(1) Ignoring the existence of data BNAK, only program code is processed in BANK mode. However, it should be noted that the process module that directly operates on data should be located in ROOTBANK, while the process that indirectly operates on data can be placed in ROOTBANK or BANK.
(2) Check the linked MAP file. Check the occupancy of the BANK pages automatically allocated by the system for the code, and thus determine the location of the data in the BANK pages that are not occupied by the system.
(3) Rewrite the process of directly operating the data according to the bank page where the data is located. In this process, the program can directly activate the required data page.
(4) Recompile and link the program.
5 Conclusion
The BANK mode of C51 has a high practical value because it breaks through the 64K program space limit of the 51 series single-chip microcomputer. With this technology, products that originally required high-end CPUs can be developed at a lower cost. Since the product cost is greatly reduced, it will inevitably bring higher economic benefits to the product. Therefore, this technology has the value of promotion and application.
Previous article:Single chip remote voice alarm system
Next article:Design of a multi-channel ambient temperature acquisition system
Recommended ReadingLatest update time:2024-11-17 01:49
- Popular Resources
- Popular amplifiers
- Siemens PLC Programming Technology and Application Cases (Edited by Liu Zhenquan, Wang Hanzhi, Yang Kun, etc.)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Implementing a Deep Learning Framework with Python (Zhang Juefei, Chen Zhen)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Research and Implementation of Serial Data Communication between C6000 and C2000 Series DSP
- LM358 op amp problem, please give me some advice
- How to Measure Circuit Current Using a Shunt Resistor
- TI's ultra-low power solution gives birth to TWS true wireless
- 【TI millimeter wave radar evaluation】+SDK development environment
- PCB News: Zhongjing Electronics plans to acquire 45% of Yuansheng Electronics for RMB 270 million to achieve horizontal integration of PCB
- How to use EPI general mode to communicate with FPGA in TM4c129 series microcontroller
- Photos: 1978-2000: Our Fashion (1989-1992)
- Before buying a cable fault tester, you must know about its manufacturer. How to find a good time...
- High-speed PCB design technology (Chinese)