Getting Started

(lily) #1

Chapter 10: C Structures


tructure Arrays


s u
stru
struct pwm pulser4k10;


pulser1k50 = makePWM(1000,128);//make a 50% duty 1000 kHz pulse
pulser1k25 = makePWM(1000,64);//make a 25% duty 1000 kHz pulse
pulser4k10 = makePWM(4000,25);//make a 10% duty 4000 kHz pulse


We could have defined an array of these structures and made them as follows


the
mes carry more user information. pulser1k25 versus pulser[1]. But
re arrays of structures come in real handy.

ames with the typedef facility.

e;

e anything declared as Byte as if it was an
es can be aliased in this manner. Typedef works
es an alias, but defines are handled by the
can do.

software more readable: Byte makes more sense in
facilitate portability of software by
ou can change them as you change

S


In the last section we used:


tr ct pwm pulser1k50;
ct pwm pulser1k25;

struct pwm pulser[] = {
{ 1000, 128 };
{ 1000, 64 };
{ 4000, 25);
}


Actually the prior, non-array version probably makes more sense because
instance na
there are cases whe


Typedef........................................................................................................


C allows us to create new data type n


typedef unsigned char Byt


would cause the compiler to handl
unsigned char. Only actual C typ
somewhat like define, in that it provid
preprocessor and more limited in what they


Typedefs are useful in making
our use than unsigned char. Another use is to
putting machine specific types in typedefs so y
machines.

Free download pdf