Getting Started

(lily) #1

Chapter 10: C Structures


ures can be nested:

}myPWMS;


ake programs

truc


You can do four things to a structure:


1.
2.


  1. Take its address with &




Let’s w to use structures
with th



  1. Pass components to the functions separately.

  2. Pass an entire structure to the function.

  3. Pass a pointer to a structure to the function.


In a moment we’ll see why #3 is best.


y = pulser1.pulseWidth // y now equals 127;


Struct


struct pwms {
struct pwm pulser1;
struct pwm pulser2;
struct pwm pulser2;
int numPulsers = 3;


and to access pulser1 pulseFreq we use:


x = myPWMS.pulser1.pulseFreq;


While it may not seem like it at this time, this kind of syntax can m
easier to write and understand, with the usually warning that C gurus will use
them to impress and thereby confuse you.


Structures and Functions


Copy it
Assign to it as a unit

Access its members

rite some functions to modulate some pulses and see how
em. We could approach this three ways:
Free download pdf