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.

<strong>MPLAB</strong> C <strong>Compiler</strong> <strong>for</strong> PIC18 <strong>MCUs</strong> vs. 16-Bit Devices<br />

D.14 MEMORY MODELS<br />

EXAMPLE D-7: LOCATE THE FUNCTION PRINTSTRING AT ADDRESS<br />

0X8000 IN PROGRAM MEMORY<br />

PIC18 #pragma code myTextSection=0x8000;<br />

int PrintString(const char *s){...};<br />

16-Bit int __attribute__((address(0x8000))) PrintString<br />

(const char *s) {...};<br />

EXAMPLE D-8: COMPILER AUTOMATICALLY SAVES AND RESTORES THE<br />

VARIABLES VAR1 AND VAR2<br />

The PIC18 MCU <strong>Compiler</strong> uses non-ANSI small <strong>and</strong> large memory models. Small uses<br />

the 16-bit pointers <strong>and</strong> restricts program memory to be less than 64 KB (32 KB words).<br />

The 16-Bit Device <strong>Compiler</strong> uses non-ANSI small code <strong>and</strong> large code models. Small<br />

code restricts program memory to be less than 96 KB (32 KB words). In large code,<br />

pointers may go through a jump table.<br />

D.15 CALLING CONVENTIONS<br />

D.16 STARTUP CODE<br />

PIC18 #pragma interrupt isr0 save=var1, var2<br />

void isr0(void)<br />

{<br />

/* per<strong>for</strong>m interrupt function here */<br />

}<br />

16-Bit void __attribute__((__interrupt__(__save__(var1,var2))))<br />

isr0(void)<br />

{<br />

/* per<strong>for</strong>m interrupt function here */<br />

}<br />

There are many differences in the calling conventions of the <strong>MPLAB</strong> C <strong>Compiler</strong> <strong>for</strong><br />

PIC18 <strong>MCUs</strong> <strong>and</strong> the <strong>MPLAB</strong> C <strong>Compiler</strong> <strong>for</strong> <strong>PIC24</strong> <strong>MCUs</strong> <strong>and</strong> <strong>dsPIC</strong> ® <strong>DSCs</strong>. Please<br />

refer to Section 4.11 “Function Call Conventions” <strong>for</strong> a discussion of 16-Bit Device<br />

<strong>Compiler</strong> calling conventions.<br />

The PIC18 MCU <strong>Compiler</strong> provides three startup routines – one that per<strong>for</strong>ms no user<br />

data initialization, one that initializes only variables that have initializers, <strong>and</strong> one that<br />

initializes all variables (variables without initializers are set to zero as required by the<br />

ANSI st<strong>and</strong>ard).<br />

The 16-Bit Device <strong>Compiler</strong> provides two startup routines – one that per<strong>for</strong>ms no user<br />

data initialization <strong>and</strong> one that initializes all variables (variables without initializers are<br />

set to zero as required by the ANSI st<strong>and</strong>ard) except <strong>for</strong> variables in the persistent data<br />

section.<br />

D.17 COMPILER-MANAGED RESOURCES<br />

The PIC18 MCU <strong>Compiler</strong> has the following managed resources: PC, WREG, STA-<br />

TUS, PROD, section .tmpdata, section MATH_DATA, FSR0, FSR1, FSR2, TBLPTR,<br />

TABLAT.<br />

The 16-Bit Device <strong>Compiler</strong> has the following managed resources: W0-W15, RCOUNT,<br />

SR.<br />

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

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

Saved successfully!

Ooh no, something went wrong!