Microcontrollers such as the Freescale MC9SDG256 are remarkable devices. They contain not
only a sophisticated microprocessor with a rich set of instructions and addressing modes, but also contain
built-in RAM, EEPROM, and flash memory as well as numerous useful I/O ports, including parallel I/O,
several different types of serial I/O, timers, and A/D converters.
This extensive list of features makes the programming of these microcontrollers, particularly
using assembly language, a daunting task. A quick look at the many textbooks (or the many datasheets)
that describe these microcontrollers will confirm this. These books and datasheets spend a great deal of
time explaining how to program the many I/O registers to perform the wide variety of different I/O tasks.
However, it is usually something fairly simple that you are trying to do; e.g. turn on a light, read a switch,
turn on a motor at some speed, read the value of an A/D converter, or measure some time interval. If you
just want to learn how to do these simple things without getting bogged down in the minutia of the
microcontrollers I/O and internal operation, then this book is for you.
Compare this book to your automobile. Most of us want to use our car to get from one place to
another easily and in comfort. We don’t want to have to learn how to design and build an internal
combustion engine or automatic transmission in order to drive our car. By the same token you should not
have to learn a particular assembly language or the details of what each bit in dozens of different I/O
registers do in order to quickly and effectively program a microcontroller to do what you want it to do.
This book will show you how to do just that. Of course, some people like to look under the hood of their car to see how things really work. If
you really want to see how the assembly language routines that we provide for you actually work you can
study the entire source listing that is included in our stationery project. But it isn’t necessary to get your
microcontroller to work.
This book assumes no previous knowledge of either microcontrollers or C. We will use a particular microcontroller, the Freescale MC9S12DG256, on a popular, low-cost development board, the
miniDRAGON-Plus2™ from Wytec, Inc. The reason for using this microcontroller is that it is one of the
more powerful in the popular HCS12 family with lots of I/O capabilities, and the reasons for using the
miniDRAGON-Plus2 in addition to its low cost, are the small footprint that makes it suitable for
embedded projects, the convenient female headers for connecting to your circuits on the protoboard, and
the built-in connectors for an LCD display and keypad. There is also an on-board speaker, a built-in Hbridge
for driving motors, convenient headers for connecting servos and an accelerometer board available
from Wytec, and female headers for connecting to your circuits on the built-in protoboard. You will
quickly be able to do lots of fun stuff with this board. A companion book for use with Wytec’s
DRAGON12-Plus board is also available from LBE Books (www.lbebooks.com).
In this book you will learn to write programs in C and compile them to HCS12 code using
CodeWarrior™, an industry-strength integrated development environment for microcontrollers.
CodeWarrior itself can be daunting, but we will make it easy for you to learn what you need to quickly
get your microcontroller to work. We do this by providing you with an LBE_miniDRAGON_Plus2
Stationery project from which you can easily build your own particular application. This project will
contain an assembly language file that we have written to do all the low-level interaction with the I/O
registers. You can then concentrate on driving your car in C rather than wasting your time figuring out
how the internal combustion engine works! So let’s get started.
Many colleagues, students and reviewers have influenced the development of this book. Their
stimulating discussions, probing questions, and critical comments are greatly appreciated. Special thanks
go to Michael Latcha and Osamah Rawashdeh with whom we have had many useful discussions related
to the contents of this book.
Richard E. Haskell
Darrin M. Hanna