mikroCDevelop your applications quickly and easily with the world'smost intuitive C compiler for PIC Microcontrollers (familiesPIC12, PIC16, and
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...2MikroElektronika: Development tools - Books - CompilerspagemikroC
Typedef SpecifierSpecifier typedef introduces a synonym for a specified type. You can use type-def declarations to construct shorter or more meaningfu
asm DeclarationC allows embedding assembly in the source code by means of asm declaration.Declarations _asm and __asm are also allowed in mikroC, and
InitializationAt the time of declaration, you can set the initial value of a declared object, i.e.initialize it. Part of the declaration which specifi
Functions are central to C programming. Functions are usually defined as subpro-grams which return a value based on a number of input parameters. Retu
Within parentheses, parameter-declarator-listis a list of formal argumentsthat function takes. These declarators specify the type of each function par
Function DefinitionFunction definition consists of its declaration and a function body. The functionbody is technically a block – a sequence of local
Function CallsA function is called with actual arguments placed in the same sequence as theirmatching formal parameters. Use a function-call operator
If a prototype is present, the number of arguments must match. The types need tobe compatible only to the extent that an assignment can legally conver
Operators are tokens that trigger some computation when applied to variables andother objects in an expression.mikroC recognizes following operators:-
MikroElektronika: Development tools - Books - Compilers101pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prec
MikroElektronika: Development tools - Books - Compilers3pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...The Co
Arithmetic OperatorsArithmetic operators are used to perform mathematical computations. They havenumerical operands and return numerical results. Type
Binary Arithmetic OperatorsDivision of two integers returns an integer, while remainder is simply truncated:/* for example: */7 / 4; // equals
Relational OperatorsUse relational operators to test equality or inequality of expressions. If the expres-sion evaluates to true, it returns 1; otherw
Bitwise OperatorsUse the bitwise operators to modify the individual bits of numerical operands.Bitwise operators associate from left to right. The onl
/* Similarly: */0x1234 | 0x5678;/* equals 0x567C */0x1234 ^ 0x5678;/* equals 0x444C */~ 0x1234;/* equals 0xEDCB */Bitwise Shift OperatorsBinary operat
Logical OperatorsOperands of logical operations are considered true or false, that is non-zero orzero. Logical operators always return 1 or 0. Operand
Logical Expressions and Side EffectsGeneral rule with complex logical expressions is that the evaluation of consecutivelogical operands stops the very
Conditional Operator ? :The conditional operator ? : is the only ternary operator in C. Syntax of the con-ditional operator is:expression1? expression
4. Both of type pointer to qualified or unqualified versions of compatible types. The resulting type is a pointer to a type qualified with all the typ
Thus, we have 10 different compound assignment operators: +=, -=, *=, /=,%=, &=, |=, ^=, <<=, and >>=. All of these associate from rig
Code Assistant [CTRL+SPACE]If you type a first few letter of a word and then press CTRL+SPACE, all the valididentifiers matching the letters you typed
Sizeof OperatorPrefix unary operator sizeof returns an integer constant that gives the size inbytes of how much memory space is used by its operand (d
An expression is a sequence of operators, operands, and punctuators that specifiesa computation. Formally, expressions are defined recursively: subexp
Binary operator comma (,) has the lowest precedence and associates from left toright, so that a, b, c is same as (a, b), c. This allows us to write se
Statements specify the flow of control as a program executes. In the absence ofspecific jump and selection statements, statements are executed sequent
Expression StatementsAny expression followed by a semicolon forms an expression statement:expression;mikroC executes an expression statement by evalua
Nested if statementsNested if statements require additional attention. General rule is that the nestedconditionals are parsed starting from the innerm
Upon finding a match, program flow continues normally: following instructionswill be executed in natural order regardless of the possible case label.
Iteration StatementsIteration statements let you loop a set of statements. There are three forms of itera-tion statements in C: while, do, and for.Whi
Do StatementThe do statement executes until the condition becomes false. Syntax of do state-ment is:dostatementwhile (expression);The statementis exec
All the expressions are optional. If condition-expis left out, it is assumed to bealways true. Thus, “empty” for statement is commonly used to create
Auto CorrectThe Auto Correct feature corrects common typing mistakes. To access the list ofrecognized typos, select Tools > Options from the drop-d
Jump StatementsA jump statement, when executed, transfers control unconditionally. There are foursuch statements in mikroC: break, continue, goto, and
You can use goto to break out from any level of nested control structures. But,goto cannot be used to jump into block while skipping that block’s init
Compound Statements (Blocks)A compound statement, or block, is a list (possibly empty) of statements enclosedin matching braces {}. Syntactically, a b
Preprocessor is an integrated text processor which prepares the source code forcompiling. Preprocessor allows:- inserting text from a specifed file to
Line Continuation with BackslashIf you need to break directive into multiple lines, you can do it by ending the linewith a backslash (\):#define MACRO
A macro won’t be expanded during its own expansion (so #define MACROMACROwon’t expand indefinitely).Let’s have an example:/* Here are some simple macr
Macros with ParametersThe following syntax is used to define a macro with parameters:#define macro_identifier(<arg_list>) token_sequenceNote the
Here is a simple example:// A simple macro which returns greater of its 2 arguments:#define _MAX(A, B) ((A) > (B)) ? (A) : (B)// Let's call it
File InclusionThe preprocessor directive #include pulls in header files (extension .h) into thesource code. Do not rely on preprocessor to include sou
Note: There is also a third version of #include directive, rarely used, whichassumes that neither < nor " appears as the first non-whitespace
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...6MikroElektronika: Development tools - Books - CompilerspageThe Co
Now, the following code,LCD_PRINT(temp)will be preprocessed to this:Lcd_Out_Cp("temp" ": "); Lcd_Out_Cp(IntToStr(temp));Operator #
Directives #if, #elif, #else, and #endifThe conditional directives #if, #elif, #else, and #endif work very similar tothe common C conditional statemen
Any processed sectioncan contain further conditional clauses, nested to anydepth. Each nested #else, #elif, or #endif directive belongs to the closest
CHAPTERMikroElektronika: Development tools - Books - Compilers4mikroC LibrariesmikroC provides a number of built-in and library routines which h
mikroC compiler provides a set of useful built-in utility functions. Built-in func-tions do not require any header files to be included; you can use t
MikroElektronika: Development tools - Books - Compilers137pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC provides a set of libraries which simplifies the initialization and use ofPIC MCU and its modules. Library functions do not require any header
ADC (Analog to Digital Converter) module is available with a number of PICMCU models. Library function Adc_Read is included to provide you comfortable
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...140MikroElektronika: Development tools - Books - CompilerspageLibr
mikroC provides a library (driver) for working with the CAN module.CAN is a very robust protocol that has error detection and signalling, self–check-i
MikroElektronika: Development tools - Books - Compilers7pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...The so
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...142MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers143pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...144MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers145pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...146MikroElektronika: Development tools - Books - CompilerspageProt
There is a number of constants predefined in CAN library. To be able to use thelibrary effectively, you need to be familiar with these. You might want
// ..continued#define CAN_CONFIG_DBL_BUFFER_BIT 0x10#define CAN_CONFIG_DBL_BUFFER_ON 0xFF // XXX1XXXX#define CAN_CONFIG_DBL_BUFFER_OFF 0xEF // XXX
CAN_RX_MSG_FLAGSCAN_RX_MSG_FLAGS are flags related to reception of CAN message. If a particularbit is set; corresponding meaning is TRUE or else it wi
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...150MikroElektronika: Development tools - Books - CompilerspageLibr
MikroElektronika: Development tools - Books - Compilers151pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...// .
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...8MikroElektronika: Development tools - Books - CompilerspageToggle
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...152MikroElektronika: Development tools - Books - CompilerspageRXDV
SPI module is available with a number of PICmicros. mikroC provides a library(driver) for working with the external CAN modules (such as MCP2515 orMCP
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...154MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers155pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...156MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers157pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...158MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers159pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...160MikroElektronika: Development tools - Books - Compilerspage// .
MikroElektronika: Development tools - Books - Compilers161pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...+5VR
Stopwatch WindowThe Stopwatch Window displays the current count of cycles/time since the lastDebugger action. Stopwatch measures the execution time (n
Compact Flash Library provides routines for accessing data on Compact Flashcard (abbrev. CF further in text). CF cards are widely used memory elements
MikroElektronika: Development tools - Books - Compilers163pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...164MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers165pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...166MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers167pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...168MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers169pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...170MikroElektronika: Development tools - Books - CompilerspageNext
MikroElektronika: Development tools - Books - Compilers171pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...+5VC
Call Stack WindowThe Call Stack Window keeps track of depth and order of nested routine calls inprogram simulation. Check the Nested Calls Limitations
EEPROM data memory is available with a number of PICmicros. mikroC includeslibrary for comfortable work with EEPROM.Eeprom_ReadEeprom_WritemikroC- C C
MikroElektronika: Development tools - Books - Compilers173pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
This library is designed to simplify handling of the underlying hardware(RTL8019AS). However, certain level of knowledge about the Ethernet andEtherne
MikroElektronika: Development tools - Books - Compilers175pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...176MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers177pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...178MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers179pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...180MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers181pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
MikroElektronika: Development tools - Books - Compilers11pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...In ca
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...182MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers183pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...184MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers185pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
This library provides routines for accessing microcontroller Flash memory. Notethat prototypes differ for PIC16 and PIC18 families.Flash_ReadFlash_Wri
The example demonstrates simple data exchange via USART. When PIC MCUreceives data, it immediately sends the same data back. If PIC is connected to th
I²C full master MSSP module is available with a number of PIC MCU models.mikroC provides I2C library which supports the master I²C mode.Note: This lib
MikroElektronika: Development tools - Books - Compilers189pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...190MikroElektronika: Development tools - Books - CompilerspageProt
This code demonstrates use of I²C Library functions. PIC MCU is connected(SCL, SDA pins ) to 24c02 EEPROM. Program sends data to EEPROM (data iswritte
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...iiMikroElektronika: Development tools - Books - CompilerspageDISCL
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...12MikroElektronika: Development tools - Books - CompilerspageAfter
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...192MikroElektronika: Development tools - Books - Compilerspage4MHz
mikroC provides library for working with 4x4 keypad; routines can also be usedwith 4x1, 4x2, or 4x3 keypad. Check the connection scheme at the end of
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...194MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers195pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...The
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...196MikroElektronika: Development tools - Books - Compilerspage4MHz
mikroC provides a library for communicating with commonly used LCD (4-bitinterface). Figures showing HW connection of PIC and LCD are given at the end
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...198MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers199pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...200MikroElektronika: Development tools - Books - CompilerspageLCD
MikroElektronika: Development tools - Books - Compilers201pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
MikroElektronika: Development tools - Books - Compilers13pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Proce
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...202MikroElektronika: Development tools - Books - CompilerspageLibr
MikroElektronika: Development tools - Books - Compilers203pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...mikr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...204MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers205pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...206MikroElektronika: Development tools - Books - CompilerspageLibr
MikroElektronika: Development tools - Books - Compilers207pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC provides a library for drawing and writing on Graphic LCD. These rou-tines work with commonly used GLCD 128x64, and work only with the PIC18fam
MikroElektronika: Development tools - Books - Compilers209pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...210MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers211pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
RAM WindowSummarizes all GPR and SFR registers and their addresses. Also displays symbol-ic names of variables and their addresses.ROM WindowLists op-
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...212MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers213pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...214MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers215pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...216MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers217pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...218MikroElektronika: Development tools - Books - Compilerspage118K
mikroC provides a library for handling Manchester coded signals. Manchestercode is a code in which data and clock signals are combined to form a singl
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...220MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers221pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
MikroElektronika: Development tools - Books - Compilers15pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...USART
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...222MikroElektronika: Development tools - Books - CompilerspageLibr
MikroElektronika: Development tools - Books - Compilers223pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Hard
mikroC provides a library for accessing data on Multi Media Card via SPIcommunication.Notes:- Library works with PIC18 family only; - Library function
MikroElektronika: Development tools - Books - Compilers225pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...226MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers227pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...228MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers229pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
MikroElektronika: Development tools - Books - Compilers230pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...231MikroElektronika: Development tools - Books - CompilerspageLibr
7 Segment Display DecoderThe 7seg Display Decoder is a convenient visual panel which returns decimal/hexvalue for any viable combination you would lik
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...232MikroElektronika: Development tools - Books - CompilerspageHard
OneWire library provides routines for communication via OneWire bus, for exam-ple with DS1820 digital thermometer. This is a Master/Slave protocol, an
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...234MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers235pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...236MikroElektronika: Development tools - Books - CompilerspageHard
mikroC provides a library for communicating with common PS/2 keyboard.Thelibrary does not utilize interrupts for data retrieval, and requires oscillat
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...238MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers239pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
CCP module is available with a number of PICmicros. mikroC provides librarywhich simplifies using PWM HW Module.Note: These routines support module on
MikroElektronika: Development tools - Books - Compilers241pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroBootloadermikroBootloader can be used only with PICmicros that support flash write.1. Load the PIC with the appropriate hex file using the conven
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...242MikroElektronika: Development tools - Books - CompilerspageHard
RS-485 is a multipoint communication which allows multiple devices to be con-nected to a single signal cable. mikroC provides a set of library routine
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...244MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers245pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...246MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers247pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...248MikroElektronika: Development tools - Books - CompilerspageHard
Secure Digital (SD) is a flash memory memory card standard, based on the olderMulti Media Card (MMC) format. SD cards are currently available in sizes
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...250MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers251pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...18MikroElektronika: Development tools - Books - CompilerspageBelow
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...252MikroElektronika: Development tools - Books - CompilerspageLibr
MikroElektronika: Development tools - Books - Compilers253pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Hard
mikroC provides routines which implement software I²C. These routines are hard-ware independent and can be used with any MCU. Software I2C enables you
MikroElektronika: Development tools - Books - Compilers255pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...256MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers257pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC provides library which implement software SPI. These routines are hard-ware independent and can be used with any MCU. You can easily communicat
MikroElektronika: Development tools - Books - Compilers259pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...260MikroElektronika: Development tools - Books - CompilerspageLibr
mikroC provides library which implements software UART. These routines arehardware independent and can be used with any MCU. You can easily communi-ca
Debugger ShortcutsF4 Run to CursorF5 Toggle breakpointF6 Run/Pause DebuggerF7 Step intoF8 Step overF9 DebugCTRL+F2 ResetMikroElek
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...262MikroElektronika: Development tools - Books - CompilerspageProt
The example demonstrates simple data exchange via software UART. When PICMCU receives data, it immediately sends the same data back. If PIC is connect
mikroC provides a Sound Library which allows you to use sound signalization inyour applications. You need a simple piezo speaker (or other hardware) o
The example is a simple demonstration of how to use sound library for playingtones on a piezo speaker. The code can be used with any MCU that has PORT
SPI module is available with a number of PIC MCU models. mikroC provides alibrary for initializing Slave mode and comfortable work with Master mode. P
MikroElektronika: Development tools - Books - Compilers267pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...268MikroElektronika: Development tools - Books - CompilerspageProt
The code demonstrates how to use SPI library functions. Assumed HW configura-tion is: max7219 (chip select pin) connected to RC1, and SDO, SDI, SCK pi
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...270MikroElektronika: Development tools - Books - CompilerspageHW C
USART hardware module is available with a number of PICmicros. mikroCUSART Library provides comfortable work with the Asynchronous (full duplex)mode.Y
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...20MikroElektronika: Development tools - Books - Compilerspage
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...272MikroElektronika: Development tools - Books - CompilerspageProt
The example demonstrates simple data exchange via USART. When PIC MCUreceives data, it immediately sends the same data back. If PIC is connected to th
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...274MikroElektronika: Development tools - Books - CompilerspageSUB-
Universal Serial Bus (USB) provides a serial bus standard for connecting a widevariety of devices, including computers, cell phones, game consoles, PD
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...276MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers277pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Libr
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...278MikroElektronika: Development tools - Books - Compilerspage// T
MikroElektronika: Development tools - Books - Compilers279pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...HW C
Util library contains miscellaneous routines useful for project development.mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simpl
mikroC provides a set of standard ANSI C library functions for testing and map-ping characters.Note: Not all of the standard functions have been inclu
CHAPTERMikroElektronika: Development tools - Books - Compilers2BuildingApplicationsCreating applications in mikroC is easy and intuitive. Projec
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...282MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers283pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...284MikroElektronika: Development tools - Books - CompilerspageProt
mikroC provides a set of standard ANSI C library functions for floating pointmath handling.Note: Functions have been implemented according to the ANSI
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...286MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers287pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...288MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers289pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...290MikroElektronika: Development tools - Books - CompilerspageProt
mikroC provides a set of standard ANSI C library functions of general utility.Note: Not all of the standard functions have been included. Functions ha
MikroElektronika: Development tools - Books - CompilersTable of ContentsCHAPTER 1 mikroC IDECHAPTER 2 Building ApplicationsCHAPTER 3 mikroC Refe
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...22MikroElektronika: Development tools - Books - Compilerspagemikro
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...292MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers293pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...294MikroElektronika: Development tools - Books - CompilerspageProt
mikroC provides a set of standard ANSI C library functions useful for manipulat-ing strings and arrays of char.Note: Not all of the standard functions
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...296MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers297pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...298MikroElektronika: Development tools - Books - CompilerspageProt
mikroC Conversions Library provides routines for converting numerals to strings,and routines for BCD/decimal conversions.You can get text representati
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...300MikroElektronika: Development tools - Books - CompilerspageProt
MikroElektronika: Development tools - Books - Compilers301pagemikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...Prot
Source files containing C code should have the extension .c. List of source filesrelevant for the application is stored in project file with extension
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...302MikroElektronika: Development tools - Books - CompilerspageProt
mikroC implements fundamental trigonometry functions. These functions areimplemented as lookup tables, and return the result as integer, multiplied by
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...304MikroElektronika: Development tools - Books - CompilerspageIf y
Paths for Header Files (.h)Header files are included by means of preprocessor directive #include. If youplace an explicit path to the header file in p
Opening an Existing FileSelect File > Open from drop-down menu, or press CTRL+O, or click the OpenFile icon. The Select Input File dialog opens. In
When you have created the project and written the source code, you will want tocompile it. Select Project > Build from drop-down menu, or click Bui
Error Messages- Specifier needed- Invalid declarator- Expected '(' or identifier- Integer const expected- Array dimension must be greater th
- Inconsistent storage class- Inconsistent type- %s tag redefined- Illegal typecast- %s is not a valid identifier- Invalid statement- Constant express
CHAPTERMikroElektronika: Development tools - Books - Compilers3mikroC LanguageReferenceC offers unmatched power and flexibility in programming m
In order to get the most from your mikroC compiler, you should be familiar withcertain aspects of PIC MCU. This knowledge is not essential, but it can
PIC16 SpecificsBreaking Through PagesIn applications targeted at PIC16, no single routine should exceed one page (2,000instructions). If routine does
CHAPTER 1: mikroC IDE 1Quick Overview 1Code Editor 3Code Explorer 6Debugger 7Error Window 11Statistics 12Integrated Tools 15Keyboard Shortcuts 19C
ANSI Standard IssuesDivergence from the ANSI C StandardmikroC diverges from the ANSI C standard in few areas. Some of these modifica-tions are improve
Predefined Globals and ConstantsTo facilitate PIC programming, mikroC implements a number of predefined glob-als and constants.All PIC SFR registers a
InterruptsInterrupts can be easily handled by means of reserved word interrupt. mikroCimplictly declares function interrupt which cannot be redeclared
Linker DirectivesmikroC uses internal algorithm to distribute objects within memory. If you need tohave variable or routine at specific predefined add
These topics provide a formal definition of the mikroC lexical elements. Theydescribe the different categories of word-like units (tokens) recognized
CommentsComments are pieces of text used to annotate a program, and are technicallyanother form of whitespace. Comments are for the programmer’s use o
Token is the smallest element of a C program that is meaningful to the compiler.The parser separates tokens from the input stream by creating the long
Constants or literals are tokens representing fixed numeric or character values.mikroC supports:- integer constants,- floating point constants,- chara
Otherwise:If the constant has a U or u suffix, its data type will be the first of the followingthat can accommodate its value: unsigned short, unsigne
Binary ConstantsAll constants starting with 0b (or 0B) are taken to be binary. In the absence of anyoverriding suffixes, the data type of an binary co
Keywords 46Identifiers 47Punctuators 48Objects and Lvalues 52Scope and Visibility 54Name Spaces 56Duration 57Types 59Fundamental Types 60Arithmetic Ty
Character ConstantsA character constant is one or more characters enclosed in single quotes, such as'A', '+', or '\n'. I
The following table shows the available escape sequences in mikroC:MikroElektronika: Development tools - Books - Compilers43pagemikroC- C Compil
String ConstantsString constants, also known as string literals, are a special type of constantswhich store fixed sequences of characters. A string li
Enumeration ConstantsEnumeration constants are identifiers defined in enum type declarations. The iden-tifiers are usually chosen as mnemonics to assi
Keywords are words reserved for special purposes and must not be used as normalidentifier names.Beside standard C keywords, all relevant SFR are defin
Identifiers are arbitrary names of any length given to functions, variables, symbol-ic constants, user-defined data types, and labels. All these progr
The mikroC punctuators (also known as separators) include brackets, parentheses,braces, comma, semicolon, colon, asterisk, equal sign, and pound sign.
BracesBraces { } indicate the start and end of a compound statement:if (d == z) {++x;func();}The closing brace serves as a terminator for the compound
SemicolonThe semicolon (;) is a statement terminator. Any legal C expression (including theempty expression) followed by a semicolon is interpreted as
Equal SignThe equal sign (=) separates variable declarations from initialization lists:int test[5] = {1, 2, 3, 4, 5};int x = 5;The equal sign is also
Expressions 113Statements 115Labeled Statements 115Expression Statements 116Selection Statements 116Iteration Statements 119Jump Statements 122Compoun
ObjectsAn object is a specific region of memory that can hold a fixed or variable value(or set of values). To prevent confusion, this use of the word
LvaluesAn lvalue is an object locator: an expression that designates an object. An exampleof an lvalue expression is *P, where P is any expression eva
ScopeThe scope of identifier is the part of the program in which the identifier can beused to access its object. There are different categories of sco
VisibilityThe visibility of an identifier is that region of the program source code from whichlegal access can be made to the identifier’s associated
Name space is the scope within which an identifier must be unique. C uses fourdistinct categories of identifiers:Goto label namesThese must be unique
Duration, closely related to storage class, defines the period during which thedeclared identifiers have real, physical objects allocated in memory. W
Here is an example of two objects with local scope, but with different duration:void f() {/* local duration var; init a upon every call to f */int a =
C is strictly typed language, which means that every object, function, and expres-sion need to have a strictly defined type, known in the time of comp
Arithmetic TypesThe arithmetic type specifiers are built from the following keywords: void, char,int, float, and double, together with prefixes short,
Below is the overview of arithmetic types:MikroElektronika: Development tools - Books - Compilers61pagemikroC- C Compiler for Microchip PIC micr
SPI Library 266USART Library 271USB HID Library 275Util Library 280ANSI C Ctype Library 281ANSI C Math Library 285ANSI C Stdlib Library 291ANSI C Stri
EnumerationsAn enumeration data type is used for representing an abstract, discreet set of val-ues with appropriate symbolic names.Enumeration Declara
The order of constants can be explicitly re-arranged. For example:enum colors { black,// value 0red,// value 1green,// value 2blue=6,// value 6violet,
Void Typevoid is a special type indicating the absence of any value. There are no objects ofvoid; instead, void is used for deriving more complex type
The derived types are also known as structured types. These types are used as ele-ments in creating more complex user-defined types.ArraysArray is the
Array InitializationArray can be initialized in declaration by assigning it a comma-delimited sequenceof values within braces. When initializing an ar
Multi-dimensional ArraysAn array is one-dimensional if it is of scalar type. One-dimensional arrays aresometimes referred to as vectors.Multidimension
PointersPointers are special objects for holding (or “pointing to”) memory addresses. In C,address of an object in memory can be obtained by means of
Note: You must initialize pointers before using them! Our previously declaredpointer *p is not initialized (i.e. assigned a value), so it cannot be us
Pointer ArithmeticPointer arithmetic in C is limited to:- assigning one pointer to another,- comparing two pointers,- comparing pointer to zero (NULL)
According to these guidelines, we can write:pa = &a[4];// pa points to a[4]x = *(pa + 3);// x = a[7]y = *pa + 3;// y = a[4] + 3Also, you need to b
mikroC- C Compiler for Microchip PIC microcontrollersmikroCmaking it simple...viiiMikroElektronika: Development tools - Books - Compilerspage
You can also compare pointers to zero value – this tests if pointer actually pointsto anything. All pointers can be successfully tested for equality o
This allows you to write loops which access the array elements in a sequence bymeans of incrementing pointer — in the last iteration you will have a p
StructuresA structure is a derived type usually representing a user-defined collection ofnamed members (or components). The members can be of any type
Note that you can omit structure tag, but then you cannot declare additionalobjects of this type elsewhere. For more information, see the “UntaggedStr
Structure AssignmentVariables of same structured type may be assigned one to another by means ofsimple assignment operator (=). This will copy the ent
Structure Member AccessStructure and union members are accessed using the following two selection oper-ators:. (period)-> (right arrow)The operator
Accessing Nested StructuresIf structure B contains a field whose type is structure A, the members of A can beaccessed by two applications of the membe
UnionsUnion types are derived types sharing many of the syntactic and functional fea-tures of structure types. The key difference is that a union allo
Referring to declarations from the previous example:mu.d = 4.016;Lcd_Out_Cp(FloatToStr(mu.d));// OK: displays mu.d = 4.016Lcd_Out_Cp(IntToStr(mu.i));/
Here, tagis an optional name of the structure; bitfield-declarator-listisa list of bit fields. Each component identifer requires a colon and its width
CHAPTERMikroElektronika: Development tools - Books - Compilers1mikroC IDEmikroC is a powerful, feature rich development tool for PICmicros. It i
C is strictly typed language, with each operator, statement and function demandingappropriately typed operands/arguments. However, we often have to us
Arithmetic ConversionsWhen you use an arithmetic expression, such as a+b, where a and b are of differ-ent arithmetic types, mikroC performs implicit t
The result of the expression is the same type as that of the two operands.Here are several examples of implicit conversion:2+3.1// = 2. + 3.1 = 5.15/4
Introduction to DeclarationsDeclaration introduces one or several names to a program – it informs the compil-er what the name represents, what is its
Let’s have an example:/* Here is a nondefining declaration of function max; *//* it merely informs compiler that max is a function */int max();/* Here
LinkageAn executable program is usually created by compiling several independent trans-lation units, then linking the resulting object files with pree
External Linkage Rule:1. names having file scope, that do not comply to any of previously stated internal linkage rules, have external linkage.The sto
Storage ClassesAssociating identifiers with objects requires each identifier to have at least twoattributes: storage class and type (sometimes referre
StaticGlobal name declared with static specifier has internal linkage, meaning that itis local for a given file. See Linkage for more information.Loca
Type QualifiersType qualifiers const and volatile are optional in declarations and do not actu-ally affect the type of declared object.Qualifier const
Commentaires sur ces manuels