How to use C51's BANK compilation mode

Publisher:快乐的舞蹈Latest update time:2012-02-15 Source: 电子元器件应用 Keywords:BANK Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1 Introduction

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 C51 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.

Keywords:BANK Reference address:How to use C51's BANK compilation mode

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

Design of PS2 keyboard --- C51 program
#include #define Frequence 11 //Crystal frequency unit is MHZ #define DELAY 10*Frequence/6 //Send program delay #define SLEEP 8*Frequence/6 //Send program delay sbit KBCLK="P3"^0; //Keyboard clock line sbit KBDATA="P3"^1; //Keyboard data line bit bat(void); //Basically guarantee that the test returns 0 if there
[Microcontroller]
51 single chip microcomputer PCA9685 drives 9 servos
The source program of the 51 single-chip PCA9685 driver board driving the servo single-chip is as follows: #include reg52.h             #include intrins.h    #include stdio.h #include math.h typedef unsigned char uchar;         typedef unsigned int uint;         unsigned char buf; sbit scl=P2^6;                   
[Microcontroller]
Introduction to the internal structure of MCS-51 single chip microcomputer
1. 8051 MCU on-chip parallel interface 2. Internal resources of MCS-51 3. MCS-51 chip pins 4. How does the microcontroller work? The working modes of the microcontroller include: reset mode, program execution mode, single-step execution mode, low-power operation mode, and EPROM programming and verification mod
[Microcontroller]
Introduction to the internal structure of MCS-51 single chip microcomputer
Watchdog circuit composed of 89C51 single chip microcomputer + X25045
The watchdog circuit is composed of 89C51 single-chip microcomputer and X25045 . The hardware connection diagram of X25045 is shown in Figure 1. The X25045 chip contains a watchdog timer, and the system monitoring time can be preset by software. If there is no bus activity within the preset time of the watchdog timer
[Power Management]
Watchdog circuit composed of 89C51 single chip microcomputer + X25045
Based on 51 microcontroller--preprocessing summary of C language
The compilation preprocessor is an important part of the C language compiler. Making good use of C language preprocessing commands can enhance the readability, flexibility, and ease of modification of the code, and facilitate the structuring of the program. The preprocessing command starts with the symbol "#" and in
[Microcontroller]
Design of drilling wellbore attitude monitoring system using C8051F060 based on MATLAB environment
1 Introduction In oil drilling, accurate measurement of wellbore attitude is the prerequisite for wellbore trajectory control. To this end, this paper fully combines the advantages of microcontroller and MATLAB, and based on the event-driven communication mechanism, proposes a visual data processing method for real-ti
[Microcontroller]
Design of drilling wellbore attitude monitoring system using C8051F060 based on MATLAB environment
Design of LED control circuit for simulating meteor shower based on W79E2051 single chip microcomputer
Based on W79E2051 MCU and LED constant current dedicated driver chip MBI5026, a simulated meteor shower LED control circuit is designed. The LED uses high brightness white, and 36, 48, or 64 LEDs can be connected as needed. When the power is turned on, the LEDs arranged in a straight line will produce a meteor showe
[Microcontroller]
Design of LED control circuit for simulating meteor shower based on W79E2051 single chip microcomputer
MAX951 Low power consumption 3V working voltage high precision A_D converter
A converter is a device that converts information from a source for a certain purpose. A matrix converter is a new type of AC-AC power converter. Compared with traditional converters, it has the following advantages: no intermediate DC energy storage link is required; it can operate in four quadrants; it has excelle
[Analog Electronics]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号