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.
We will use a particular microcontroller, the Freescale MC9S12DG256, that it is one of the
more powerful in the popular HCS12 family of microcontrollers from Freescale with lots of I/O
capabilities. This microcontroller is available on the DRAGON12-Plus-USB™ development board
from Wytec, Inc. The DRAGON12-Plus-USB™ has many built-in I/O devices including LEDs,
switches, four 7-segment displays, a hex keypad, an LCD display, a hex keypad, a D/A converter
chip, an on-board speaker, a built-in H-bridge 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.
A previous book from LBE Books, Learning By Example Using C – Programming the
DRAGON12-Plus™ Using CodeWarrior showed how to write programs in C with a minimum of
effort for this development board. We did this by providing you with a CodeWarrior stationery
project that contained an assembly language file to do all the low-level interaction with the I/O
registers. These assembly language routines become function calls for your C program. Thus, in this
previous book you didn't have to learn any assembly language to get sophisticated programs to work
on this development board.
This current book provides these same CodeWarrior Stationery projects so that you can write
C programs easily for the DRAGON12-Plus-USB™ development board. However, in this book we
look under the hood to see how all of the assembly language routines that are included in the
stationery project work. This way you will learn how to program the HCS12 microcontroller in
assembly language and how to call these assembly language routines from your top-level C program.
You will therefore be able to write your own assembly language subroutines that you can call from
your C program, and in this way get the maximum performance from the MC9SDG256
microcontroller.
In Chapter 1 we introduce the DRAGON12-Plus-USB™ development board. Chapter 2 will
include examples of using the parallel ports for outputs and Chapter 3 will include examples of using
the parallel ports for inputs. Liquid crystal displays are described in Chapter 4. The important topic
of interrupts are introduced in Chapter 5. Examples using the two 8-channel A/D converters that are
built into the MC9S12DG256 microcontroller are given in Chapter 6. Examples that show how to
use pulse-width modulation (PWM) to control the speed of a DC motor or the position of a servo are
presented in Chapter 7. Chapter 8 includes examples of using the serial communication interface
(SCI) and Chapter 9 shows how to use the serial peripheral interface (SPI). Examples using the builtin
timer module are given in Chapter 10 and an example of using the MC9S12DG256 microcontroller
for fuzzy control is included in Chapter 11.
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