Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


or 1 so how the heck do we set a bit to 4?. Well, or
ourse we don’t. The CS00 = 0, so we are left shifting the number 4 by 0 meaning
ny shifting of the 4, we are just ORing it with the other two
values:


TCCR0A |= (1<<WGM01)|(1<<WGM00)|(4<<CS00);


hat the lower three bytes of the TCC0RA register can be
considered a three bit select the clock. The number 4


ulti-bit fields.

er’ (this will be explained
r section) to set bits 6, 3, and 2 ( x4C)
g the other R it like before we wou

|= 0x4C;

xxxx n’t know, or need to
100110
----------- ------
= x1xx11x = our bits are set the rest

blem is what does it mean to setup the timer wit en you
A |= 0x4C; you don’t know what it is doing and you have to derive
d look in the d

1<<WG 1)|(1<<WGM00)|(4<<CS00);

he (1<<WGM01)|(1<<WGM00)|(4<<CS00) is the same as 0x4C except that we
an read that we are setting both the Waveform Generation bits and we are setting

But wait, wouldn’t that mean that (4<<CS00) means we are setting the CS00 bit
to 4? But a bit can only be 0
c
we aren’t doing a


Since 4 = 00000100, we will be setting the CS02 bit, not the CS00 bit. So why
didn’t we say (1<<CS02) instead of (4<<CS00)? And the answer is ‘because’.
Actually the answer is t
field for a number used to
selects the clock/256 prescaler (see the Clock Select Bit table in Figure 12 above).
Now we can see that (5<<CS00) would mean set the clock to clk/1024 and so
forth. We will often think in terms of m


Our goal was to ‘Set Fast PWM mode, CLK/256 prescal
later in the time
ectin


so we want
e O

01001100 = 0

without aff bits. If w ld:


TCC0RA


Which is:


TCC0RA = xxx x = we do o.
0x4C = 0 0




OR x are not
changed.


The only pro h 0x4C? Wh
see TCC0R
the binary an ata book to figure it out. But using:


TCCR0A |= (
M0


T
c

Free download pdf