How can I place variables in different banks?


TR 18037 standardized named address spaces, and MPC uses these to assist in placing variables in different banks.

In device header files, banks are declared like this:

0029 0047                         #pragma memory RAM bank0 [B0SIZE] @ B0START;
00A0 0050                         #pragma memory RAM bank1 [B1SIZE] @ B1START;
0110 0060                         #pragma memory RAM bank2 [B2SIZE] @ B2START;
0190 0060                         #pragma memory RAM bank3 [B3SIZE] @ B3START;

The SIZE and START symbols are calculated just above these declarations.

In your program, use the names as follows:

bank1 int8 one;
bank2 int8 two;
bank3 int8 three;

In previous versions of the compiler, the name came after the type:

int8 bank1 one;

...but this usage is deprecated.


The same goes for structures/enums/unions too, although you can simplify structures by declaring them separately from the implementing variables:

struct __mystruct {
  int a;
  int b;

bank2 struct __mystruct myvar;