Abl-electronic PIC Microcontrollers PIC16 Manuel d'utilisateur Page 89

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 312
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 88
Here,
tag
is an optional name of the structure;
bitfield-declarator-list
is
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
bitfield-declarator-list
, you can omit identi-
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 : 2,
// Skip bits 0 and 1, no identifier here
mybits : 3;
// Relevant bits 2, 3, and 4
// Bits 5, 6, and 7 are implicitly left out
} myreg;
Here is an example:
typedef struct {
prescaler : 2; timeronoff : 1; postscaler : 4;} mybitfield;
which declares structured type mybitfield containing three components:
prescaler (bits 0 and 1), timeronoff (bit 2), and postscaler (bits 3, 4, 5,
and 6).
Bit Fields Access
Bit fields can be accessed in same way as the structure members. Use direct and
indirect member selector (
. and ->). For example, we could work with our
previously declared mybitfield like this:
// Declare a bit field TimerControl:
mybitfield TimerControl;
void main() {
TimerControl.prescaler = 0;
TimerControl.timeronoff = 1;
TimerControl.postscaler = 3;
T2CON = TimerControl;
}
MikroElektronika:
Development
tools
-
Books
-
Compilers
81
page
mikroC
- C Compiler for Microchip PIC microcontrollers
mikroC
making it simple...
Vue de la page 88
1 2 ... 84 85 86 87 88 89 90 91 92 93 94 ... 311 312

Commentaires sur ces manuels

Pas de commentaire