mikroElektronika PIC Microcontrollers PIC12 User Manual page 89

Mikroc user's manual
Table of Contents

Advertisement

mikroC
making it simple...
Here,
a list of bit fields. Each component identifer requires a colon and its width in bits
to be explicitly specified. Total width of all components cannot exceed one byte (8
bits).
As an object, bit fields structure takes one byte. Individual fields are packed with-
in byte from right to left. In
fier(s) to create artificial "padding", thus skipping irrelevant bits.
For example, if we need to manipulate only bits 2–4 of a register as one block, we
could create a structure:
struct {
unsigned
mybits
} myreg;
Here is an example:
typedef struct {
prescaler
which declares structured type
prescaler
and 6).
Bit Fields Access
Bit fields can be accessed in same way as the structure members. Use direct and
indirect member selector (
previously declared
// Declare a bit field TimerControl:
mybitfield TimerControl;
void main() {
TimerControl.prescaler
TimerControl.timeronoff = 1;
TimerControl.postscaler = 3;
T2CON = TimerControl;
}
MikroElektronika: Development tools - Books - Compilers
is an optional name of the structure;
tag
bitfield-declarator-list
: 2,
// Skip bits 0 and 1, no identifier here
: 3;
// Relevant bits 2, 3, and 4
// Bits 5, 6, and 7 are implicitly left out
: 2; timeronoff : 1; postscaler : 4;} mybitfield;
(bits 0 and 1),
timeronoff
and
.
mybitfield
mikroC - C Compiler for Microchip PIC microcontrollers
bitfield-declarator-list
containing three components:
mybitfield
(bit 2), and
postscaler
). For example, we could work with our
->
like this:
= 0;
is
, you can omit identi-
(bits 3, 4, 5,
page
81

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?

This manual is also suitable for:

Pic microcontrollers pic16Pic microcontrollers pic18

Table of Contents