Declaring SPECIAL Memory

SPECIAL memory declarations support the use of external memory, such as in a device driver, or internal memory, such as in a second EPROM.

_Access

SPECIAL declarations are deprecated in favour of _Access declarations. The two declarations have similar semantics:

#pragma memory RAM _Access name [size] @ location;

SPECIAL memory declarations support the use of external memory, such as in a device driver, or internal memory, such as in a second EPROM. The directive #pragma memory SPECIAL name [size] @ location assigns a name, size and location to the special memory. You must create read and write functions or macros name_r and name_w in order to access variables in the special area. Multiple SPECIAL declarations with the same name are supported, facilitating the efficient use of non-contiguous address space.

The example below includes SPECIAL memory declarations for unused RAM in a 2 line by 16 character LCD display with a Hitachi HD44780 controller. The controller has 128 bytes of display RAM and 64 bytes of RAM reserved for coding 8 special characters. The non-visible part of the display and the character generator RAM (if it is not used) can be used to store data. Two lines by 16 characters use a total of 32 bytes from 80..8F and C0..CF. The areas from 90..BF and D0..FF are free for your use. The character generator occupies 40..7F.

The functions wLCDctrl8(), rLCDram() and wLCDram() are available in Byte Craft's LCD8 library.

#pragma memory SPECIAL ddram [48] @ 0x90; //Hidden display area
#pragma memory SPECIAL ddram [48] @ 0xD0; //Hidden display area
#pragma memory SPECIAL ddram [64] @ 0x40; //Character generator area
 //The following function reads LCD memory and returns the value read
char ddram_r(char loc){      
        wLCDctrl8(loc);
    return(rLCDram ());
} 
//The following function writes a value to LCD memory
void ddram_w(char loc; char value){
     wLCDctrl8(loc);
     wLCDram(value);
} 
char a,b,c; //Normal declaration 
char ddram wa; //Modifier puts variable in SPECIAL address space char ddram wb;
char ddram ar[10];
char ddram wc;
char o,p,q; //Normal declaration 
void main (void){
     wa = a;
     b = wb;
     wb = c;
     a = ar[b];
}