Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


ay still have to use the data book to look at the
enerator and Clock Select tables, but it is still clearer isn’t it?

r chance at knowing what is going on?

TCC0RA |= 0x4C;
Ve r s u s :
TCCR0A |= (1<<WGM01)|(1<<WGM00)|(4<<CS00);


Heck, I don’t know, but it is how the guys in Norway do it so we’ll give them the
benefit of the doubt and do it the Norway way and be able to steal all that cool
Butterfly code.


Testing Bits
Now we have our timer setup, but suppose there is a function that needs to know
how the Waveform Generator is set so that it can choose among several
alternative actions? We can test a bit by using the AND operator, but not assigning
any values. For example:


Waveform Generator Modes:


WGM01 WGM00 Mode

the clock prescaler to 4, we m
Waveform g


Which gives you a bette


0 0 Normal
0 1 PWM, phase correct
1 0 CTC
1 1 Fast PWM

if( !(TCC0RA & WGM01) && !(TCC0RA & WGM00) )
{
// do this only if in the normal mode
}
else if( !(TCC0RA & WGM01) && (TCC0RA & WGM00) )
{
// do this only if in the PWM, phase correct mode
}


C mode
}


else if( (TCC0RA & WGM01) && !(TCC0RA & WGM00) )
{
// do this only if in the CT

Free download pdf