Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Single- and multi-chip microcontroller interfacing
Nội dung xem thử
Mô tả chi tiết
Single- and Multi-Chip
Microcontroller Interfacing
For the Motorola 68HC12
Academic Press Series in Engineering
Series Editor
J. David Irwin
Auburn University
Designed to bring together interdependent topics in electrical engineering, mechanical
engineering, computer engineering, and manufacturing, the Academic Press Series in
Engineering provides state-of-the-art handbooks, textbooks, and professional reference
books for researchers, students, and engineers. This series provides readers with a comprehensive group of books essential for success in modern industry. A particular emphasis
is given to the applications of cutting-edge research. Engineers, researchers, and students
alike will find the Academic Press Series in Engineering to be an indispensable part of
their design toolkit.
Published books in the series:
Industrial Controls and Manufacturing, 1999, E. Kamen
DSP Integrated Circuits, 1999, L. Wanhammar
Time Domain Electromagnetics, 1999, S. M. Rao
Single- and Multi-Chip Microcontroller Interfacing for the Motorola 68HC12, 1999,
G. J. Lipovski
Control in Robotics and Automation, 1999, B. K. Ghosh, N. Xi, T. J. Tarn
Single- and Multi-Chip
Microcontroller Interfacing
For the Motorola 68HC12
G. Jack Lipovski
Department of Electrical and Computer Engineering
University of Texas
Austin, Texas
ACADEMIC PRESS
San Diego London Boston
New York Sydney Tokyo Toronto
This book is printed on acid-free paper. ©
Copyright © 1999 by Academic Press
All rights reserved.
No part of this publication may be reproduced or
transmitted in any form or by any means, electronic
or mechanical, including photocopy, recording, or
any information storage and retrieval system, without
permission in writing from the publisher.
Academic Press
525 B. St., Suite 1900, San Diego, California 92101-4495, USA
http://www.apnet.com
Academic Press
24–28 Oval Road, London NW1 7DX, UK
http://www.hbuk.co.uk/ap/
Library of Congress Catalog Card Number: 98-89451
ISBN: 0-12-451830-3
Printed in the United States of America
99 00 01 02 03 MV 9 8 7 6 5 4 3 2 1
Disclaimer:
This eBook does not include the ancillary media that was
packaged with the original printed version of the book.
Dedicated to my mother,
Mary Lipovski
G. Jack Lipovski has taught electrical engineering and computer science at the
University of Texas since 1976. He is a computer architect internationally recognized for his
design of the pioneering database computer, CASSM, and the parallel computer, TRAC. His
expertise in microcomputers is also internationally recognized by his being a past director of
Euromicro and an editor of IEEE Micro. Dr. Lipovski has published more than 70 papers,
largely in the proceedings of the annual symposium on computer architecture, the IEEE
transactions on computers and the national computer conference. He holds eight patents,
generally in the design of logic-in-memory integrated circuits for database and graphics
geometry processing. He has authored seven books and edited three. He has served as chairman of the IEEE Computer Society Technical Committee on Computer Architecture, member of the Computer Society Governing Board, and chairman of the Special Interest Group
on Computer Architecture of the Association for Computer Machinery. He has been elected
Fellow of the IEEE and a Golden Core Member of the IEEE Computer Society. He received
his Ph.D. degree from the University of Illinois, 1969, and has taught at the University of
Florida, and at the Naval Postgraduate School, where he held the Grace Hopper chair in
Computer Science. He has consulted for Harris Semiconductor, designing a microcomputer,
and for the Microelectronics and Computer Corporation, studying parallel computers. He
founded the company Linden Technology Ltd., and is the chairman of its board. His current
interests include parallel computing, database computer architectures, artificial intelligence
computer architectures, and microcomputers.
About the Author
Contents
Preface x i i i
List of Figures xvii
List of Tables xxi
Acknowledgments xxi
About the Author xxiii
I Microcomputer Architecture I
1.1 An Introduction to the Microcomputer I
1.1.1 Computer Architecture 2
1.1.2 The Instruction 6
1.1.3 Microcomputers 9
1.2 The 6812 Instruction Set 11
1.2.1 6812 Addressing Modes 11
1.2.2 6812 Data Operator Instructions 16
1.2.3 6812 Control Instructions 23
1.3 Assembly-Language Directives 28
1.4 Organization of 6812 Microcontrollers 31
1.4.1 Notation for Block Diagrams 31
.,4.2 6812 Microcontroller I/O and Memory Organization 31
1.4.3 The MC68HC812A4 and MC68HC912B32 Memory Maps 35
1.5 Conclusions 36
Problems 38
2 Programming Microcomputers 45
2.1 Introduction to C 46
2.2 Data Structures 55
2.2.1 Indexable Data Structures 57
2.2.2 Sequential Data Structures 59
2.3 Writing Clear C Programs 66
2.3.1 C Procedures and Their Arguments 66
2.3.2 Programming Style 72
2.3.3 Object-Oriented Programming 73
2.3.4 Optimizing C Programs Using Declarations 83
2.3.5 Optimizing C Programs with Assembly Language 83
2.4 Conclusions 84
Problems 86
vu
Contents
3 Bus Hardware and Signals 93
3.1 Digital Hardware 94
3.1.1 Modules and Signals 94
3.1.2 Drivers, Registers, and Memories 97
3.2 Address and Control Signals in 6812 Microcontrollers 104
3.2.1 Address and Control Timing 104
3.2.2 Address and Control Signal Decoding 108
3.3 Conclusions 113
Problems 115
4. Parallel and Serial Input/Output
4.1 I/O Devices and Ports
4.1.1 Generic Port Architecture
4.1.2 Generic Port Classes
4.1.3 Debugging Tools
4.2 6812 Parallel Ports
4.2.1 MC68HC812A4 Port Architecture
4.2.2 MC68HC912B32 Port Architecture
4.2.3 Programming of PORTA
4.2.4 A Class for Ports with Direction Control
4.3 Input/Output Software
4.3.1 A Wire
4.3.2 A Movie
4.3.3 A Traffic Light Controller
4.3.4 A Sequential Machine
4.3.5 An IC Tester
4.3.6 Object-oriented Vector Functions and Interpreters
4.4 Input/Output Indirection
4.4.1 Indirect Input/Output
4.4.2 LCD Interfacing
4.4.3 Synchronous Serial Input/Output
4.4.4 The 6812 SPI Module
4.4.5 Accessing Devices Using Vectors and structs
4.4.5.1 Vector Access to Ports
4.4.5.2 Vector Pointer Access to Ports
4.4.5.3 Using #defines to Name Ports
4.4.5.4 Struct Pointer Access to Ports
4.4.5.5 Struct Access to Ports
4.4.6 Indirect and Serial I/O Objects
4.5 A Designer's Selection of I/O Ports and Software
4.6 Conclusions
Problems
Contents
5 Interrupts and Alternatives 193
5.1 Programmed Synchronization 196
5.1.1 Real-time Synchronization 196
5.1.2 Gadfly Synchronization 198
5.1.2.1 MC68HC812A4 Gadfly Synchronization 199
5.1.2.2 MC68HC912B32 Gadfly Synchronization 200
5.1.2.3 Gadfly Synchronization Characteristics 200
5.1.3 Handshaking 200
5.1.4 Some Examples of Programmed I/O 201
5.1.5 Object-oriented Classes for Programmed I/O 204
5.2 Interrupt Synchronization 210
5.2.1 Steps in an Interrupt 210
5.2.1.1 Steps in an Interrupt in the MC68HC812A4 211
5.2.1.2 Steps in an Interrupt in the MC68HC912B32 212
5.2.1.3 Properties of Interrupt Synchronization 213
5.2.2 Interrupt Handlers and Critical Sections 214
5.2.2.1 A Handler That Changes a Global Variable 214
5.2.2.2 A Handler That Fills or Empties a Buffer 216
5.2.2.3 A Handler That Uses a Queue for Input 218
5.2.2.4 A Handler That Uses a Queue for Output 220
5.2.2.5 Critical Sections 221
5.2.3 Polled Interrupts 222
5.2.3.1 Polled Interrupts in the MC68HC812A4 222
5.2.3.2 Polled Interrupts in the MC68HC912B32 224
5.2.3.3 Service Routines 225
5.2.3.4 Round-robin Handlers 226
5.2.4 Vectored Interrupts 228
5.2.4.1 Vectored Interrupts in the MC68HC812A4 228
5.2.4.2 Vectored Interrupts in the MC68HC912B32 230
5.2.4.3 Vectored Interrupts for Other Devices 231
5.2.5 Examples of Interrupt Synchronization 231
5.2.5.1 Keyboard Handling 23 i
5.2.5.2 Interrupts for SPI Systems 235
5.2.5.3 Histograms and Histories for the MC68HC812A4 236
5.2.6 Object-oriented Classes for Interrupts 237
5.2.6.1 An IQFPort Class 237
5.2.6.2 An OQFPort Class 239
5.2.6.3 Polling IQFPort and OQFPort Classes 240
5.2.6.4 Bar-code Class 240
5.2.6.5 An X-10 Class 241
5.3 Time-Sharing 244
5.3.1 Real-time Interrupts 244
5.3.2 Multithread Scheduling 245
5.3.3 Threads for Time-sharing 248
5.3.4 An Efficient Time Schedular 252
5.3.5 Special Instructions for Time-sharing 256
Contents
5.3.6 Object-oriented Classes for Time-sharing
5.4 Fast Synchronization Mechanisms
5.4.1 Direct Memory Access
5.4.2 Context Switching
5.4.3 Memory Buffer Synchronization
5.5 Conclusions
Problems
6 System Control 277
6.1 6812 Chip Modes 277
6.1.1 MODE Control Port 277
6.1.2 Port E Assignment 279
6.2 6812 Memory Map Control 280
6.2.1 Internal Memory Map Control 280
6.2.2 MC68HC812A4 Chip Selects 281
6.2.3 MC68HC812A4 Memory Expansion 284
6.2.4 Object-oriented Programming of Memory Expansion 285
6.3 EEPROM and Flash Memory Programming 286
6.4 MC68HC812A4 Timing Control 289
6.5 An External Memory for the MC68HC812A4 290
6.6 The 6812 Background Debug Module 295
6.7 6812 Reset Handler 299
6.8 Conclusions 301
Problems 302
7 Analog Interfacing 307
7.1 Input and Output Transducers 309
7.1.1 Positional Transducers 309
7.1.2 Radiant Energy Transducers 311
7.1.3 Other Transducers 313
7.2 Basic Analog Processing Components 314
7.2.1 Transistors and Silicon Controlled Rectifiers 314
7.2.2 Basic Linear Integrated Circuits 317
7.2.3 Practical Linear Integrated Circuits 321
7.3 OP AMP and Analog Switch Signal Conditioning 326
7.3.1 Filters 327
7.3.2 Selection of Inputs and Control of Gain 329
7.3.3 Nonlinear Amplification 332
7.4 Converters 334
7.4.1 Digital-to-Analog Converters 334
7.4.2 Analog-to-Digital Converters 338
7.4.3 Voltage Conversion to or from Frequency 340
7.5 Data Acquisition Systems 344
7.5.1 Basic Operation of a Data Acquisition System 345
7.5.2 The MC145040 A-to-D Converter 346
7.5.3 The MC68HC812A4 A-to-D Converter 347
7.5.4 Object-oriented Programming of Converters 349
7.5.5 Applications in Control Systems 350
7.6 Conclusions 352
Problems 354
8 Counters and Timers 361
8.1 The MC68HC812A4 Counter/Timer Subsystem 362
8.2 Signal Generation 363
8.2.1 Output Compare Logic 364
8.2.2 The Counter/Timer Square-Wave Generator 365
8.2.3 The MC68HC912B32 PWM Signal Generator 366
8.2.4 A Touch-tone Signal Generator 369
8.2.5 The Pulse Generator 373
8.2.6 A Rotary Dialer 374
8.2.7 Real-Time Clock and Trace Mechanism 375
8.2.8 Output Compare 7 376
8.2.9 Object-oriented Square-wave and Pulse Generation 378
8.3 Frequency and Period Measurement 381
8.3.1 The Input Capture Mechanism and Period Measurement 381
8.3.2 Pulse-width Measurement 383
8.3.3 Triac Control 385
8.3.4 Pulse Accumulation and Frequency Measurement 385
8.3.5 Object-oriented Period, Pulse-width, and Frequency Measurements 387
8.4 Conclusions 388
Problems 390
9. Communications Systems 397
9.1 Communications Principles 398
9.2 Signal Transmission 401
9.2.1 Voltage and Current Linkages 401
9.2.2 Frequency Shift-Keyed Links Using Modems 405
9.2.3 Infrared Links 407
9.3 UART Link Protocol 408
9.3.1 UART Transmission and Reception by Software 408
9.3.2 The UART 411
9.3.3 The ACIA 414
9.3.4 The M14469 417
9.3.5 The Serial Communication Interface System in the 6812 420
9.3.6 Object-oriented Interfacing to the SCI 423
9.4 Other Protocols 427
9.4.1 Synchronous Bit-oriented Protocols 427
9.4.2 MC68HC912B32 BDLC Device 430
9.4.3 IEEE-488 Bus Standard 432
9.4.4 The Small Computer System Interface (SCSI) 435
9.5 Conclusions 436
Problems 438
xii Contents
10. Display and Storage Systems 445
10.1 Display Systems 446
10.1.1 NTSC Television Signals 446
10.1.2 A 6812 SPI Display 448
10.1.3 A Bitmapped Display 450
10.1.4 An Object-oriented Display 453
10.2 Storage Systems 455
10.2.1 Floppy Disk Format 455
10.2.2. The Western Digital 37C65C Floppy Disk Controller 459
10.2.3. Floppy Disk Interfacing Procedures 462
10.2.4 Personal Computer Disk Data Organization 466
10.2.5 Object-oriented Disk I/O 470
10.3 Conclusions 473
Problems 475
Appendix. Using the HIWAVE CD-ROM 481
Index 483
Preface
By 1980, the microcomputer had changed so many aspects of engineering that the
cliche "microcomputer revolution" echoed from almost every other magazine article and
learned paper in the field. It is a great tool. This book's ancestor, Microcomputer
Interfacing: Principles and Practices, was written at that time to establish some design
theory for this dynamic field. A successor book, which is this book's predecessor,
Single- and Multiple-Chip Microcomputer Interfacing, was motivated by two
significant changes: the evolution of powerful single-chip microcomputers and the IEEE
Computer Society Curriculum Committee recommendation for a course on
microcomputer interfacing and communication. The development of powerful single-chip
microcomputers introduces a new design choice: to use either a microprocessor in a
personal computer with some 16M bytes of memory and an operating system or a less
costly single-chip microcomputer with much less overhead. This decision is largely
based on the designer's understanding of the capabilities and limitations of the singlechip microcomputer. The development of a standard curriculum for a course lent stability
to this field. The book aimed to teach the principles and practices of microcomputer
systems design in general, and interfacing in particular, and to foster an understanding of
single-chip microcomputers within the guidelines of the IEEE Computer Society
Curriculum Committee's recommendations. This book was motivated by the
development of the Motorola 6812, and its need for more sophisticated software. Since
the 6812 featured so many on-chip I/O devices, which were already connected to the
6812's address and data buses, but which each had to be programmed, and managing a
number of I/O devices often necessitated the use of time sharing, this book features
programming in C and C++. However, the designer must be wary of high-level language
statements that do not do what he or she intended. High-level languages are designed for
algorithms, not for I/O interfacing, and optimizing high-level language compilers can
"optimize you right out of business." The designer is shown how each high-level
language statement is implemented in assembler language.
This book's predecessor evolved from a set of notes for a senior level course in
microcomputer design. The course - which is still taught - focuses on the combined
hardware/software design of microcomputer systems. It emphasizes principles of design
because theory is as necessary for a solid foundation in design as theory is in any
engineering discipline. However, it also emphasizes the practices - the details of how to
get a system to work - because microcomputer system design requires hands-on
experience. There is a remarkable difference between a student who merely reads about
microcomputers and a student who has worked with one - clear evidence that theory has
to be taught with practice. Practical experience is desirable in almost any engineering
course. This is not always possible. But microcomputer systems are inexpensive enough
that the school or the student can afford this hands-on opportunity; and the joy of seeing
the principles work is so attractive that the student often can't get enough of the material
to be satiated. The development of very powerful, inexpensive single-chip
microcomputers furthers this opportunity. So the course, this book's predecessor, and
this book, all emphasize both the principles and practices of microcomputer design.
xiv Preface
The principles and practices of microcomputer design have to cover both hardware
and software. A purely hardware approach might appeal to a seasoned digital system
designer or an electrical engineering student, but it leads to poor choices that either do
not take full advantage of software's tremendous power or force unnecessary constraints
and therefore higher costs on its development. However, a purely software approach
misses the opportunity to understand how and why things happen, and how to take
advantage of the hardware. The IEEE Computer Society Curriculum Committee
recommends a combined hardware/software approach.
A combined hardware/software approach does require more background. The course
this book is based on is the second of a two-course sequence. The first course teaches
how C statements are implemented in assembler-language programming. The second
course builds on that background and also presumes some background in logic design, as
would be obtained in a standard introductory course on that topic. This book, however,
has three chapters that survey these topics. These chapters can be skimmed as a review of
the required background material or carefully studied as a condensed tutorial if the reader
has not had the earlier courses or their equivalents. Because they are intended as review or
intensive tutorial material, to prepare the readers for the book's main subject, these three
chapters are comparatively compressed and terse.
We make the practices discussed in this book concrete through detailed discussion of
the 6812 microcontroller. However, these products are used as a means to the end of
teaching principles and practices in general, rather than to promote the use of specific
Motorola products. Applications notes and catalogues are available from Motorola to
that end. Specific, detailed discussion encourages and aids the reader in learning through
hands-on experience and vitally contributes to his or her enthusiasm for and
understanding of the principles. The 6812 is used primarily because the MC68HC812A4
(abbreviated 'A4) and the MC68HC912B32 (abbreviated 'B32) are believed to be the
most easily taught single-chip microcomputer. The 6812 instruction set is as complete
as that of any other comparable machine, supporting C and C++ well enough to teach
the intelligent use of data structures, and it is symmetrical and comparatively free of
quirks and warts that detract from the subject under discussion. Moreover, the 'A4's 4 K
bytes of EEPROM, which can be written 10,000 times, is well suited to university-level
lab and project use. The less costly 'B32, with its 1 K bytes of SRAM, is also suited to
simple lab experiments. Nevertheless, we stress that detailed comparisons between the
' A4 and other well-designed microcomputers clearly show that others may be better than
the 'A4 or 'B32 for different applications. However, a comparative study of different
microcomputers and applications is beyond the scope of this book.
As mentioned, the first three chapters quickly survey the background needed for the
remainder of the book. Chapter 1 is a survey that covers computer architecture and the
instruction set of the 6812. Chapter 2 covers some software techniques, including
subroutine parameter and local variable conventions, that are very useful in
microcomputers. Object-oriented programming is introduced for readers with advanced
programming skills. Chapter 3 covers basic computer organization, but confines itself to
those aspects of the topic that are particularly germane to microcomputers. For example,
basic computer organization traditionally covers floating point arithmetic, but this
chapter doesn't; and this chapter dwells on address decoders, a topic not often covered in
computer organization.