8051 code bank principle introduction

8051 code bank principle introduction

A standard 8051 device can address 64KB of code address space. For codes exceeding 64KB, single-chip systems usually use code paging (CODE BANKING) to expand the program space.

How to expand:
The following introduces a method combined with hardware, using special function registers (SFR).
Hardware setting:
It is realized by manipulating the bit of the port through SFR on the hardware.
insert image description here
Software settings:
New projects need to add STARTUP.A51 and L51_BANK.A51, among which STARTUP.A51 is a new function that is added automatically, and L51_BANK.A51 is added manually. The source files are in the keil installation directory lib (\keil \ C51\lib\L51_BANK.A51 ).

1. First check Use Extended Linker(Lx51) instead of BL51 in keil.
Note that you must check this item if you want to use the code bank function.
insert image description here
2. Check code banking under Target, which means it supports the code banking function, and the size is set according to the needs.
insert image description here
Until this step, the settings on Keil are completed. Now we need to modify L51_BANK.A51

1. First look at its configuration section. There are mainly the following five variables to be set:
usually need to modify
B_NBANKS: specify the number of banks
B_MODE: select the way the bank is switched.
insert image description here
The core of bank switching:
mainly two functions B_BANK&N and B_SWITCH&N:
The function of B_BANK&N is to save some addresses to prevent the Bank from returning after switching.
1. Save the address of the current bank (C51 will generate an address vector table for multiple banks to store the B_SWITCH&N function, and the saved address is this address) 2. Save the address of the function to be
switched
insert image description here

B_SWITCH&N Switch to the corresponding bank
insert image description here
Let's see an example: bank0->bank1->bank0
insert image description here

Guess you like

Origin blog.csdn.net/shenjin_s/article/details/106915578