MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs ... - Microchip
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
16-Bit C <strong>Compiler</strong> User’s Guide<br />
write_external32<br />
void __write_external32(unsigned int address,<br />
unsigned int memory_space,<br />
unsigned long data)<br />
Write 32 bits of data to external memory space memory_space starting from address<br />
address. The compiler would like to call this function if trying to write a 32-bit sized<br />
object, such as a long or float type.<br />
write_external64<br />
void __write_external64(unsigned int address,<br />
unsigned int memory_space,<br />
unsigned long long data)<br />
Write 64 bits of data to external memory space memory_space starting from address<br />
address. The compiler would like to call this function if trying to write a 64-bit sized<br />
object, such as a long long or long double type.<br />
6.4.4 An External Example<br />
The following snippets of example come from a working example (in the Examples<br />
folder.)<br />
This example implements, using external memory, addressable bit memory. In this<br />
case each bit is stored in real data memory, not off chip. The code will define an<br />
external memory of 512 units <strong>and</strong> map accesses using the appropriate read <strong>and</strong><br />
write function to one of 64 bytes in local data memory.<br />
First the external memory is defined:<br />
extern unsigned int bit_memory<br />
__attribute__((space(external(size(512)))));<br />
Next appropriate read <strong>and</strong> write functions are defined. These functions will make use<br />
of an array of memory that is reserved in the normal way.<br />
static unsigned char real_bit_memory[64];<br />
unsigned char __read_external8(unsigned int address,<br />
unsigned int memory_space) {<br />
if (memory_space == bit_memory) {<br />
/* an address within our bit memory */<br />
unsigned int byte_offset, bit_offset;<br />
byte_offset = address / 8;<br />
bit_offset = address % 8;<br />
return (real_bit_memory[byte_offset] >> bit_offset) & 0x1;<br />
} else {<br />
fprintf(stderr,"I don't know how to access memory space: %d\n",<br />
memory_space);<br />
}<br />
return 0;<br />
}<br />
void __write_external8(unsigned int address,<br />
unsigned int memory_space,<br />
unsigned char data) {<br />
if (memory_space == bit_memory) {<br />
/* an address within our bit memory */<br />
unsigned int byte_offset, bit_offset;<br />
byte_offset = address / 8;<br />
bit_offset = address % 8;<br />
real_bit_memory[byte_offset] &= (~(1