You might wonder why blinking an LED
is the first project, when traditional C programming texts start with a “Hello World!”
program. The Butterfly has an LCD that can
show the words so it should be easy, but
controlling the LCD is much more complex
than blinking an LED, so we’ll save the LCD
for later when we’ve gotten a better handle
on things. Actually, the main reason is that
I’m partial to LEDs so you are going to see
a lot of flashing lights before we are through,
and hopefully the lights won’t be from you
passing out from boredom and boinking
your head on the keyboard. You are going to
use a lot of code in this series that will have
stuff in it that you won’t understand (yet).
My reasoning is that by
the deep end, you get to
do some interesting things
now and you can learn
how things work later.
■ FIGURE 5. Project
■ FIGURE 6. Project Options.
Keep this in mind if you don’t understand all of what we
are doing here. Eventually, you’ll see an explanation or at
least become more comfortable with mystery — a trait all
programmers develop over time. In the AVR Studio IDE
center screen, you’ll see a text window titled:
‘C:\Workshop\CylonEyes.c’. Either type what is
shown in Listing 1 or download it from the files
that are included on the Nuts & Volts website
( www.nutsvolts.com). Press the ‘Build Active
Configuration’ button (Figure 7). This will
■ FIGURE 7.
Build Active Configuration.
A Brief Introduction to C —
What Makes CylonEyes
Blink Those LEDs?
This section takes a very brief look at CylonEyes.c
to help begin understanding what each line means.
Later, these items will be covered in greater detail in the
context of programs written specifically to aid in learning
the C programming language, as it is used for common
You can add comments (text the compiler ignores)
to your code two ways. For a single line of comments,
use double back slashes as in
For multi-line comments, begin them with /* and end
them with */.
#define F_CPU 1000000l
The ‘#include’ is a preprocessor directive that
instructs the compiler to find the file in the <> brackets
and tack it on at the head of the file you are about to
compile. The io.h provides data for the port we use, and
the delay.h provides the definitions for the delay function
we call. The #define F_CPU 1000000l is placed before
the delay.h include since that file requires a value for
F_CPU in order to create a timed delay.
Operators are symbols that tell the compiler to do
things such as set one variable equal to another, the ‘=’
operator, as in ‘DDRB = 0xFF,’ or the ‘++’ operator for
adding 1, as in ‘counter++.’