Embedded Microcomputer Systems: Real Time Interfacing
Embedded Microcomputer Systems: Real Time Interfacing
Embedded Microcomputer Systems: Real Time Interfacing
Embedded
Microcomputer
Systems
Real Time Interfacing
Second Edition
Jonathan W. Valvano
University of Texas at Austin
Contents
1 Microcomputer-Based 1.10
1.11
Choosing a Microcontroller
Exercises 54
53
xiv Contents
2.4.6 Mealy Finite State Machine Robot 3.5.3 Gadfly Keyboard Interface Using Latched
Controller 101 Input 158
2.5 Modular Software Development 104 3.5.4 Gadfly ADC Interface Using Simple
2.5.1 Local Variables in Assembly Input 159
Language 104 3.5.5 Gadfly External Sensor Interface Using
2.5.2 Modules 109 Input Handshake 161
2.5.3 Dividing a Software Task into Modules 113 3.5.6 Gadfly Printer Interface Using Output
2.5.4 Rules for Developing Modular Software in Handshake 163
Assembly Language 116 3.5.7 Gadfly Synchronous Serial Interface to a
2.6 Layered Software Systems 118 Temperature Sensor 164
2.7 Device Drivers 119 3.6 Serial Communications Interface (SCI)
2.7.1 Basic Concept of Device Drivers 119 Device Driver 173
2.7.2 Design of a Serial Communications 3.6.1 Transmitting in Asynchronous Mode 174
Interface (SCI) Device Driver 121 3.6.2 Receiving in Asynchronous Mode 175
2.8 Object-Oriented Interfacing 122 3.6.3 6811 SCI Details 177
3.6.4 6812 SCI Details 178
2.8.1 Encapsulated Objects Using
3.6.5 SCI Device Driver 179
Standard C 122
2.8.2 Object-Oriented Interfacing 3.7 Exercises 181
Using C++ 123 3.8 Lab Assignments 187
2.8.3 Portability Using Standard C
and C++ 124
2.9 Threads 126
2.9.1 Single-Threaded Execution 126
4 Interrupt Synchronization
2.9.2 Multithreading and Reentrancy 126 189
2.10 Recursion 128 4.1 What Are Interrupts? 190
2.11 Debugging Strategies 128 4.1.1 Interrupt Definition 190
2.11.1 Debugging Tools 128 4.1.2 Interrupt Service Routines 191
2.11.2 Debugging Theory 129 4.1.3 When to Use Interrupts 192
2.11.3 Functional Debugging 131 4.1.4 Interthread Communication 192
2.11.4 Performance Debugging 133 4.2 Reentrant Programming 197
2.11.5 Profiling 136
4.3 First-In–First-Out Queue 204
2.12 Exercises 137 4.3.1 Introduction to FIFOs 204
2.13 Lab Assignments 141 4.3.2 Two-Pointer FIFO Implementation 205
4.3.3 Two-Pointer/ Counter FIFO
3 Interfacing Methods 142 Implementation
4.3.4 FIFO Dynamics
208
209
3.1 Introduction 142 4.4 General Features of Interrupts on the
3.1.1 Performance Measures 142 6811/6812 210
3.1.2 Synchronizing the Software with the 4.4.1 6811 Interrupts 212
State of the I/O 143 4.4.2 6812 Interrupts 213
3.1.3 Variety of Available I/O Ports 146 4.5 Interrupt Vectors and Priority 214
3.2 Handshake protocols 148 4.5.1 MC68H11E Interrupt Vectors and
3.2.1 6811 Handshake Protocol 148 Priority 214
3.2.2 MC68HC812A4 Key Wakeup 4.5.2 MC68HC812A4 Interrupt Vectors and
Interrupts 149 Priority 216
3.2.3 MC9S12C32 Key Wakeup Interrupts 150 4.5.3 MC68HC912B32 Interrupt Vectors and
3.3 Blind Cycle Counting Priority 217
Synchronization 151 4.5.4 MC9S12C32 Interrupt Vectors and
3.3.1 Blind Cycle Printer Interface 151 Priority 218
3.3.2 Blind Cycle ADC Interface 152 4.6 External Interrupt Design
3.4 Gadfly or Busy Waiting Approach 219
Synchronization 153 4.7 Polled Versus Vectored
3.5 Parallel I/O Interface Examples 155 Interrupts 221
3.5.1 Blind Cycle Printer Interface 156 4.8 Keyboard Interface Using
3.5.2 Blind Cycle ADC Interface 157 Interrupts 223
51629_00_TOC_RSE.qxd 2/2/06 4:55 PM Page xv
Contents xv
xvi Contents
7.6 SCI Software Interfaces 349 8.5.6 Interfacing EM Relays, Solenoids, and DC
7.6.1 Full Duplex Serial Channel 349 Motors 425
7.6.2 Use of Data Terminal Ready (DTR) 8.5.7 Solid-State Relays 430
to Interface a Printer 352 8.6 Stepper Motors 431
7.6.3 Use of XON/XOFF to Interface 8.6.1 Stepper Motor Example 431
a Printer 354 8.6.2 Basic Operation 434
7.7 Synchronous Transmission and Receiving 8.6.3 Stepper Motor Hardware Interfaces 438
Using the SPI 355 8.6.4 Stepper Motor Shaft Encoder 441
7.7.1 SPI Fundamentals 355 8.7 Exercises 443
7.7.2 MC68HC711E9 SPI Details 358 8.8 Lab Assignments 446
7.7.3 MC9S12C32 SPI Details 359
7.8
7.7.6 SPI Applications
Exercises 368
361
9 Memory Interfacing 448
7.9 Lab Assignments 370 9.1 Introduction 448
9.2 Address Decoding 451
9.2.1 Full-Address Decoding 452
8 Parallel Port 9.2.2
9.2.3
Minimal-Cost Address Decoding 454
Special Cases When Address Decoding 457
Interfaces 375 9.2.4 Flexible Full-Address Decoder 458
8.1 Input Switches and Keyboards 375 9.2.5 Integrated Address Decoder on the
8.1.1 Interfacing a Switch to the Computer 375 MC68HC812A4 459
8.1.2 Hardware Debouncing Using a 9.3 Timing Syntax 461
Capacitor 377 9.3.1 Available and Required Time Intervals 461
8.1.3 Software Debouncing 381 9.3.2 Timing Diagrams 463
8.1.4 Basic Approaches to Interfacing 9.4 General Memory Bus Timing 463
Multiple Keys 386 9.4.1 Synchronous Bus Timing 464
8.1.5 Sixteen-Key Electronic Piano 389 9.4.2 Partially Asynchronous Bus Timing 465
8.1.6 4 by 4 Scanned Keyboard 393 9.4.3 Fully Asynchronous Bus Timing 466
8.1.7 Multiplexed/Demultiplexed Scanned 9.5 External Bus Timing 468
Keyboard 396 9.5.1 Synchronized Versus Unsynch-ronized
8.2 Output LEDs 398 Signals 468
8.2.1 Single LED Interface 400 9.5.2 Freescale MC68HC11A8 External Bus
8.2.2 Seven-Segment LED Interfaces 402 Timing 469
8.2.3 Scanned Seven-Segment LED 9.5.3 Freescale MC68HC812A4 External
Interface 402 Bus Timing 472
8.2.4 Scanned LED Interface Using the 7447 9.5.4 Freescale MC9S12C32 External
Seven-Segment Decoder 405 Bus Timing 477
8.2.5 Integrated LED Interface Using the MC14489 9.6 General Approach to Interfacing 483
Display Driver 408 9.6.1 Interfacing to a 6811 483
8.3 Liquid Crystal Displays 410 9.6.2 Interfacing to a 6812 in Expanded
8.3.1 LCD Fundamentals 410 Narrow Mode 484
8.3.2 Simple LCD Interface with the 9.6.3 Interfacing to a 6812 in Expanded
MC14543 412 Wide Mode 485
8.3.3 Scanned LCD Interface with the 9.7 Memory Interface Examples 487
MC145000, MC145001 414 9.7.1 32K PROM Interface 487
8.3.4 Parallel Port LCD Interface with the 9.7.2 8K RAM Interface 492
HD44780 Controller 416 9.7.3 32K by 16-bit PROM Interface to a
8.4 Transistors Used for Computer- MC68HC812A4 505
Controlled Current Switches 419 9.7.4 8K by 16-bit RAM Interface 507
8.5 Computer-Controlled Relays, Solenoids, 9.7.5 Extended Address Data Page Interface to the
and DC Motors 421 MC68HC812A4 509
8.5.1 Introduction to Relays 421 9.7.6 Extended Address Program Page Interface to
8.5.2 Electromagnetic Relay Basics 422 the MC68HC812A4 511
8.5.3 Reed Relays 424 9.8 Dynamic RAM (DRAM) 514
8.5.4 Solenoids 424 9.9 Exercises 514
8.5.5 Pulse-Width Modulated DC Motors 424 9.10 Lab Assignments 523
51629_00_TOC_RSE.qxd 2/2/06 4:55 PM Page xvii
Contents xvii
xviii Contents