Page 471 - Robot Builder's Bonanza
P. 471
440 UNDERSTANDING MICROCONTROLLERS
case- sensitive. It doesn’t care if you use different capitalizations to reference the same
things.
C: The language of choice for programming professionals, C has more strict syntax rules,
so it’s often considered harder to learn. (In a spoken language, syntax is how the parts
of speech are strung together to form a coherent statement. It’s the same in a program-
ming language.) For all the bad rep C gets for being a stern schoolmaster, it’s actually
not that much more difficult to learn than BASIC, at least not when it comes to micro-
controllers.
Pascal: Considered a blueprint for modern structured programming, Pascal is a lesser- used
language when it comes to microcontrollers (so there aren’t as many options for it), but
it’s known for being easy to learn.
G There are several other programming languages used in microcontrollers, including Forth, Java,
Python, and C#. The choice of which language to use depends greatly on which one you’re
more comfortable with and which offers the feature set you want to exploit in your robot work.
Three Steps in Programming a Microcontroller
No matter what system or language you use, there are three basic steps to programming a
microcontroller. They are:
1. Use your personal computer to write your program with a text editor or other applica-
tion. Many commercial programming languages come with a fancy editor, called an
IDE, for integrated development environment. This single application combines the
programming step with the other two that follow.
2. You then compile your program into a form of data that the MCU will understand. The
microcontroller doesn’t know an “If” statement from a hole in the ground, and the job
of the compiler is to convert the human- readable code you just wrote to the machine
language the microcontroller understands.
3. After being compiled, the translated program is downloaded to the microcontroller.
This is most often done using a USB or serial cable. Once downloaded, the program is
immediately ready to be run inside the microcontroller. In fact, it will usually start run-
ning the moment the downloading process is complete.
Microcontroller Shapes and Sizes
All microcontrollers are integrated circuits, with anywhere from 8 to over 128 connection
pins, depending on complexity. But you don’t always work with a microcontroller as a sepa-
rate integrated circuit. Popular form factors of microcontrollers include (see Figure 35- 3):
Chip- only: You work with the microcontroller at the bare IC level. The chip may or may
not need any external components to operate. At a minimum, some need a voltage
regulator and an oscillator or resonator as a clock source.
Carrier: In this variation the microcontroller IC is mounted on a carrier, which contains
additional electronics. The carrier is itself the size and shape of a wide- profile integrated
circuit: a 24- pin “double- wide” IC is common. This is the form factor of the BASIC
Stamp and similar products. The carrier can be plugged into solderless breadboards for
35-chapter-35.indd 440 4/21/11 11:57 AM

