ABL electronic PIC Microcontrollers PIC18 User Manual

Page of 312
Predefined Globals and Constants
To facilitate PIC programming, mikroC implements a number of predefined glob-
als and constants.
All PIC SFR registers are implicitly declared as global variables of 
volatile
unsigned short
. These identifiers have external linkage, and are visible in the
entire project. When creating a project, mikroC will include an appropriate .def
file, containing declarations of available SFR and constants (such as 
T0IE
INTF
,
etc). Identifiers are all in uppercase, identical to nomenclature in Microchip
datasheets. For the complete set of predefined globals and constants, look for
“Defs” in your mikroC installation folder, or probe the Code Assistant for specific
letters (Ctrl+Space in Editor).
Device Clock Constants
There are two built-in constants related to device clock: 
___FOSC
and 
___FCY
.
Constant 
___FOSC
equals the frequency that is provided by an external oscillator,
while 
___FCY
is the operating frequency of PIC. Both constants can be used any-
where in the code, and are automatically updated as you change target PIC in your
project. Source files that use these constants are recompiled any time the clock is
changed in IDE.
Accessing Individual Bits
mikroC allows you to access individual bits of 8-bit variables, types 
char
and
unsigned short
. Simply use the direct member selector (
.
) with a variable,
followed by one of identifiers 
F0
F1
, … , 
F7
. For example:
// If RB0 is set, set RC0:
if
(PORTB.F0) PORTC.F0 = 1;
There is no need for any special declarations; this kind of selective access is an
intrinsic feature of mikroC and can be used anywhere in the code. Identifiers
F0
F7
are not case sensitive and have a specific namespace.
Provided you are familiar with the particular chip, you can access bits by their
name:
INTCON.TMR0F = 0;  
// Clear TMR0F
MikroElektronika:  Development  tools  -  Books  -  Compilers
33
page
mikroC - C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...