MPC - Named Address Space


This tip takes advantage of a useful new feature: named address space. The #pragma memory RAM directive allows you to define the RAM limits of your system. The newest version of MPC allows you to name up to 15 of these defined RAM areas. Naming address space allows for the grouping of variables. For example, variables used in timing-critical sections of code can be grouped in an area which does not require a bank switching instruction for access.

#pragma option v;
#pragma has PIC12;
#pragma has PIC16C57;
#pragma vector __RESET @ 0x7FF;
#define MAXROM 0x800  // Total program memory 
#define MAXRAM 0x10   // File register space 
#define MAXB0  0x20   // File register space 
#define MAXB1  0x40   // File register space 
#define MAXB2  0x60   // File register space 
#define MAXB3  0x80   // File register space 
#pragma memory ROM [MAXROM - 0x00] @ 0x00;
#pragma memory RAM register[MAXRAM - 0x09] @ 0x09;
#pragma memory RAM [MAXB0  - 0x10] @ 0x10;
#pragma memory RAM [MAXB1  - 0x30] @ 0x30;
#pragma memory RAM bank2 [MAXB2  - 0x50] @ 0x50;
#pragma memory RAM [MAXB3  - 0x70] @ 0x70;
int array1[8];
int array2[16];
char k;
register char j;
char bank2 l;

void main()
    int register i;
    i = 0xFF;
    do {
    } while(i--);