Page 12 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 12

Preface                                                              xi


                                      PREFACE

         Programming is an essential engineering skill. To almost any engineer, it is as
         important as circuit design to an electrical engineer, as statistics to a civil engineer, and
         as heat transfer to a chemical engineer. The engineer has to program in high-level
         languages to solve problems. He or she also should be able to read assembly-language
         programs to understand what a high-level language does. Finally, he or she should
         understand the capabilities of a microcontroller because they are components in many
         systems designed, marketed, and maintained by engineers. The first goal of this book
         then is to teach engineers how a computer executes instructions. The second goal is to
         teach the engineer how a high-level language statement converts to assembler language.
         A final goal is to teach the engineer what can be done on a small computer and how the
         microcomputer is interfaced to the outside world. Even the nonprogramming engineer
         should understand these issues. Although this book is written for engineers, it will serve
         equally well for anyone, even hobbyists, interested in these goals.
             The reader is taught the principles of assembly-language programming by being
         shown how to program a particular microcomputer, the Motorola 6812. The important
         thing about the 6812 is that it has a straightforward yet powerful instruction set, midway
         between smaller and more powerful microcontrollers; from it the reader can adjust to
         these smaller or more powerful microcontrollers. The best way to learn these principles
         is to write a lot of programs, debug them, and see them work on a real microcontroller.
         This hands-on experience can be inexpensively obtained on the 6812. Several 6812
         boards, which do everything described in this book, are available for under $100. (This
         price doesn't include the personal computer that hosts the 6812 target system.)
             The following discussion outlines the book and explains several decisions that
         were made when we wrote the book. Optional chapters are available for readers having
         various interests. The main skills taught in each chapter are summarized.
             Chapters 1 to 3 discuss programming using hand-translated machine code, and the
         implementation of machine instructions in an idealized microcontroller. The assembler is
         not introduced until Chapter 4. This gives the engineering student a fine feeling for the
         machine and how it works, and helps him or her resolve problems encountered later with
         timing in input/output programming or with the use of addressing modes in managing
         data structures. Chapter 1 explains how a microprocessor interacts with the memory and
         how it executes the instruction cycle. The explanation focuses on a microcomputer and
         is simplified to provide just enough background for the remainder of the text. Simple
         instructions and elementary programs are introduced next. Pointing out that there is no
         best program to solve a problem, Chapter 1 observes what makes a good program and
         encourages the reader to appreciate good programming style. A discussion of the
         available organizations of 6812 microcontrollers concludes this chapter.
             In Chapter 2, the main concept is the alternative forms of the same kind of
         instruction on the 6812. Rather than listing the instructions alphabetically, as is
         desirable in a reference book, we group together instructions that perform the same type
         of function. Our groups are the classical ones, namely, the move, arithmetic, logical,
         edit, control, and input/output groups. Although other groupings are also useful, this
         one seerns to encourage the student to try alternative instructions as a way of looking for
         the best instruction for his or her purpose. The 6812 has an extensive set of addressing
         modes that can be used with most instructions; these are covered in Chapter 3, The
   7   8   9   10   11   12   13   14   15   16   17