Microcontroller Programming: An Introduction is a comprehensive one-stop resource that covers the concepts, principles, solution development, and associated techniques involved in microcontroller-based systems. Focusing on the elements and features of the popular and powerful Motorola 68HC11 microcontroller IC as a representative example, this book is unlike others, which are often too broad in scope, delving into every topic of concern regarding microcontroller programmers. Instead, this text concentrates on design, architecture, and development, giving developers the tools to develop solid, effective embedded applications. Front Cover 1 Title Page 5 Copyright 6 Dedication 7 Contents 9 Preface 17 Acknowledgments 25 The Author 27 1 Number Systems, Operations, and Codes 29 1.1 Introduction 30 1.2 Digital versus Analog Quantities 31 1.3 Digital Numbering System (Base 10) 32 1.4 Binary Numbering System (Base 2) 33 1.5 Octal Numbering System (Base 8) 35 1.6 Hexadecimal Numbering System (Base 16) 36 1.7 Binary-Coded-Decimal System 38 1.8 Binary Conversions 39 1.9 Binary Operations 40 1.9.1 Binary Addition 41 1.9.2 Binary Subtraction 42 1.9.3 Binary Multiplication 43 1.9.4 Binary Division 44 1.10 Octal Conversions 45 1.11 Hexadecimal Conversions 46 1.12 Hexadecimal Operations 48 1.12.1 Hexadecimal Addition 48 1.12.2 Hexadecimal Subtraction 49 1.13 1’s and 2’s Complements of Binary Numbers 49 1.13.1 Finding the 1’s Complement 49 Example 1.21 49 1.13.2 Finding the 2’s Complement 49 1.14 Signed Numbers 51 1.14.1 The Sign Bit 52 1.14.2 Sign-Magnitude Form 52 1.14.3 1’s Complement Form 52 1.14.4 2’s Complement Form 53 1.15 The ASCII Code 53 1.16 Summary 56 Glossary 57 Answers to Section Review Quiz 58 True/False Quiz 58 Questions 59 Problems 60 2 Semiconductors and Digital Logic 63 2.1 Introduction 64 2.2 Diode Logic 64 2.3 The Inverter 65 2.3.1 Inverter Truth Table 66 2.3.2 Inverter Symbol 67 2.3.3 Operation of an Inverter 68 2.3.4 Timing Diagrams 68 2.3.5 Logic Expressions for an Inverter 69 2.4 The AND Gate 70 2.4.1 AND Gate Symbol 70 2.4.2 Operation of an AND Gate 71 2.4.3 AND Gate Truth Table 72 Example 2.2 73 Example 2.3 73 2.4.4 Timing Diagrams 74 2.4.5 Logic Expressions for an AND Gate 75 2.5 The OR Gate 77 2.5.1 OR Gate Symbol 77 2.5.2 Operation of an OR Gate 77 2.5.3 OR Gate Truth Table 79 2.5.4 Timing Diagram 80 2.5.5 Logic Expressions for an OR Gate 83 2.6 The NAND Gate 85 2.6.1 NAND Gate Symbol 85 2.6.2 Operation of a NAND Gate 85 2.6.3 Timing Diagram 86 2.6.4 Negative-OR Equivalent Operation of a NAND Gate 88 2.6.5 Logic Expressions for a NAND Gate 89 2.7 The NOR Gate 90 2.7.1 NOR Gate Symbol 90 2.7.2 Operation of a NOR Gate 90 2.7.3 Timing Diagram 91 2.7.4 Negative-AND Equivalent Operation of the NOR Gate 92 2.7.5 Logic Expressions for a NOR Gate 93 2.8 The Exclusive-OR Gate 95 2.8.1 XOR Gate Symbol 95 2.8.2 Operation of XOR Gate 95 2.8.3 XOR Gate Truth Table 97 2.8.4 Timing Diagram 97 2.8.5 Parity 99 2.10 Summary 105 Glossary 106 Answers to Section Review Quiz 107 True/False Quiz 108 Questions 108 Problems 109 3 Microcontroller Hardware 117 3.1 Introduction 118 3.2 A Transistor as a Switch 119 3.3 The TTL Integrated Circuit 121 3.4 The CMOS Integrated Circuit 122 3.5 Using Integrated-Circuit Logic Gates 124 3.6 Seven-Segment Displays 126 3.7 Liquid-Crystal Displays 130 3.8 Keypads 133 3.9 The 68HC11/68HC12 Microcontroller 134 3.9.1 HC11 Processor 138 3.9.2 HC11 Memory 140 3.9.3 HC11 Advanced On-Chip Input/Output (I/O) Capabilities 146 3.10 EVBU/BUFFALO 149 3.11 Summary 152 Glossary 154 Answers to Section Review Quiz 156 True/False Quiz 157 Questions 158 Problems 159 4 Microcontroller Software 161 4.1 Introduction 162 4.2 Programming Concepts 163 4.3 System Software 167 4.4 Developing a Program 170 4.4.1 Problem Analysis 172 4.4.2 Design Development 173 4.4.3 Coding 173 4.4.4 Program Testing 175 4.5 Flow and State Diagrams 176 4.5.1 Flowchart Symbols 176 4.5.2 Flowcharting Techniques 176 4.5.3 State Diagrams 178 4.6 HC11 Programming Model 180 4.6.1 The Condition Code Register (Flags) 181 4.7 HC11 Memory-Addressing Modes 186 4.7.1 Extended Addressing 187 4.7.2 Direct Addressing 188 4.7.3 Immediate Addressing 189 4.7.4 Inherent Addressing 190 4.7.5 Indexed Addressing 190 4.7.6 Relative Addressing 191 4.8 Summary 192 Glossary 194 Answers to Section Review Quiz 197 True/False Quiz 197 Questions 198 Problems 199 5 Introduction 203 5.1 Introduction 204 5.2 Data Movement 205 5.2.1 Load Instructions 206 5.2.2 Store Instructions 209 5.2.3 Clear Instructions 212 5.2.4 Transfer Instructions 213 5.2.5 Exchange Instructions 214 5.3 Arithmetic 215 5.3.1 Addition 215 5.3.2 Increment Instructions 218 5.2.3 Subtraction 219 5.3.4 Negate and Decrement Instructions 222 5.4 Logic 223 5.5 Shifting and Rotating 227 5.6 Multiplication and Division 232 5.7 CCR (Flag) Manipulation 233 5.8 Bit-Level Operations 234 5.9 Summary 235 Glossary 236 Answers to Section Review Quiz 238 True/False Quiz 238 Questions 239 Problems 240 6 Control Structures and Subroutines 245 6.1 Introduction 246 6.2 Indexed Addressing Mode 247 6.3 Jumping and Branching 249 6.3.1 Jumping 251 6.3.2 Branching 253 6.4 Compare Instructions 259 6.5 Conditional Flow and Program Loops 263 6.6 Stack Operation 267 6.7 Subroutines 272 6.8 BUFFALO Subroutine 274 6.9 Summary 276 Glossary 277 Answers to Section Review Quiz 279 True/False Quiz 279 Questions 280 Problems 281 7 Hello World! 289 7.1 Introduction 290 7.2 Creating Source Code Files 291 7.2.1 Writing the “Hello World!” Program 297 7.3 Assembling Programs 300 7.4 Ten Useful Programs 304 7.5 Summary 331 Glossary 332 Answers to Section Review Quiz 333 True/False Quiz 333 Questions 334 Problems 334 8 Input/Output (I/O) Ports 341 8.1 Introduction 342 8.2 Data Transfer Mode 343 8.3 Port A 345 8.4 Port B 346 8.5 Port C 348 8.6 Port D and Port E 352 8.7 I/O Using Handshaking 355 8.7.1 Simple Handshaking 357 8.7.2 Full-Input Handshaking 358 8.7.3 Full-Output Handshaking 360 8.8 A Project Using Port B 361 8.8.1 Objective 361 8.8.2 Requirements Analysis 362 8.8.3 Design Development 363 8.9 Summary 368 Glossary 369 Answers to Section Review Quiz 370 True/False Quiz 370 Questions 371 Problems 372 9 Interrupts 377 9.1 Introduction 378 9.2 Basics of an Interrupt 380 9.3 Servicing an Interrupt 382 9.4 Interrupt Control 391 9.4.1 Interrupt Related Instructions 392 9.4.2 Local and Global Control 394 9.5 Maskable Interrupts 395 9.5.1 Serial Communication System Interrupt Sources 395 9.5.2 Timer System Interrupt Sources 395 9.5.3 External Interrupts Using IRQ 396 9.5.4 Maskable Interrupt Priority 397 9.6 Output Compare 398 9.6.1 Internal Timing Devices 399 9.6.2 Output Compare Interrupts 403 9.7 Nonmaskable Interrupts 410 9.7.1 External Interrupts Using XIRQ 410 9.7.2 Other Nonmaskable Interrupts 410 9.8 Interrupts on the EVBU 411 9.9 A Project with Interrupts 413 9.9.1 Objective 413 9.9.2 Requirements Analysis 413 9.9.3 Design 414 9.9.4 Description of OC3 ISR 415 9.10 Summary 421 Glossary 422 Answers to Section Review Quiz 424 True/False Quiz 424 Questions 425 Problems 427 10 Analog Capture 433 10.1 Introduction 434 10.2 Analog-to-Digital Conversion 435 10.2.1 Range 437 10.2.2 Steps 439 10.2.3 Step Voltage and Digital Code 440 10.2.4 Resolution 442 10.3 A/D Tools 444 10.3.1 Port E 445 10.3.2 ADC 445 10.3.3 Conversion Control 446 10.3.4 Result Registers 448 10.4 A/D Operation 448 10.5 A Project with Analog Capture 451 10.5.1 Requirements Analysis 451 10.5.2 Hardware Design 451 10.5.3 Software Design 452 10.6 Summary 455 Glossary 456 Answers to Section Review Quiz 457 True/False Quiz 457 Questions 458 Problems 459 11 Input Capture 461 11.1 Introduction 462 11.2 Basic Modules of Input Capture 463 11.3 Input-Capture Registers 464 11.4 Input Edge Detection Logic 465 11.5 Interrupt Generation Logic 467 11.6 A Project with Input Capture 468 11.7 Summary 471 Glossary 472 Answers to Section Review Quiz 473 True/False Quiz 474 Questions 475 Problems 475 12 Higher-Level Programming 477 12.1 Introduction 478 12.2 Levels in Programming Languages 478 12.3 C Programming 481 12.3.1 Getting Started with C 481 12.3.2 Data Types 482 12.3.3 Operators 485 12.3.4 Conditional Flow and Program Loops 488 12.3.5 Subroutines 491 12.3.6 Pointers and Arrays 492 12.4 Examples 493 12.5 A Project with C 497 12.6 Summary 501 Glossary 502 Answers to Section Review Quiz 503 True/False Quiz 503 Questions 504 Problems 505 Appendix 1—Supplemental Web Site 507 Appendix 2—States and Resolution for Binary Numbers 509 Appendix 3—Basic Boolean Theorems and Identities 511 Appendix 4—The Resistor Color Code 513 Appendix 5—Waterfall Software Development Lifecycle Model 515 Appendix 6—Loading Your Program into the EEPROM 517 Appendix 7—Pulse-Width Modulation 519 Appendix 8—HC11 Instruction Set 521 Appendix 9—Comprehensive Glossary 529 Back Cover 541 A comprehensive resource to the concepts, principles, solution development and techniques of microcontroller-based systems, focusing on the elements and features of the 68HC11 microcontroller IC as a representative example. The book focuses on how microcontroller-based applications are architected, developed, and designed.-- From publisher's description