aula de compiladores.
cc5x - 31
(Parte 1 de 14)
CC5X
C Compiler for the PICmicro Devices
Version 3.1
User's Manual
B Knudsen Data Trondheim - Norway
CC5X C Compiler B Knudsen Data
This manual and the CC5X compiler is protected by Norwegian copyright laws and thus by corresponding copyright laws agreed internationally by mutual consent. The manual and the compiler may not be copied, partially or as a whole without the written consent from the author. The PDF-edition of the manual can be printed to paper for private or local use, but not for distribution. Modification of the manual or the compiler is strongly prohibited. All rights reserved.
LICENSE AGREEMENT: By using the CC5X compiler, you agree to be bound by this agreement. Only one person may use a licensed CC5X compiler at the same time. If more than one person want to use the compiler for each license, then this have to be done by some manual handshaking procedure (not electronic automated), for instance by exchanging this manual as a permission key. You may make backup copies of the software, and copy it to multiple computers. You may not distribute copies of the compiler to others. B Knudsen Data assumes no responsibility for errors or defects in this manual or in the compiler. This also applies to problems caused by such errors.
Copyright © B Knudsen Data, Trondheim, Norway, 1992 - 2000
This manual covers CC5X version 3.1 and related topics. New versions may contain changes without prior notice.
Microchip and PICmicro are trademarks of Microchip Technology Inc., Chandler, U.S.A.
The compiler has been carefully tested and debugged. It is, however, not possible to guarantee a 100 % error free product.
If the compiler generates application code bugs, it is almost always possible to rewrite the program slightly in order to avoid the bug. #pragma optimize can be used to avoid optimization bugs. Other #pragma statements are also useful.
Please report cases of bad generated code and other serious program errors.
1) Investigate and describe the problem. If possible, please provide a short code sample which demonstrates the problem. A fragment of the generated assembly file (use cut and paste) is normally enough. Alternatively a short and complete C program (10 - 100 lines). 2) This service is intended for difficult compiler problems (not application problems). 3) Language: English 4) State the compiler version. 5) Send your report to support@bknd.com or by fax to (+47) 73 96 51 84.
CC5X C Compiler B Knudsen Data
| 1 INTRODUCTION | 7 |
| 1.1 SUPPORTED DEVICES | 8 |
| 1.2 INSTALLATION AND SYSTEM REQUIREMENTS | 8 |
| Support for Long File Names | 8 |
| User Interface | 8 |
| 1.3 MPLAB SUPPORT | 9 |
| 1.4 SUMMARY OF DELIVERED FILES | 9 |
| 1.5 SHORT PROGRAM EXAMPLE | 10 |
| 1.6 DEFINING THE PICMICRO DEVICE | 1 |
| 1.7 WHAT TO DO NEXT | 12 |
| 2 VARIABLES | 13 |
| 2.1 INFORMATION ON RAM ALLOCATION | 13 |
| 2.2 DEFINING VARIABLES | 13 |
| Integer variables | 14 |
| Floating point | 14 |
| IEEE754 interoperability | 15 |
| Fixed point variables | 16 |
| Assigning variables to RAM addresses | 17 |
| Supported type modifiers | 18 |
| Local Variables | 19 |
| Temporary Variables | 19 |
| Arrays, structures and unions | 20 |
| Bitfields | 20 |
| Typedef | 21 |
| 2.3 USING RAM BANKS | 21 |
| The bank type modifier | 21 |
| RAM Bank Selection Bits | 2 |
| Local user update regions | 2 |
| 2.4 POINTERS | 23 |
| Pointer models | 23 |
| The 12 bit Core | 24 |
| The 14 bit core: the IRP bit | 25 |
| 2.5 CONST DATA SUPPORT | 26 |
| Storing 14 bit data | 27 |
| Data of size 16 bit or more | 27 |
| Code pages | 28 |
| Merging data | 28 |
| Examples | 28 |
| 3 SYNTAX | 29 |
| 3.1 STATEMENTS | 29 |
| if statement | 29 |
| while statement | 29 |
| for statement | 29 |
| do statement | 30 |
| switch statement | 30 |
| break statement | 30 |
| continue statement | 31 |
| return statement | 31 |
| goto statement | 31 |
CONTENTS 3.2 ASSIGNMENT AND CONDITIONS ....................................................................................................... 31
CC5X C Compiler B Knudsen Data
| Special syntax examples | 31 |
| Conditions | 32 |
| Bit variables | 32 |
| Multiplication, division and modulo | 3 |
| Precedence of C operators | 3 |
| Mixed variable sizes are allowed | 34 |
| 3.3 CONSTANTS | 34 |
| Constant Expressions | 34 |
| Enumeration | 35 |
| 3.4 FUNCTIONS | 35 |
| Function return values | 35 |
| Parameters in function calls | 35 |
| Internal functions | 35 |
| 3.5 TYPE CAST | 36 |
| 3.6 ACCESSING PARTS OF A VARIABLE | 37 |
| 3.7 C EXTENSIONS | 37 |
| 3.8 PREDEFINED SYMBOLS | 38 |
| Automatically defined macros and symbols | 39 |
| 3.9 UPWARD COMPATIBILITY | 39 |
| 4 PREPROCESSOR DIRECTIVES | 40 |
| #define | 40 |
| #include | 40 |
| #undef | 40 |
| #if | 40 |
| #ifdef | 41 |
| #ifndef | 41 |
| #elif | 41 |
| #else | 41 |
| #endif | 41 |
| #error | 41 |
| #pragma | 41 |
| 4.1 THE PRAGMA STATEMENT | 41 |
| #pragma asm2var 1 | 42 |
| #pragma assert [/] <type> <text field> | 42 |
| #pragma assume *<pointer> in rambank <n> | 42 |
| #pragma bit <name> @ <N.B or variable[.B]> | 42 |
| #pragma cdata[ADDRESS] = <VXS>, .., <VXS> | 42 |
| #pragma char <name> @ <constant or variable> | 43 |
| #pragma chip [=] <device> | 43 |
| #pragma codepage [=] <0,1,2,3> | 43 |
| #pragma computedGoto [=] <0,1,2> | 43 |
| #pragma config <id> = <state> [, <id> = <state>] | 43 |
| #pragma config_def [=] <value> | 4 |
| #pragma library <0/1> | 4 |
| #pragma location [=] <0,1,2,3,-> | 4 |
| #pragma optimize [=] [N:] <0,1> | 4 |
| #pragma origin [=] <n> | 4 |
| #pragma rambank [=] <0,1,2,3,-> | 45 |
| #pragma rambase [=] <n> | 45 |
| #pragma ramdef <ra> : <rb> [MAPPING] | 45 |
| #pragma resetVector <n> | 45 |
| #pragma return[<n>] = <strings or constants> | 45 |
| #pragma stackLevels <n> | 46 |
| #pragma update_FSR [=] <0,1> | 46 |
CC5X C Compiler B Knudsen Data
| #pragma update_PAGE [=] <0,1> | 46 |
| #pragma update_RP [=] <0,1> | 46 |
| #pragma wideConstData [<N>] | 47 |
| 4.2 PICMICRO CONFIGURATION | 47 |
| 5 COMMAND LINE OPTIONS | 48 |
| 5.1 OPTIONS ON A FILE | 50 |
| 6 PROGRAM CODE | 51 |
| 6.1 PROGRAM CODE PAGES | 51 |
| Another way of locating functions | 51 |
| The page type modifier | 52 |
| Page selection bits | 52 |
| 6.2 SUBROUTINE CALL LEVEL CHECKING | 52 |
| Stack level checking when using interrupt | 52 |
| Recursive functions | 53 |
| 6.3 INTERRUPTS | 53 |
| 6.4 STARTUP AND TERMINATION CODE | 54 |
| Clearing ALL RAM locations | 54 |
| 6.5 LIBRARY SUPPORT | 5 |
| Math libraries | 5 |
| Integer libraries | 56 |
| Fixed point libraries | 57 |
| Floating point libraries | 58 |
| Floating point library functions | 59 |
| Fast and compact inline operations | 61 |
| Using prototypes and multiple code pages | 61 |
| Fixed point example | 62 |
| Floating point example | 62 |
| How to save code | 63 |
| 6.6 INLINE ASSEMBLY | 63 |
| Generating Single Instructions | 67 |
| 6.7 OPTIMIZING THE CODE | 68 |
| Optimized Syntax | 68 |
| Peephole optimization | 69 |
| 6.8 LINKER SUPPORT | 70 |
| Variables | 70 |
| Local variables | 71 |
| Header files | 71 |
| Using RAM banks | 71 |
| Bank bit updating | 72 |
| Functions | 72 |
| Using code pages | 72 |
| Interrupts | 72 |
| Call level checking | 73 |
| Computed goto | 73 |
| Recommendations when using MPLINK | 73 |
| MPLAB and MPASM support | 74 |
| The MPLINK script file | 75 |
| Example with 3 modules | 7 |
| 6.9 THE CDATA STATEMENT | 80 |
| Storing EEPROM data | 80 |
| Using the cdata statement | 81 |
| 7 DEBUGGING | 83 |
5 7.1 COMPILATION ERRORS..................................................................................................................... 83
CC5X C Compiler B Knudsen Data
| Error and warning details | 84 |
| Some common compilation problems | 84 |
| 7.2 MPLAB DEBUGGING SUPPORT | 84 |
| ICD debugging | 85 |
| 7.3 ASSERT STATEMENTS | 85 |
| 7.4 DEBUGGING IN ANOTHER ENVIRONMENT | 86 |
| 8 FILES PRODUCED | 8 |
| 8.1 HEX FILE | 8 |
| 8.2 ASSEMBLY OUTPUT FILE | 8 |
| 8.3 VARIABLE FILE | 89 |
| 8.4 LIST FILE | 90 |
| 8.5 FUNCTION CALL STRUCTURE | 90 |
| 9 APPLICATION NOTES | 91 |
| 9.1 DELAYS | 91 |
| 9.2 COMPUTED GOTO | 92 |
| Built in skip() function for computed goto | 93 |
| Computed Goto Regions | 93 |
| 9.3 THE SWITCH STATEMENT | 96 |
| APPENDIX | 97 |
| A1 USING INTERRUPTS | 97 |
| A2 PREDEFINED REGISTER NAMES | 98 |
| A3 ASSEMBLY INSTRUCTIONS | 98 |
| Addition for the 14 bit core | 9 |
CC5X C Compiler B Knudsen Data
1 INTRODUCTION
Welcome to the CC5X C compiler for the Microchip PICmicro family of microcontrollers. The CC5X compiler enables programming using a subset of the C language. Assembly is no longer required. The reason for moving to C is clear. Assembly language is generally hard to read and errors are easily produced.
C enables the following advantages compared to assembly: • Source code standardization
• Faster program development
• Improved source code readability
• Easier documentation
• Simplified maintenance
• Portable code
The CC5X compiler was designed to generate tight and optimized code. The optimizer automatically squeezes the code to a minimum. It is possible to write code that compiles into single instructions, but with C syntax. This means that the code can be optimized by rewriting C instead of rewriting assembly.
The design priority was not to provide full ANSI C support, but to enable best possible usage of the limited code and RAM resources. If the compiler generated less optimal code, this would force assembly to be used for parts of the code.
CC5X features
• Local and global variables of 1, 8, 16, 24 and 32 bits • Efficient reuse of local variable space
• Generates tight and optimized code
• Produces binary, assembly, list, COD, error, function outline and variable files
• Automatic updating of the page selection bits
• Automatic updating of the bank selection bits
• Enhanced and compact support of bit operations, including bit functions
• Floating and fixed point math up to 32 bit
• Math libraries including functions like sin(), log(), exp(), sqrt(), etc.
• Supports standard C constant data and strings in program memory (const)
• Automatic storing of compressed 7 bit data in PIC16F87X devices
• Pointer models of 8 and 16 bits, mixed sizes in same application allowed
• RAM and/or ROM pointers
• The size of single pointers can be automatically chosen by the compiler
• Linker support (MPLINK), interfaces with assembly (MPASM) modules
• Extended call level by using GOTO instead of CALL when possible
• Inserts links to "hidden" subroutines
• Access to all assembly instructions through corresponding C statements
(Parte 1 de 14)











