📄 preface1.htm
字号:
<head>
<title>Preface </title>
</head>
<body>
<h1>Preface</h1>
<p> This book introduces you to new and useful techniques of programming
microcontrollers with the high level language C. The concept of reusable components
evolved from research aimed at object oriented programming for microcontrollers in C. It
was found that classes written in C can be packaged as components for easy reuse and
modification needed to extend their capability.
<p> In this book you will learn how to create classes in C. Instances of these classes
are objects, and within the limites of the microcontroller and other peripherals, as many
instances of these objects as are needed can be created. We call these classes components.
Such software components have advantages over the corresponding hardware
components. In the construction of components, we can apply the concepts of inheritance
and polymorphism. Inheritance allows extension of the basic component to meet new
requirements without modification of the basic class code. Polymorphism, or late bindig,
permits the program to select one of several alternative functions or methods, the choice
of which to execute cannot be determined until run time. It will be found that careful
application of polymorphism can allow a savings of program code.
<p> One of the features of any high level language is to implement an abstraction in
which the underlying computer seemingly disappears. The total programmer interface
with the computer is through the language. Often the basic nature of the computer being
programmed is of little concern to the programmer. True for the computer, but untrue for
the peripherals. Most of the skill needed to program microcontrollers with a high level
language involves the efficient coding of the interface between the main computer, and its
program, with the peripherals of the system. The code in this text is for an M68HC16
family part. This code is also usuable on the M68300 series of components. The main
difference will be that the initialization of the core computers is slightly different, and since
most peripherals are common between the chips, the only header file change needed will
be the basic core part header. The microcontroller code contained in this book, where
possible, has been compiled and tested on an M68300 component. <p>Chapter 1 contains a
very brief summary of OOP. The main purpose of the chapter is to introduce some of the
language of OOP, how classes and objects are used, what to expect from inheritance and
virtual functions, and the many limitations of C as an OOP language.
<p> Objects written in C are explored in Chapter 2. Here we start with the simplest
concept of an object and develop it into a class. We make a class that can support
multiple instantiations of itself in the form of different objects. Inheritance is examined
and implemented. We then see how virtual functions can be implemented and used .
Finally, several mechanisms to improve the appearance, maintainability, and size of the
code written with these techniques are shown. All of the code found in Chapter2 is
written for a DOS based machine. The code in the remainder of the book is written for
the M68HC16Y1 microcontroller.
<p> The contents of Chapter 3 show the development of several useful objects for
microcontroller programs. Here the classes cover some typical data structure type classes
that can be used in your programs. These data structures have been developed to meet a
programming need for some embedded system.
<p> In Chapter 4, we develop a class that creates instances of an asynchronous serial
port. This serial port driver is interrupt controlled and block oriented. Its implementation
is object oriented. Instances of serial port objects can be created, and with proper care by
the basic program, these instances can be run simultaneously. The microcontroller
programmed here contains a dual channel asynchronous serial port that is comprised of
two distinct universal asynchronous receiver-transmitters, UARTs. While this application
might seem to be a perfect example where it is possible to merge the software drivers for
these two on-board devices into a single class, it is a case where the merging of the two
programs will essentially double the total code, and it will increase the complexity of the
software driver considerably. It was decided that the natural integration of multiple
devices into a single object oriented interface would best be demonstrated with the on-
board general purpose timer covered in Chapters 5 and 6.
<p> Several timer functions are developed in Chapters 5 and 6. These timers are based
on the timers found in the General Purpose Timer, GPT. The GPT contains both output
compare operations and input capture functions. You will find development of
components to make use of the output compare systems in Chapter 5. There are four
output compare systems on board the chip. Object oriented interfaces to these output
compare systems are created in a single class. Mechanizations are provided to attach a
delay object to any timer. When needed, multiple operations can be controlled by each
timer through the use of a Linked List of object oriented drivers that are executed with
each output compare interrupt. Input capture operations are used to measure time
between events. An object oriented interface to the several on-board input capture
systems is completed and applications to make precision time measurements are shown in
Chapter 6.
<p>Chapter 7 is a data manual. The text is on components, and most components that
we encounter in hardware have an associated data sheet. Data sheets for all of the
components derived in this book have been collected together and placed in the Data
Manual, Chapter 7. Here you can find how to use each software component, its
parameters, and the essential items needed to use the class as a super class for the
derivation of another class. I suspect that this chapter will be a well used chapter in this
book.
<p>In Appendix A, you will find a very brief description of the Cosmic C compiler
used to develop code for the M68HC16 series of components. Appendix B contains
several important header files needed to compile code for this chip family.
<p> A CDROM is attached to this book for your convenience. The contents of the
CDROM should be installed on your hard drive. A command like
<pre><code>
x:>install y:
</code></pre><p>
where x: is the volume of your CDROM drive and y: is the volume of the destination
drive will load the proper files on your hard disk. This install command will create
three directories on your hard disk: <i>programs</i>,
<i>html</i>, and <i>Cosmic</i>. The directory <i>programs,</i> contain all of the executable code contained in
the book. It is organized by chapter to help you find what you need. The directory
<i>Cosmic</i> contains a demonstration C compiler from Cosmic Software. This fine product
will compile all of the code contained in this book.
<p> The directory <i>html</i> contains a complete copy of this book. You are about to use
one of the excellent developments that has come from the World Wide Web. The language
used to generate Web Pages is called HTML from HyperText Markup Language. This
language allows you to create data pages that are formatted by the language rather than
the author. Look into any of the *.htm files in this directory to see what HTML files look
like.
<p> To access an HTML file you must use a Web Browser such as Netscape, or any
other of these popular programs. Once you get this program running, you can bring up
the text with a command to the browser like:
<pre><code>
file://localhost/c:/<path>/contents.htm
</code></pre><p>
Where <path> is the path to your html files. From that point on, it is merely point and
click to move through the book.
<p>I would like to take this opportunity to extend my thank to the Semiconductor
Products Sector of Motorola, Inc. for their support in the production of this book. Neil
Krohn, my manager, is always there with encouragement to try new business ideas. This,
my second book, has been written with his support and blessing. I could not have
completed it without his help. My associates Lou Pagnucco and A. J. Pohlmeyer have
provided me with many interesting discussions that have shaped the contents of this
book. Finally, I would also like to thank Brian Wilkie, the manager of the
Advanced Microcontroller Unit.
<pre>
Ted Van Sickle
1996
</pre>
</ul>
<hr>
<p>
<a href="copyrite.htm#copyright">Copyright</a>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -