Data SheetTable of ContentsTable of Contents3Preface11Introduction11Document Layout12Conventions Used13Recommended Reading14myMicrochip Personalized Notification Service15The Microchip Web Site15Microchip Forums16Customer Support16Document Revision History16Chapter 1. Compiler Overview171.1 Introduction171.2 Device Description171.3 Compiler Description and Documentation171.3.1 ANSI C Standard171.3.2 Optimization171.3.3 ANSI Standard Library Support181.3.4 Flexible Memory Models181.3.5 Attributes and Qualifiers181.3.6 Compiler Driver181.3.7 Documentation181.4 Compiler and Other Development Tools19Chapter 2. Common C Interface212.1 Introduction212.2 Background – The Desire for Portable Code212.2.1 The ANSI Standard222.2.2 The Common C Interface232.3 Using the CCI242.4 ANSI Standard Refinement252.4.1 Source File Encoding252.4.1.1 Example252.4.1.2 Differences252.4.1.3 Migration to the CCI252.4.2 The Prototype for main252.4.2.1 Example252.4.2.2 Differences252.4.2.3 Migration to the CCI252.4.3 Header File Specification252.4.3.1 Example252.4.3.2 Differences262.4.3.3 Migration to the CCI262.4.4 Include Search Paths262.4.4.1 Example262.4.4.2 Differences262.4.4.3 Migration to the CCI262.4.5 The number of Significant Initial Characters in an Identifier272.4.5.1 Example272.4.5.2 Differences272.4.5.3 Migration to the CCI272.4.6 Sizes of Types272.4.6.1 Example272.4.6.2 Differences272.4.6.3 Migration to the CCI272.4.7 Plain char Types282.4.7.1 Example282.4.7.2 Differences282.4.7.3 Migration to the CCI282.4.8 Signed Integer Representation282.4.8.1 Example282.4.8.2 Differences282.4.8.3 Migration to the CCI282.4.9 Integer conversion292.4.9.1 Example292.4.9.2 Differences292.4.9.3 Migration to the CCI292.4.10 Bit-wise Operations on Signed Values292.4.10.1 Example292.4.10.2 Differences292.4.10.3 Migration to the CCI292.4.11 Right-shifting Signed Values292.4.11.1 Example292.4.11.2 Differences302.4.11.3 Migration to the CCI302.4.12 Conversion of Union Member Accessed Using Member With Different Type302.4.12.1 Example302.4.12.2 Differences302.4.12.3 Migration to the CCI302.4.13 Default Bit-field int Type302.4.13.1 Example302.4.13.2 Differences312.4.13.3 Migration to the CCI312.4.14 Bit-fields Straddling a Storage Unit Boundary312.4.14.1 Example312.4.14.2 Differences312.4.14.3 Migration to the CCI312.4.15 The Allocation Order of Bits-field312.4.15.1 Example322.4.15.2 Differences322.4.15.3 Migration to the CCI322.4.16 The NULL macro322.4.16.1 Example322.4.16.2 Differences322.4.16.3 Migration to the CCI322.4.17 Floating-point sizes322.4.17.1 Example322.4.17.2 Differences322.4.17.3 Migration to the CCI322.5 ANSI Standard Extensions332.5.1 Generic Header File332.5.1.1 Example332.5.1.2 Differences332.5.1.3 Migration to the CCI332.5.2 Absolute addressing332.5.2.1 Example332.5.2.2 Differences332.5.2.3 Migration to the CCI342.5.2.4 Caveats342.5.3 Far Objects and Functions342.5.3.1 Example342.5.3.2 Differences342.5.3.3 Migration to the CCI352.5.3.4 Caveats352.5.4 Near Objects352.5.4.1 Example352.5.4.2 Differences352.5.4.3 Migration to the CCI362.5.4.4 Caveats362.5.5 Persistent Objects362.5.5.1 Example362.5.5.2 Differences362.5.5.3 Migration to the CCI362.5.5.4 Caveats362.5.6 X and Y Data Objects372.5.6.1 Example372.5.6.2 Differences372.5.6.3 Migration to the CCI372.5.6.4 Caveats372.5.7 Banked Data Objects372.5.7.1 Example372.5.7.2 Differences382.5.7.3 Migration to the CCI382.5.7.4 Caveats382.5.8 Alignment of Objects382.5.8.1 Example382.5.8.2 Differences382.5.8.3 Migration to the CCI382.5.8.4 Caveats382.5.9 EEPROM Objects392.5.9.1 Example392.5.9.2 Differences392.5.9.3 Migration to the CCI392.5.9.4 Caveats392.5.10 Interrupt Functions392.5.10.1 Example402.5.10.2 Differences402.5.10.3 Migration to the CCI412.5.10.4 Caveats412.5.11 Packing Objects422.5.11.1 Example422.5.11.2 Differences422.5.11.3 Migration to the CCI422.5.11.4 Caveats422.5.12 Indicating Antiquated Objects432.5.12.1 Example432.5.12.2 Differences432.5.12.3 Migration to the CCI432.5.12.4 Caveats432.5.13 Assigning Objects to Sections432.5.13.1 Example432.5.13.2 Differences442.5.13.3 Migration to the CCI442.5.13.4 Caveats442.5.14 Specifying Configuration Bits452.5.14.1 Example452.5.14.2 Differences452.5.14.3 Migration to the CCI452.5.14.4 Caveats452.5.15 Manifest Macros46Table 2-1: Manifest macros defined by the CCI462.5.15.1 Example462.5.15.2 Differences462.5.15.3 Migration to the CCI462.5.15.4 Caveats462.5.16 In-line Assembly472.5.16.1 Example472.5.16.2 Differences472.5.16.3 Migration to the CCI472.5.16.4 Caveats472.6 Compiler Features482.6.1 Enabling the CCI482.6.1.1 Differences482.6.1.2 Migration to the CCI482.6.1.3 Caveats48Chapter 3. Compiler Command-Line Driver493.1 Introduction493.2 Invoking the Compiler503.2.1 Drive Command-Line Format503.2.2 Environment Variables503.2.3 Input File Types513.3 The Compilation Sequence523.3.1 The Compiler Applications523.3.2 Single-Step Compilation543.3.2.1 Compiling a Single File543.3.2.2 Compiling Multiple Files553.3.3 Multi-Step Compilation553.3.4 Assembly Compilation563.4 Runtime Files573.4.1 Library Files573.4.1.1 Standard Libraries573.4.1.2 User-Defined libraries573.4.2 Startup and Initialization573.5 Compiler Output583.5.1 Output Files583.5.2 Diagnostic Files583.6 Compiler Messages593.7 Driver Option Descriptions603.7.1 Options Specific to 16-Bit Devices603.7.2 Options for Controlling the Kind of Output623.7.3 Options for Controlling the C Dialect633.7.4 Options for Controlling Warnings and Errors643.7.5 Options for Debugging703.7.6 Options for Controlling Optimization713.7.7 Options for Controlling the Preprocessor763.7.8 Options for Assembling793.7.9 Options for Linking793.7.10 Options for Directory Search823.7.11 Options for Code Generation Conventions823.8 MPLAB IDE Toolsuite Equivalents83Chapter 4. Device-Related Features854.1 Introduction854.2 Device Support854.3 Device Header Files854.3.1 Register Definition Files854.4 Stack864.5 Configuration Bit Access864.6 Using SFRs874.7 Bit-Reversed and Modulo Addressing89Chapter 5. Differences Between MPLAB XC16 and ANSI C915.1 Divergence from the ANSI C Standard915.2 Extensions to the ANSI C Standard915.2.1 Keyword Differences915.2.2 Expression Differences915.3 Implementation-Defined Behavior91Chapter 6. Supported Data Types and Variables936.1 Introduction936.2 Identifiers936.3 Integer Data Types946.3.1 Double-Word Integers946.3.2 char Types956.4 Floating-Point Data Types956.5 Structures and Unions966.5.1 Structure and Union Qualifiers966.5.2 Bit-Fields in Structures966.6 Pointer Types986.6.1 Combining Type Qualifiers and Pointers986.6.2 Data Pointers996.6.3 Function Pointers996.6.4 Special Pointer Targets996.7 Complex Data Types1006.8 Literal Constant Types and Formats1016.9 Standard Type Qualifiers1036.9.1 Const Type Qualifier1036.9.2 Volatile Type Qualifier1036.10 Compiler-Specific type Qualifiers1046.10.1 __psv__ Type Qualifier1046.10.2 __prog__ Type Qualifier1046.10.3 __eds__ Type Qualifier1056.10.4 __pack_upper_byte Type Qualifier1056.10.5 __pmp__ Type Qualifier1056.10.6 __external__ Type Qualifier1066.11 Variable Attributes107Chapter 7. Memory Allocation and Access1177.1 Introduction1177.2 Address Spaces1177.3 Variables in Data Space Memory1187.3.1 Non-Auto Variable Allocation and Access1187.3.1.1 Default Allocation of Non-auto Variables1187.3.1.2 Static Variables1197.3.1.3 Non-Auto Variable Size Limits1197.3.1.4 Changing Non-Auto Variable Allocation1207.3.1.5 Data Memory Allocation Macros1207.3.2 Auto Variable Allocation and Access1217.3.2.1 Software Stack1217.3.2.2 The C Stack Usage1227.3.2.3 Auto Variable Size Limits1247.3.3 Changing Auto Variable Allocation1247.4 Variables in Program Space1257.4.1 Allocation and Access of Program Memory Objects1257.4.1.1 String and Const Objects1257.4.1.2 Const-qualified Variables in Secure Flash1267.4.1.3 String Literals as Arguments1267.4.2 Access of objects in Program Memory1277.4.2.1 Managed PSV Access1277.4.2.2 Object Compatibility Model1277.4.2.3 ISR Considerations1287.4.3 Size Limitations of Program Memory Variables1287.4.4 Changing Program Memory Variable Allocation1297.5 Parallel Master Port Access1307.5.1 Initialize PMP1307.5.2 Declare a New Memory Space1317.5.3 Define Variables within PMP Space1317.6 External Memory Access1327.6.1 Declare a New Memory Space1327.6.2 Define Variables Within an External Space1327.6.3 Define How to Access Memory Spaces1337.6.3.1 Functions for Reading1337.6.3.2 Functions for Writing1347.6.4 An External Example1357.7 Extended Data Space Access1367.8 Packing Data Stored in Flash1377.8.1 Packed Example1377.8.2 Usage Considerations1377.8.3 Addressing Information1387.9 Allocation of Variables to Registers1397.10 Variables in EEPROM1397.10.1 Accessing EEDATA via User Managed PSV1397.10.2 Accessing EEDATA Using TBLRDx Instructions1407.10.3 Accessing EEDATA Using Managed Access1417.10.4 Additional Sources of Information1417.11 Dynamic Memory Allocation1417.12 Memory Models1427.12.1 Near or Far Data143Chapter 8. Operators and Statements1458.1 Introduction1458.2 Built-In Functions1458.3 Integral Promotion145Chapter 9. Register Usage1479.1 Introduction1479.2 Register Variables1479.3 Changing Register Contents148Chapter 10. Functions14910.1 Introduction14910.2 Writing Functions14910.2.1 Function Specifiers14910.2.2 Function Attributes14910.3 Function Size Limits15610.4 Allocation of Function Code15610.5 Changing the Default Function Allocation15710.6 Inline Functions15810.7 Memory Models15910.7.1 Near or Far Code16010.8 Function Call Conventions16110.8.1 Function Parameters16110.8.2 Return Value16310.8.3 Preserving Registers Across Function Calls163Chapter 11. Interrupts16511.1 Introduction16511.2 Interrupt Operation16611.3 Writing an Interrupt Service Routine16611.3.1 Guidelines for Writing ISRs16611.3.2 Syntax for Writing ISRs16711.3.3 Coding ISRs16711.3.4 Using Macros to Declare Simple ISRs16811.4 Specifying the Interrupt Vector16911.4.1 Non-SMPS dsPIC30F DSCs Interrupt Vectors17011.4.2 SMPS dsPIC30F DSCs Interrupt Vectors17211.4.3 PIC24F MCUs Interrupt Vectors17411.4.4 dsPIC33F DSCs/PIC24H MCUs Interrupt Vectors17711.5 Interrupt Service Routine Context Saving18011.6 Nesting Interrupts18011.7 Enabling/Disabling Interrupts18111.8 ISR Considerations18211.8.1 Sharing Memory with Mainline Code18211.8.1.1 Development Issues18311.8.1.2 Development Solutions18411.8.1.3 Application Example18511.8.2 PSV Usage with Interrupt Service Routines18611.8.3 Latency186Chapter 12. Main, Runtime Startup and Reset18712.1 Introduction18712.2 The main Function18712.3 Runtime Startup and Initialization187Chapter 13. Mixing C and Assembly Code18913.1 Introduction18913.2 Mixing Assembly Language and C Variables and Functions18913.3 Using Inline Assembly Language19213.4 Predefined Assembly Macros196Chapter 14. Library Routines197Chapter 15. Optimizations19915.1 Introduction199Chapter 16. Preprocessing20116.1 Introduction20116.2 C Language Comments20116.3 Preprocessing Directives20116.4 Predefined Macro Names20216.4.1 Compiler Version Macro20216.4.2 Output Types Macros20316.4.3 Target Device Macros20316.4.4 Device Features Macros20316.4.5 Other Macros20416.5 Pragmas vs. Attributes205Chapter 17. Linking Programs20717.1 Introduction20717.2 Default Memory Spaces20717.3 Replacing Library Symbols20917.4 Linker-Defined Symbols20917.5 Default Linker Script210Appendix A. Implementation-Defined Behavior211A.1 Introduction211A.2 Translation212A.3 Environment212A.4 Identifiers213A.5 Characters213A.6 Integers214A.7 Floating Point215A.8 Arrays and Pointers215A.9 Registers216A.10 Structures, Unions, Enumerations and Bit Fields216A.11 Qualifiers216A.12 Declarators216A.13 Statements217A.14 Preprocessing Directives217A.15 Library Functions218A.16 Signals219A.17 Streams and Files220A.18 tmpfile221A.19 errno221A.20 Memory221A.21 abort221A.22 exit221A.23 getenv221A.24 system221A.25 strerror222Appendix B. Diagnostics223B.1 Introduction223B.2 Errors223B.3 Warnings242Appendix C. GNU Free Documentation License263C.1 Preamble263C.2 Applicability and Definitions263C.3 Verbatim Copying265C.4 Copying in Quantity265C.5 Modifications266C.6 Combining Documents267C.7 Collections of Documents267C.8 Aggregation with Independent Works267C.9 Translation268C.10 Termination268C.11 Future Revisions of this License268C.12 Relicensing269Appendix D. ASCII Character Set271Appendix E. Deprecated Features273E.1 Introduction273E.2 Predefined Constants273E.3 Variables in Specified Registers274E.3.1 Defining Global Register Variables274E.3.2 Specifying Registers for Local Variables275E.4 Changing Non-Auto Variable Allocation275Appendix F. Built-in Functions277F.1 Introduction277F.2 Built-In Function Descriptions279Appendix G. XC16 Configuration Settings305G.1 Introduction305Glossary307Index327Worldwide Sales and Service338Size: 3.31 MBPages: 338Language: EnglishOpen manual