Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


While using &= and/or |= is acceptable, the Butterfly code generally does this a
ake the code a little clearer,
first. When we create masks to set or clear bits,
ed PD0 and we
h ighth bit simple, but it gets hairy when
give com es to all the bits in the dozens of registers. For instance
e Time TCC imer e
owing b age 90 ATMEGA


‘a’ = 0x61 = 01100001
~0x20 = 11011111


AND = 01000001 = 0x41 = ‘A’


This is a lot harder for us than ordinary subtraction, but much easier for the
machine.


little differently, not to make your life harder, but to m
though it won’t seem that way at
we will nam or instance the
can guess t


e the bits so f
at the e

first bit in port D is nam
is named PD7. That’s
we plicated nam
in th r0 register:
its named (p


R0A, T /Counter Control Register A we have th
foll 169 databook):


Bit 7 = FOC0A – Force Output Compare A
rm Generation Mode 0


as:

Bit 6 = WGM00 – Wavefo
Bit 5 = COM0A1 – Compare Match Output Mode 1
Bit 4 = COM0A0 – Compare Match Output Mode 0
Bit 3 = WGM01 – Waveform Generation Mode 1
Bit 2 = CS02 – Clock Select Bit 2
Bit 1 = CS01 – Clock Select Bit 1
Bit 0 = CS00 – Clock Select Bit 0


Bits 0, 1, and 2 the Clock Select Bits are defined

Free download pdf