This Appendix was adapted from a chapter entitled “Programming” from “Arduino Processing for
To the novice, programming a microcontroller may appear mysterious, complicated, over-
whelming, and difﬁcult. When faced with a new task, one often does not know where to start. The
goal of this Appendix is to provide a tutorial on how to begin programming. We will use a top-down
design approach. We begin with the “big picture” of the appendix, followed by an overview of the
major pieces of a program. We then discuss the basics of the C programming language. Only the
most fundamental concepts will be covered. Throughout the appendix, we provide examples and
also provide references to a number of excellent references.
A.2 THE BIG PICTURE
Most microcontrollers are programmed with some variant of the C programming language. The C
programming language provides a nice balance between the programmer’s control of the microcon-
troller hardware and time efﬁciency in programming writing.
As you can see in Figure A.1, the compiler software is hosted on a computer separate from
the MSP430 development board. The job of the compiler is to transform the program provided
by the program writer (ﬁlename.c and ﬁlename.h) into machine code suitable for loading into the
Once the source ﬁles are provided to the compiler, the compiler executes two steps to render
the machine code. The ﬁrst step is the compilation process. Here the program source ﬁles are
transformed into assembly code. If the program source ﬁles contains syntax errors, the compiler
reports these to the user. An assembly language program is not generated until the syntax errors have
The assembly language source ﬁle is then passed to the assembler.The assembler transforms the
assembly language source ﬁle to machine code suitable for loading to the MSP430 microcontroller.
The Texas Instrument Code Composer Studio provides a user friendly interface to aid in program
development, transformation to machine code, and loading into the MSP430 development board.
In the next section, we will discuss the components ofaCprogram.