07.04.2013 Views

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

SHOW MORE
SHOW LESS

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 />

D.13 PRAGMAS<br />

The PIC18 MCU <strong>Compiler</strong> uses pragmas <strong>for</strong> sections (code, romdata, udata,<br />

idata), interrupts (high-priority <strong>and</strong> low-priority) <strong>and</strong> variable locations (bank, section).<br />

The 16-Bit Device <strong>Compiler</strong> uses non-ANSI attributes instead of pragmas.<br />

TABLE D-5: PRAGMAS VS. ATTRIBUTES<br />

Pragma (PIC18 MCU <strong>Compiler</strong>) Attribute (16-Bit Device <strong>Compiler</strong>)<br />

#pragma udata [name] __attribute__ ((section ("name")))<br />

#pragma idata [name] __attribute__ ((section ("name")))<br />

#pragma romdata [name] __attribute__ ((space (prog)))<br />

#pragma code [name] __attribute__ ((section ("name"))),<br />

__attribute__ ((space (prog)))<br />

#pragma interruptlow __attribute__ ((interrupt))<br />

#pragma interrupt __attribute__ ((interrupt, shadow))<br />

#pragma varlocate bank NA*<br />

#pragma varlocate name<br />

*16-bit devices do not have banks.<br />

NA*<br />

EXAMPLE D-4: SPECIFY AN UNINITIALIZED VARIABLE IN A USER SECTION<br />

IN DATA MEMORY<br />

PIC18 #pragma udata mybss<br />

int gi;<br />

16-Bit int __attribute__((__section__(".mybss"))) gi;<br />

EXAMPLE D-5: LOCATE THE VARIABLE MABONGA AT ADDRESS 0X100 IN<br />

DATA MEMORY<br />

PIC18 #pragma idata myDataSection=0x100;<br />

int Mabonga = 1;<br />

16-Bit int __attribute__((address(0x100))) Mabonga = 1;<br />

EXAMPLE D-6: SPECIFY A VARIABLE TO BE PLACED IN PROGRAM<br />

MEMORY<br />

PIC18 #pragma romdata const_table<br />

const rom char my_const_array[10] =<br />

{0,1,2,3,4,5,6,7,8,9};<br />

16-Bit const __attribute__((space(auto_psv)))<br />

char my_const_array[10] = {0,1,2,3,4,5,6,7,8,9};<br />

Note: The 16-Bit Device <strong>Compiler</strong> does not directly support accessing variables<br />

in program space. Variables so allocated must be explicitly accessed by the<br />

programmer, usually using table-access inline assembly instructions, or<br />

using the program space visibility window. See Section 4.14 “Program<br />

Space Visibility (PSV) Usage” <strong>for</strong> more on the PSV window.<br />

DS51284H-page 206 © 2008 <strong>Microchip</strong> Technology Inc.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!