by Joe Pardue
Get started now with this
series! Joe’s book & kit are
available in our webstore at
www.nutsvolts.com
PART 1:
Introducing the AVR C
Programming Workshop Series
Cprogramming and microcontrollers are two big topics,
practically continental in size,
and like continents, are easy to get
lost in. Combining the two is a little
like traipsing from Alaska to Tierra del
Fuego. Chances are you’ll get totally
lost and if the natives don’t eat you,
your infected blisters will make you
want to sit and pout. I’ve been down
this road so many times that I
probably have my own personal rut
etched in the metaphorical soil, and
I can point to the sharp rocks I’ve
stepped on, the branches that have
whacked me in the face, and the
bushes from which the predators
leapt. If you get the image of a
raggedy bum stumbling through the
jungle, you’ve got me right. Consider
these workshops a combination
roadmap, guidebook, and emergency
first aid kit for your journey into this
fascinating, but sometimes dangerous
world.
I highly recommend that you
get the book The C Programming
Language — Second Edition by
Kernighan and Ritchie, here after
referred to as K&R. Dennis Ritchie
(Figure 1) wrote C, and his book is
the definitive source on all things C.
In Figure 1, Ritchie (inventor of
the C programming language) stands
next to Ken Thompson, original
inventor of Unix, designing the
original Unix operating system at Bell
Labs on a PDP- 11.
I have chosen to follow that
book’s organization structure in this
series of workshops. The main
difference is that their book is
machine independent and gives lots
of examples based on manipulating
text, while these workshops are
machine dependent, specifically based
on the AVR microcontroller, and the
examples are as microcontroller
oriented as I can make them.
Why C?
Back in the dark ages of
microprocessors, software
development was done exclusively
in the specific assembly language of
the specific device. These assembly
languages were character based
‘mnemonic’ substitutions for the
numerical machine language codes.
Instead of writing something like:
0x12 0x07 0xA4 0x8F to get the
device to load a value into a memory
location, you could write something
like: MOV 22, MYBUFFER+ 7.
The assembler would translate
that statement into the machine
language for you.
I’ve written code in machine
language (as a learning experiment)
and believe me when I tell you
that assembly language is
a major step up in
productivity. But a device’s
assembly language is tied
to the device and the way
the device works.
Assembly languages are
hard to master and
become obsolete for you
the moment you change
microcontroller families.
They are specific-purpose languages
that work only on specific microprocessors. C is a general-purpose
programming language that can work
on any microprocessor that has a
C compiler written for it.
C abstracts the concepts of what
a computer does and provides a text
based logical and readable way to
get computers to do what computers
do. Once you learn C, you can move
easily between microcontroller
families, write software much faster,
and create code that is much easier
to understand and maintain.
Why AVR?
There are many excellent micro-controller families out there, but I
chose the AVR because — among
many reasons — it was designed with
the C programming language in
mind, has Flash memory that can be
configured with a bootloader (more
on all this later), and has the best
user forum I’ve ever used: www.avr
freaks.net.
The AVR is fast, cheap, in-circuit
■FIGURE 1. Cbeing invented.
August 2008 61