MPLAB C30 C Compiler User's Guide - Microchip Technology

MPLAB? C30 C COMPILER USER'S GUIDE

? 2007 Microchip Technology Inc.

DS51284F

Note the following details of the code protection feature on Microchip devices: ? Microchip products meet the specification contained in their particular Microchip Data Sheet.

? Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions.

? There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property.

? Microchip is willing to work with the customer who is concerned about the integrity of their code.

? Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as "unbreakable."

Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip's code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.

Information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.

Trademarks

The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KEELOQ, KEELOQ logo, microID, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

AmpLab, FilterLab, Linear Active Thermistor, Migratable Memory, MXDEV, MXLAB, PS logo, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A.

Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, , dsPICworks, ECAN, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit, PICDEM, , PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel, Total Endurance, UNI/O, WiperLock and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

All other trademarks mentioned herein are property of their respective companies.

? 2007, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

Printed on recycled paper.

Microchip received ISO/TS-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona, Gresham, Oregon and Mountain View, California. The Company's quality system processes and procedures are for its PIC? MCUs and dsPIC? DSCs, KEELOQ? code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip's quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

DS51284F-page ii

? 2007 Microchip Technology Inc.

Table of Contents

MPLAB? C30 USER'S GUIDE

Preface ........................................................................................................................... 1

Chapter 1. Compiler Overview

1.1 Introduction ..................................................................................................... 7 1.2 Highlights ........................................................................................................ 7 1.3 MPLAB C30 Description ................................................................................. 7 1.4 MPLAB C30 and Other Development Tools ................................................... 7 1.5 MPLAB C30 Feature Set ................................................................................ 9

Chapter 2. Differences Between MPLAB C30 and ANSI C

2.1 Introduction ................................................................................................... 11 2.2 Highlights ...................................................................................................... 11 2.3 Keyword Differences .................................................................................... 11 2.4 Statement Differences .................................................................................. 30 2.5 Expression Differences ................................................................................ 31

Chapter 3. Using MPLAB C30 C Compiler

3.1 Introduction ................................................................................................... 33 3.2 Highlights ...................................................................................................... 33 3.3 Overview ...................................................................................................... 33 3.4 File Naming Conventions ............................................................................. 34 3.5 Options ......................................................................................................... 34 3.6 Environment Variables ................................................................................. 59 3.7 Predefined Constants ................................................................................... 60 3.8 Compiling a Single File on the Command Line ............................................ 60 3.9 Compiling Multiple Files on the Command Line ........................................... 61

? 2007 Microchip Technology Inc.

DS51284F-page iii

MPLAB? C30 User's Guide

Chapter 4. MPLAB C30 C Compiler Runtime Environment

4.1 Introduction ................................................................................................... 63 4.2 Highlights ...................................................................................................... 63 4.3 Address Spaces ........................................................................................... 63 4.4 Code and Data Sections .............................................................................. 65 4.5 Startup and Initialization ............................................................................... 67 4.6 Memory Spaces ........................................................................................... 68 4.7 Memory Models ............................................................................................ 69 4.8 Locating Code and Data ............................................................................... 71 4.9 Software Stack ............................................................................................. 72 4.10 The C Stack Usage .................................................................................... 73 4.11 The C Heap Usage ..................................................................................... 75 4.12 Function Call Conventions ......................................................................... 76 4.13 Register Conventions ................................................................................. 78 4.14 Bit Reversed and Modulo Addressing ........................................................ 79 4.15 Program Space Visibility (PSV) Usage ...................................................... 79

Chapter 5. Data Types

5.1 Introduction ................................................................................................... 81 5.2 Highlights ...................................................................................................... 81 5.3 Data Representation .................................................................................... 81 5.4 Integer .......................................................................................................... 81 5.5 Floating Point ............................................................................................... 82 5.6 Pointers ........................................................................................................ 82

Chapter 6. Device Support Files

6.1 Introduction ................................................................................................... 83 6.2 Highlights ...................................................................................................... 83 6.3 Processor Header Files ................................................................................ 83 6.4 Register Definition Files ............................................................................... 84 6.5 Using SFRs .................................................................................................. 85 6.6 Using Macros ............................................................................................... 87 6.7 Accessing EEDATA from C Code - dsPIC30F dSCs only ............................ 88

Chapter 7. Interrupts

7.1 Introduction ................................................................................................... 91 7.2 Highlights ...................................................................................................... 91 7.3 Writing an Interrupt Service Routine ............................................................ 92 7.4 Writing the Interrupt Vector .......................................................................... 94 7.5 Interrupt Service Routine Context Saving .................................................. 104 7.6 Latency ....................................................................................................... 104 7.7 Nesting Interrupts ....................................................................................... 104 7.8 Enabling/Disabling Interrupts ..................................................................... 105 7.9 Sharing Memory Between Interrupt Service Routines and Mainline Code 106 7.10 PSV Usage with Interrupt Service Routines ............................................. 109

DS51284F-page iv

? 2007 Microchip Technology Inc.

Table of Contents

Chapter 8. Mixing Assembly Language and C Modules

8.1 Introduction ................................................................................................. 111 8.2 Highlights .................................................................................................... 111 8.3 Mixing Assembly Language and C Variables and Functions ..................... 111 8.4 Using Inline Assembly Language ............................................................... 113

Appendix A. Implementation-Defined Behavior

A.1 Introduction ................................................................................................ 121 A.2 Highlights ................................................................................................... 121 A.3 Translation ................................................................................................. 122 A.4 Environment ............................................................................................... 122 A.5 Identifiers ................................................................................................... 123 A.6 Characters ................................................................................................. 123 A.7 Integers ...................................................................................................... 124 A.8 Floating Point ............................................................................................. 124 A.9 Arrays and Pointers ................................................................................... 125 A.10 Registers .................................................................................................. 125 A.11 Structures, Unions, Enumerations and Bit fields ...................................... 126 A.12 Qualifiers .................................................................................................. 126 A.13 Declarators ............................................................................................... 126 A.14 Statements ............................................................................................... 126 A.15 Preprocessing Directives ......................................................................... 127 A.16 Library Functions ..................................................................................... 128 A.17 Signals ..................................................................................................... 129 A.18 Streams and Files .................................................................................... 129 A.19 tmpfile ...................................................................................................... 130 A.20 errno ......................................................................................................... 130 A.21 Memory .................................................................................................... 130 A.22 abort ......................................................................................................... 130 A.23 exit ........................................................................................................... 130 A.24 getenv ...................................................................................................... 131 A.25 system ...................................................................................................... 131 A.26 strerror ..................................................................................................... 131

Appendix B. MPLAB C30 Built-in Functions

B.1 Introduction ................................................................................................ 133 B.2 Built-In Function List .................................................................................. 134

Appendix C. MPLAB C30 C Compiler Diagnostics

C.1 Introduction ................................................................................................ 155 C.2 Errors ......................................................................................................... 155 C.3 Warnings .................................................................................................... 174

? 2007 Microchip Technology Inc.

DS51284F-page v

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download