Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


Figure 12: from page 92 of the ATMega169 data book


Fast PWM mode and CLK/256 prescaler
TCCR0A |= (1<<WGM01)|(1<<WGM00)|(4<<CS00);

We use the left shift o number before the operand to the
numeric position in th the number following the operand. In
the case of (1<<WGM01) we shift a 1 to the left by WGM01 bit positions, and we
see from iom169.h:


#define FOC0A 7
#defin
#defin
#defin
#defin
#defin
#defin 1

Let’s initialize the timer with:


// Set


perator ’<<’ to shif
ed by

t the
e byte specifi

/* TCCR0A */

e WGM00 6
e COM0A1 5
e COM0A0 4
e WGM01 3
e CS02 2
e CS01
#define CS00 0

WGM01 = 3, so (1<<WGM01) is the same as (1<<3) and means to shift 0000001
three places left to 00001000. Now look at The TCCR0A register and notice
where the WGM01 bit is located. Ah ha! Like I said, we have a way of dealing
with a bit by a name.

Free download pdf