Table of Contents
Previous topic Next topic
C COMPILER->Code Bank Switching->Restoration of the Previous Bank
There are two things to note from the previous section:
- the address __LastBank holds the latest value used to switch in the active bank.
- the previous bank is restored assuming that the type, address and mask are the same as for the present bank.
__LastBank is a one byte location present in the library. It is initialised to zero. You might want it to be initialised to a different value so that a particular bank is active even when no banked function is running. To do this, you can either initialise it in your startup file, eg:
extrn data(__LastBank)
mov __LastBank,#2
or create your own _LastBank variable by placing for example the following line in one of your C source files:
unsigned char _data _LastBank = 2;
Since the previous bank is restored assuming that the type, address and mask are the same as for the present bank, you cannot mix types, addresses or masks. Therefore if you are switching code banks via a particular port and with a particluar mask or via a memory mapped address, then you must use the same bank attributes thoughout your program.