- •Contents
- •Preface
- •List of Figures
- •List of Tables
- •Acknowledgments
- •1.1.2 The Instruction
- •1 Problems
- •2 Programming Microcomputers
- •3 Bus Hardware and Signals
- •3.3 Conclusions
- •3 Problems
- •5 Interrupts and Alternatives
- •5.4.1 Direct Memory Access
- •7.1.3 Other Transducers
- •7.2 Basic Analog Processing Components
- •7.2.1 Transistors and Silicon Controlled Rectifiers
- •8 Counters and Timers
- •9. Communications Systems
- •9.3.3 The ACIA
- •9.4.4 The Small Computer System Interface (SCSI)
- •9.5 Conclusions
- •10.1.2 A 6812 SPI Display
Singleand 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 acomprehensive group of books essential for success in modern industry. A particular emphasis s 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 heir design toolkit.
Published books in the series:
ndustrial Controls and Manufacturing, 1999, E. Kamen DSP Integrated Circuits, 1999, L. Wanhammar
Time Domain Electromagnetics, 1999, S. M. Rao
Singleand 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
Singleand 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
Dedicated to my mother, Mary Lipovski
Contents
reface |
|
x i ii |
|
ist |
of |
Figures |
xvii |
ist |
of |
Tables |
xxi |
cknowledgments |
xxi |
||
bout |
the Author |
xxiii |
|
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 |
|
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.1I/O Devices and Ports
4.1.1Generic Port Architecture
4.1.2Generic Port Classes
4.1.3Debugging Tools
4.26812 Parallel Ports
4.2.1MC68HC812A4 Port Architecture
4.2.2MC68HC912B32 Port Architecture
4.2.3Programming of PORTA
4.2.4A Class for Ports with Direction Control
4.3Input/Output Software
4.3.1A Wire
4.3.2A Movie
4.3.3A Traffic Light Controller
4.3.4A Sequential Machine
4.3.5An IC Tester
4.3.6Object-oriented Vector Functions and Interpreters
4.4Input/Output Indirection
4.4.1Indirect Input/Output
4.4.2LCD Interfacing
4.4.3Synchronous Serial Input/Output
4.4.4The 6812 SPI Module
4.4.5Accessing Devices Using Vectors and structs
4.4.5.1Vector Access to Ports
4.4.5.2Vector Pointer Access to Ports
4.4.5.3Using #defines to Name Ports
4.4.5.4Struct Pointer Access to Ports
4.4.5.5Struct Access to Ports
4.4.6Indirect and Serial I/O Objects
4.5A Designer's Selection of I/O Ports and Software
4.6Conclusions
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-timeInterrupts |
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.6Object-oriented Classes for Time-sharing
5.4Fast Synchronization Mechanisms
5.4.1Direct Memory Access
5.4.2Context Switching
5.4.3Memory Buffer Synchronization
5.5Conclusions
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 |
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 |
. 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 |
ii |
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 |