SOFTWARE AND HARDWARE ENGINEERING: MOTOROLA M68HC11

Fredrick M. Cady
Department of Electrical Engineering
Montana State University
Bozeman, MT 59715
fcady(aatt_sign)ece.montana.edu

New York Oxford
Oxford University Press
1997



PREFACE


Software and Hardware Engineering: Motorola M68HC11, together with Microcontrollers and Microcomputers: Principles of Software and Hardware Engineering, is designed to give the student a fundamental understanding of a microcomputer-based system. The material is aimed at the sophomore, junior or senior level Electrical Engineering, Electrical Engineering Technology or Computer Science student taking a first course in microcomputers. Prerequisites are a digital logic course and a first course in a programming language.

The overall objective for this text is to provide an introduction to the architecture and design of hardware and software for the Motorola M68HC11. Although Software and Hardware Engineering: Motorola M68HC11 is designed to accompany a text explaining the general principles of software and hardware engineering, it can stand alone as a reference for M68HC11 users. It gives many programming and hardware interfacing examples that will enable students to become accomplished software and hardware designers. Of course, no one should expect to become an expert in using the M68HC11 in a single course.

The following study plan, summarized in Table I, will help the reader become familiar with the principles of microcomputer systems and to learn about the M68HC11 microcontroller as an example. A well designed course should have the student learn general design principles illustrated by examples of a specific processor. Table I shows how one could combine this text with Microcontrollers and Microcomputers: Principles of Software and Hardware Engineering to give the student a reference than can be used when applying other processors later in his or her career.

Two useful appendices are included. Appendix A gives a list of references pointing the reader toward more information about the M68HC11. There is a wealth of information to be gleaned from the Internet and from Motorola application notes. Appendix B explains the versions of the M68HC11 microcontroller family.

In addition to covering the features common to all members of the M68HC11 family of microcontrollers, advanced features are discussed. These include the pulse-width modulator in Chapter 10, the 16-bit math coprocessor in Chapter 13, and the 8-bit digital-to-analog converter in Chapter 12. The enhanced Serial Communications Interface (SCI) and Serial Peripheral Interface (SPI) are discussed in Chapter 11.


Table I. M68HC11 Study plan.

The following study plan will help the reader become familiar with the principles of microcomputer systems and to learn about the M68HC11 microcontroller as an example. Table I shows how one could combine this text with Microcontrollers and Microcomputers: Principles of Software and Hardware Engineering to give the student a reference than can be used when applying other processors later in his or her career.

Study Goals Microcontrollers and Microcomputers:
Principles of Software and Hardware Engineering
Software and Hardware Engineering:
Motorola M68HC11
Overview Chapter 1. Introduction Chapter 1. Introduction
Learn about the architecture of stored program computer. Chapter 2. The Picoprocessor: An Introduction to Computer Architecture .
Learn about different registers in a CPU and how the codes used for various information affect how we interpret the Condition Code Register. Chapter 3. Introduction to the CPU: Registers and Condition Codes Chapter 2. Introduction to the M68HC11 Hardware
Learn about the various ways a CPU can address memory. Chapter 4. Addressing Modes .
Learn how an assembler works and some of the techniques of programming in assembly language. Learn how to operate your laboratory assembler. Chapter 5. Assembly Language Programming and Debugging Chapter 3. Motorola AS11 Assembler
See how instructions can be grouped into categories that help make your beginning programming tasks easier. . Chapter 4. Introduction to the M68HC11 Instruction Set
Learn how to debug assembly language programs. . Chapter 5. Buffalo Monitor and Debugger
Learn how to properly design more complex software. Chapter 6. Top Down Software Design .
Develop good assembly language programming style. . Chapter 6. AS11 Programs for the M68HC11
Learn about parallel data transfer, timing, addressing and I/O interfaces. Chapter 7. Computer Buses and Parallel Input/Output Chapter 7. M68HC11 Parallel I/O.
Learn about interrupts and interrupt service routines. Chapter 8. Interrupts and Real-Time Events Chapter 8. M68HC11 Interrupts
Learn about the different types of memory and how the organization of the memory is affected by the type of computer system being designed. Chapter 9. Computer Memories Chapter 9. M68HC11 Memories
Many interrupts in real-time systems are generated by timer circuits. In this chapter we learn about the timer in the M68HC11. . Chapter 10. M68HC11 Timer
The elements of serial I/O are quite simple and yet serial interfacing is frustrating. These chapters will help you learn how to deal with the problems of serial interfacing. Chapter 10. Serial Input/Output Chapter 11. M68HC11 Serial I/O
Information in the real world is often analog. This chapter will show you how various A/D and D/A devices work and how to specify either in a system. Chapter 11. Analog Input and Output Chapter 12. M68HC11 Analog Input and Output.
This chapter is a general look at more advanced hardware features of your laboratory microprocessor. . Chapter 13. Advanced M68HC11 Hardware
The final exam is a look at the Motorola M68HC11EVB Evaluation Board. . Chapter 14. The Motorola M68HC11EVB Evaluation Board


TABLE OF CONTENTS


CHAPTER 1. INTRODUCTION 1.1 INTRODUCTION 1 1.2 COMPUTERS, MICROPROCESSORS, MICROCOMPUTERS, MICROCONTROLLERS 1 1.3 SOME BASIC DEFINITIONS 3 1.4 NOTATION 3 1.5 BIBLIOGRAPHY AND FURTHER READING 4 1.6 REFERENCES 4 CHAPTER 2. INTRODUCTION TO THE M68HC11 HARDWARE 2.1 CHAPTER PRE-STUDY MATERIAL 5 2.2 INTRODUCTION 5 2.3 CPU AND REGISTERS 8 THE PROGRAMMER'S CPU MODEL 8 CONTROL REGISTERS 10 2.4 ADDRESSING MODES 13 IMMEDIATE ADDRESSING 13 DIRECT AND EXTENDED ADDRESSING 13 INDEXED ADDRESSING 14 INHERENT ADDRESSING 15 RELATIVE ADDRESSING 16 2.5 RESET 16 THE RESET ACTION 17 CAUSES OF RESET 18 RESET SUMMARY 18 2.6 CONCLUSION AND CHAPTER SUMMARY POINTS 18 2.7 BIBLIOGRAPHY AND FURTHER READING 19 2.8 PROBLEMS 19 CHAPTER 3. MOTOROLA AS11 ASSEMBLER 3.1 ASSEMBLY LANGUAGE EXAMPLE 21 3.2 M68HC11 AS11 ASSEMBLER 23 3.3 ASSEMBLER SOURCE CODE FIELDS 23 LABEL FIELD 23 OPCODE OR OPERATION FIELD 25 OPERAND FIELD 25 COMMENT FIELD 31 3.4 ASSEMBLER DIRECTIVES 31 SET THE PROGRAM COUNTER 32 DEFINING SYMBOLS 33 RESERVING MEMORY LOCATIONS 34 DEFINING CONSTANTS IN MEMORY 35 MISCELLANEOUS DIRECTIVES 38 3.5 ASSEMBLER OUTPUT FILES 39 3.6 ASSEMBLER INVOCATION 40 3.7 ASSEMBLER ERROR MESSAGES 41 3.8 CHAPTER SUMMARY POINTS 41 3.9 PROBLEMS 42 CHAPTER 4. THE M68HC11 INSTRUCTION SET 4.1 INTRODUCTION 44 4.2 M68HC11 INSTRUCTION SET CATEGORIES 44 4.3 LOAD AND STORE REGISTER INSTRUCTIONS 47 EIGHT-BIT LOAD AND STORE INSTRUCTIONS 48 SIXTEEN-BIT LOAD AND STORE INSTRUCTIONS 51 STACK INSTRUCTIONS 52 4.4 TRANSFER REGISTER INSTRUCTIONS 56 4.5 DECREMENT AND INCREMENT INSTRUCTIONS 58 4.6 CLEAR AND SET INSTRUCTIONS 61 4.7 SHIFT AND ROTATE INSTRUCTIONS 66 4.8 ARITHMETIC INSTRUCTIONS 72 ADD AND SUBTRACT 72 DECIMAL ARITHMETIC 75 NEGATING INSTRUCTIONS 77 MULTIPLICATION 77 FRACTIONAL NUMBER ARITHMETIC 78 DIVISION 79 MATHEMATICS COPROCESSOR 80 4.9 LOGIC INSTRUCTIONS 81 4.10 DATA TEST INSTRUCTIONS 83 4.11 CONDITIONAL BRANCH INSTRUCTIONS 85 SIGNED AND UNSIGNED CONDITIONAL BRANCHES 86 4.12 UNCONDITIONAL JUMP AND BRANCH INSTRUCTIONS 88 BRANCHES TO SUBROUTINES 89 4.13 CONDITION CODE REGISTER INSTRUCTIONS 90 4.14 INTERRUPT INSTRUCTIONS 93 4.15 MISCELLANEOUS INSTRUCTIONS 93 4.16 ADVANCED INSTRUCTION SET DETAILS 94 4.17 CHAPTER SUMMARY POINTS 94 4.18 BIBLIOGRAPHY AND FURTHER READING 94 4.19 PROBLEMS 95 CHAPTER 5. BUFFALO MONITOR AND DEBUGGER 5.1 M68HC11 EVB BUFFALO MONITOR 99 ENTERING THE MONITOR 99 COMMAND LINE FORMAT 100 5.2 MONITOR COMMANDS 100 5.3 MONITOR UTILITY ROUTINES 106 5.4 BUFFALO MONITOR INTERRUPT JUMP VECTOR TABLE 107 5.5 OPERATING HINTS FOR THE BUFFALO MONITOR 109 5.6 PROBLEMS 109 CHAPTER 6. AS11 PROGRAMS FOR THE M68HC11 6.1 ASSEMBLY LANGUAGE PROGRAMMING STYLE 111 SOURCE CODE STYLE 111 TO INDENT OR NOT TO INDENT 118 UPPER AND LOWER CASE 118 USE EQUATES, NOT MAGIC NUMBERS 119 USING BOILERPLATE FILES 120 USING MONITOR ROUTINES 120 COMMENTING STYLE 120 SUBROUTINE OR FUNCTION HEADERS 121 6.2 STRUCTURED ASSEMBLY LANGUAGE PROGRAMMING 121 SEQUENCE 121 DECISION 122 WHILE-DO REPETITION 124 DO-WHILE REPETITION 126 6.3 EXAMPLE PROGRAMS 128 6.4 CONCLUSION AND CHAPTER SUMMARY POINTS 134 6.5 BIBLIOGRAPHY AND FURTHER READING 135 6.6 PROBLEMS 135 CHAPTER 7. M68HC11 PARALLEL I/O 7.1 INTRODUCTION 138 7.2 OPERATING MODES 140 NORMAL SINGLE-CHIP MODE 140 NORMAL EXPANDED-MODE 141 7.3 THE PROGRAMMER'S MODEL 145 7.4 M68HC11 PARALLEL I/O PORTS 146 PORT B 146 PORT A 146 PORT C 148 PORT D 153 PORT E 155 7.5 HANDSHAKING I/O 156 SIMPLE STROBED I/O 156 FULL HANDSHAKING I/O 159 7.6 I/O SOFTWARE 166 REAL-TIME SYNCHRONIZATION 167 POLLED I/O 169 7.7 CHAPTER SUMMARY POINTS 169 7.8 BIBLIOGRAPHY AND FURTHER READING 170 7.9 PROBLEMS 170 CHAPTER 8. M68HC11 INTERRUPTS 8.1 INTRODUCTION 172 8.2 THE INTERRUPT PROCESS 173 THE INTERRUPT ENABLE 173 THE INTERRUPT DISABLE 173 THE INTERRUPT REQUEST 173 THE INTERRUPT SEQUENCE 174 THE INTERRUPT RETURN 175 8.3 INTERRUPT VECTORS 175 DEDICATED SYSTEM VECTORS 175 BUFFALO MONITOR INTERRUPT VECTOR JUMP TABLE 177 8.4 INTERRUPT PRIORITIES 179 8.5 NONMASKABLE INTERRUPTS 181 SOFTWARE INTERRUPT - SWI 182 CLOCK MONITOR FAILURE 182 COP FAILURE 182 ILLEGAL OPCODE TRAP 182 NONMASKABLE INTERRUPT REQUESTQ 182 8.6 PARALLEL I/O SYSTEM INTERRUPTS 183 OTHER INTERNAL INTERRUPT SOURCES 186 8.7 ADVANCED INTERRUPTS 186 SHAREDQ AND PARALLEL I/O INTERRUPT VECTOR 186 POLLING FOR MULTIPLE EXTERNAL DEVICES 187 SELECTING EDGE OR LEVEL TRIGGERING 187 WHAT TO DO WHILE WAITING FOR AN INTERRUPT 187 8.8 THE INTERRUPT SERVICE ROUTINE 188 INTERRUPT SERVICE ROUTINE HINTS 189 A DEDICATED SYSTEM ISR EXAMPLE 191 BUFFALO MONITOR ISR EXAMPLES 194 8.9 CONCLUSION AND CHAPTER SUMMARY POINTS 196 8.10 BIBLIOGRAPHY AND FURTHER READING 197 8.11 PROBLEMS 197 CHAPTER 9. M68HC11 MEMORIES 9.1 INTRODUCTION 199 9.2 M68HC11 MEMORY MAP 199 9.3 M68HC11 RAM 200 9.4 M68HC11 ROM 202 9.5 M68HC11 EPROM 202 9.6 M68HC11 EEPROM 202 EEPROM READING 203 EEPROM PROGRAMMING REGISTER 203 EEPROM PROGRAMMING VOLTAGE 204 EEPROM PROGRAMMING 204 EEPROM ERASING 206 9.7 MEMORY TIMING IN EXPANDED-MODE OPERATION 208 9.8 EXTENDING M68HC11 MEMORY ADDRESSES 211 9.9 CONCLUSION AND CHAPTER SUMMARY POINTS 220 9.10 BIBLIOGRAPHY AND FURTHER READING 220 9.11 PROBLEMS 220 CHAPTER 10. M68HC11 TIMER 10.1 INTRODUCTION 221 10.2 BASIC TIMER 223 SIXTEEN-BIT FREE-RUNNING TCNT REGISTER 224 TIMER OVERFLOW FLAG 225 TIMER OVERFLOW INTERRUPTS 226 10.3 OUTPUT COMPARE 229 OUTPUT COMPARE TIME DELAYS 230 OUTPUT COMPARE INTERRUPTS 231 OUTPUT COMPARE BIT OPERATION 234 ONE OUTPUT COMPARE CONTROLLING UP TO FIVE OUTPUTS 235 VERY SHORT DURATION PULSES 236 FORCED OUTPUT COMPARES 238 10.4 INPUT CAPTURE 238 10.5 REAL-TIME INTERRUPT 242 10.6 COMPUTER OPERATING PROPERLY - COP 244 10.7 PULSE ACCUMULATOR 246 PULSE ACCUMULATOR INTERRUPTS 248 10.8 PULSE-WIDTH MODULATION 250 PULSE-WIDTH MODULATOR CLOCK CONTROL 251 PULSE-WIDTH MODULATION CONTROL REGISTERS 252 CHOOSING PULSE-WIDTH MODULATION PRE-SCALE VALUES 256 10.9 EXTERNAL INTERRUPTS USING TIMER INTERRUPTS 260 10.10 CLEARING TIMER FLAGS 260 10.11 CONCLUSION AND CHAPTER SUMMARY POINTS 261 10.12 PROBLEMS 262 CHAPTER 11. M68HC11 SERIAL I/O 11.1 INTRODUCTION 264 11.2 ASYNCHRONOUS SERIAL COMMUNICATIONS INTERFACE - SCI SCI DATA 265 SCI INITIALIZATION 266 SCI STATUS FLAGS 269 SCI INTERRUPTS 271 SCI WAKE UP 273 SCI BREAK CHARACTER 275 SCI PROGRAMMING EXAMPLE 275 11.3 ENHANCED SCI 277 11.4 SYNCHRONOUS SERIAL PERIPHERAL INTERFACE - SPI 279 INTERPROCESSOR SERIAL COMMUNICATIONS 279 SPI DATA REGISTER 280 SPI INITIALIZATION 280 SPI STATUS REGISTER AND INTERRUPTS 284 SPI INTERRUPTS 285 11.5 ENHANCED SPI 286 11.6 CONCLUSION AND CHAPTER SUMMARY POINTS 287 11.7 BIBLIOGRAPHY AND FURTHER READING 288 11.8 PROBLEMS 288 CHAPTER 12. M68HC11 ANALOG INPUT AND OUTPUT 12.1 INTRODUCTION 290 12.2 M68HC11 A/D CONVERTER 290 A/D INITIALIZATION 292 A/D OPERATION 294 12.3 A/D I/O SYNCHRONIZATION 296 12.4 A/D PROGRAMMING EXAMPLE 296 12.5 DIGITAL-TO-ANALOG CONVERTER 297 12.6 CHAPTER SUMMARY POINTS 298 12.7 BIBLIOGRAPHY AND FURTHER READING 299 12.8 PROBLEMS 299 CHAPTER 13. ADVANCED M68HC11 HARDWARE 13.1 HARDWARE MODE SELECT 300 SPECIAL TEST MODE 301 SPECIAL BOOTSTRAP MODE 301 13.2 CONFIGURATION CONTROL REGISTER 302 13.3 SYSTEM OPTION REGISTER 304 13.4 SECURITY MODE 305 13.5 M68HC11 MATH COPROCESSOR 306 MATH COPROCESSOR OPERATIONS 310 MATH COPROCESSOR INTERRUPTS 315 13.6 BIBLIOGRAPHY AND FURTHER READING 316 CHAPTER 14. THE MOTOROLA M68HC11EVB EVALUATION BOARD 14.1 INTRODUCTION 317 14.2 EVB COMPONENTS AND CIRCUITS 317 MCU I/O PORT CONNECTOR 319 POWER SUPPLY 321 RESET CIRCUIT 321 CPU CRYSTAL CLOCK OSCILLATOR 322 M68HC11 322 14.3 I/O PORTS 322 PORT A 322 PORT B AND PORT C 322 PORT D 322 PORT E 323 INTERRUPTS 323 14.4 M68HC11 EXPANDED MODE 323 ADDRESS DECODING 324 EXTERNAL ROM 324 EXTERNAL RAM/EPROM SOCKET 324 EXTERNAL RAM 325 M68HC24 PORT REPLACEMENT UNIT 325 E-CLOCK 325 14.5 SERIAL I/O INTERFACE 325 M6850 ASYNCHRONOUS COMMUNICATION INTERFACE ADAPTER 325 RS-232-C INTERFACE 326 14.6 CHAPTER SUMMARY POINTS 326 14.7 BIBLIOGRAPHY AND FURTHER READING 326 APPENDIX A. M68HC11 RESOURCES A.1 INTERNET RESOURCES 327 THE WORLD WIDE WEB 327 EMAIL LIST SERVERS 328 FTP 329 A.2 MOTOROLA APPLICATION NOTES AND LITERATURE 330 A.3 HARDWARE AND SOFTWARE VENDORS 331 APPENDIX B. M68HC11 FAMILY B.1 THE M68HC11 FAMILY OF MICROCONTROLLERS 332 B.2 M68HC11 PART NUMBERING AND PACKAGING 334 ANSWERS TO CHAPTER PROBLEMS 495 INDEX