(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 INTRODUCTION7
1.1 SUPPORTED DEVICES8
1.2 INSTALLATION AND SYSTEM REQUIREMENTS8
Support for Long File Names8
User Interface8
1.3 MPLAB SUPPORT9
1.4 SUMMARY OF DELIVERED FILES9
1.5 SHORT PROGRAM EXAMPLE10
1.6 DEFINING THE PICMICRO DEVICE1
1.7 WHAT TO DO NEXT12
2 VARIABLES13
2.1 INFORMATION ON RAM ALLOCATION13
2.2 DEFINING VARIABLES13
Integer variables14
Floating point14
IEEE754 interoperability15
Fixed point variables16
Assigning variables to RAM addresses17
Supported type modifiers18
Local Variables19
Temporary Variables19
Arrays, structures and unions20
Bitfields20
Typedef21
2.3 USING RAM BANKS21
The bank type modifier21
RAM Bank Selection Bits2
Local user update regions2
2.4 POINTERS23
Pointer models23
The 12 bit Core24
The 14 bit core: the IRP bit25
2.5 CONST DATA SUPPORT26
Storing 14 bit data27
Data of size 16 bit or more27
Code pages28
Merging data28
Examples28
3 SYNTAX29
3.1 STATEMENTS29
if statement29
while statement29
for statement29
do statement30
switch statement30
break statement30
continue statement31
return statement31
goto statement31

CONTENTS 3.2 ASSIGNMENT AND CONDITIONS ....................................................................................................... 31

CC5X C Compiler B Knudsen Data

Special syntax examples31
Conditions32
Bit variables32
Multiplication, division and modulo3
Precedence of C operators3
Mixed variable sizes are allowed34
3.3 CONSTANTS34
Constant Expressions34
Enumeration35
3.4 FUNCTIONS35
Function return values35
Parameters in function calls35
Internal functions35
3.5 TYPE CAST36
3.6 ACCESSING PARTS OF A VARIABLE37
3.7 C EXTENSIONS37
3.8 PREDEFINED SYMBOLS38
Automatically defined macros and symbols39
3.9 UPWARD COMPATIBILITY39
4 PREPROCESSOR DIRECTIVES40
#define40
#include40
#undef40
#if40
#ifdef41
#ifndef41
#elif41
#else41
#endif41
#error41
#pragma41
4.1 THE PRAGMA STATEMENT41
#pragma asm2var 142
#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 CONFIGURATION47
5 COMMAND LINE OPTIONS48
5.1 OPTIONS ON A FILE50
6 PROGRAM CODE51
6.1 PROGRAM CODE PAGES51
Another way of locating functions51
The page type modifier52
Page selection bits52
6.2 SUBROUTINE CALL LEVEL CHECKING52
Stack level checking when using interrupt52
Recursive functions53
6.3 INTERRUPTS53
6.4 STARTUP AND TERMINATION CODE54
Clearing ALL RAM locations54
6.5 LIBRARY SUPPORT5
Math libraries5
Integer libraries56
Fixed point libraries57
Floating point libraries58
Floating point library functions59
Fast and compact inline operations61
Using prototypes and multiple code pages61
Fixed point example62
Floating point example62
How to save code63
6.6 INLINE ASSEMBLY63
Generating Single Instructions67
6.7 OPTIMIZING THE CODE68
Optimized Syntax68
Peephole optimization69
6.8 LINKER SUPPORT70
Variables70
Local variables71
Header files71
Using RAM banks71
Bank bit updating72
Functions72
Using code pages72
Interrupts72
Call level checking73
Computed goto73
Recommendations when using MPLINK73
MPLAB and MPASM support74
The MPLINK script file75
Example with 3 modules7
6.9 THE CDATA STATEMENT80
Storing EEPROM data80
Using the cdata statement81
7 DEBUGGING83

5 7.1 COMPILATION ERRORS..................................................................................................................... 83

CC5X C Compiler B Knudsen Data

Error and warning details84
Some common compilation problems84
7.2 MPLAB DEBUGGING SUPPORT84
ICD debugging85
7.3 ASSERT STATEMENTS85
7.4 DEBUGGING IN ANOTHER ENVIRONMENT86
8 FILES PRODUCED8
8.1 HEX FILE8
8.2 ASSEMBLY OUTPUT FILE8
8.3 VARIABLE FILE89
8.4 LIST FILE90
8.5 FUNCTION CALL STRUCTURE90
9 APPLICATION NOTES91
9.1 DELAYS91
9.2 COMPUTED GOTO92
Built in skip() function for computed goto93
Computed Goto Regions93
9.3 THE SWITCH STATEMENT96
APPENDIX97
A1 USING INTERRUPTS97
A2 PREDEFINED REGISTER NAMES98
A3 ASSEMBLY INSTRUCTIONS98
Addition for the 14 bit core9

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)

Comentários