Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C Programming for microcontrollers (Joe Pardue, 2005).pdf
Скачиваний:
260
Добавлен:
12.08.2013
Размер:
4.55 Mб
Скачать

Chapter 4: C Types, Operators, and Expressions

the clock prescaler to 4, we may still have to use the data book to look at the Waveform generator and Clock Select tables, but it is still clearer isn’t it?

Which gives you a better chance at knowing what is going on?

TCC0RA |= 0x4C;

Versus:

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

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

}

else if( (TCC0RA & WGM01) && !(TCC0RA & WGM00) )

{

// do this only if in the CTC mode

}

60