microelectronics andmicroprocessor-basedsystems978-1-349-06978-1/1.pdf · students attending btec...

12
Microelectronics and Microprocessor-based Systems

Upload: lenhu

Post on 07-Jul-2018

247 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

Microelectronics and Microprocessor-based Systems

Page 2: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

Other Macmillan Booksof Related Interest

Microprocessors and Microcomputers Eric HugginsDigital Electronic Circuits and Systems Noel M. MorrisMicroprocessor and Microcomputer Technology Noel M. MorrisSemiconductor Devices Noel M. MorrisIntroduction to Digital Filters T. J . TernellInformation Theory for Information Technologists M. J. UsherUnderstanding Microprocessors B. S. WalkerMastering Electronics John Watson

Page 3: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

Microelectronic andMicroprocessor-based

Systems

Noel M. Morris

North Staffordshire Polytechnic

MMACMILLAN

Page 4: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

© Noel M. Morris 1985

All rights reserved. No part of this publication may be reproduced or transmitted,in any form or by any means, without permission

First published 1985 byHigher and Further Education DivisionMACMILLAN PUBLISHERS LTDHoundmills, Basingstoke, Hampshire RG21 2XS and LondonCompanies and representatives throughout the world

Typeset in Great Britain byTEC SET, Sutton, Surrey

British Library Cataloguing in Publication Data

Morris, Noel M.Microelectronic and microprocessor-basedsystems .1. Microcomputers 2. MicroprocessorsI. Title001.64'04 QA76.5

ISBN 978-0-333-36 190-0DOI 10.1007/978-1-349-06978-1

ISBN 978-1-349-06978- 1 (eBook)

Page 5: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

Contents

Preface xi

1 Binary Numbers and Arithmetic 1

1.1 Binary numbers 11.2 The binary numbering system 21.3 The octal numbering system 21.4 The hexadecimal numbering system 31.5 Converting an integer of any radix into its decimal equivalent 41.6 Converting a decimal integer into its equivalent in any radix 51.7 Converting a binary integer into an octal integer 51.8 Converting a binary integer into its hexadecimal equivalent 51.9 Converting a decimal integer into its hexadecimal equivalent 51.10 Addition 61.11 Binary addition 71.12 Unsigned binary numbers 81.13 Hexadecimal addition 81.14 Status register or flag register of a microprocessor 91.15 Signed binary numbers 91.16 Negative numbers 91.17 Binary subtraction 101.18 The range of values that can be handled by an 8-bit

microcomputer 111.19 Overflow in an 8-bit microcomputer 121.20 Byte 12Problems 12

2 Introduction to Microprocessors and Microcomputers 14

2.1 Digital computing2.2 A simple microcomputer2.3 Peripherals and input/output (I/O) ports2.4 A minimal microprocessor-based system2.5 Hardware , software and firmware2.6 A simple microprocessor-based system2.7 Parallel input/output (I/O) ports

14141717171820

Page 6: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

vi

2.8 Serial I/O ports2.9 A simplified memory map of a microcomputer2.10 Three-state or tri-state gates2.11 Using three-state gates with bus systemsProblems

3 The CPU and its Fetch-Execute Cycle

3.1 The architecture of a microprocessor chip or CPU3.2 Multiplexed bus systems3.3 The fetch-execute cycleProblems

4 Bus Signal Timing and Input/Output Timing

4.1 The clock generator4.2 Outgoing data transfers from the CPU4.3 A memory write machine cycle4.4 An I/O write machine cycle4.5 Incoming data transfers to the CPU4.6 A memory read machine cycle4.7 An I/O read machine cycle4.8 Memory access time4.9 Input/output timing4.10 Software polling4.11 Introduction to interrupts4.12 Data transfers using an electronic 'handshake'Problems

5 Storage Systems or Memory Systems and Address Decoding

5.1 Introduction5.2 Simplified structure of a read-only memory chip5.3 Pin connections to a practical ROM chip5.4 Pin connections to a practical RAM chip5.5 Partial addressing of memory chips - 'foldback' on the

memory map5.6 Relationship between the size of ROM and RAM in a

microcomputerProblems

6 Interfacing

6.1 General principles6.2 Tri-state buffers6.3 An interface between the data bus and LED displays

Contents

2323242627

28

28323333

35

35353637373839393940414243

44

44454752

57

5858

60

606063

Page 7: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

Contents

6.4 Driving a single 7-segment display6.5 A simple keyboard system6.6 An encoded keyboard6.7 A microcomputer with a keyboard input and a 7-segment display6.8 Conversion of voltage and current levels, UARTsProblems

7 Timing Methods and Programmable Timers

7.1 Applications of timing sequences7.2 The basis of a software time delay program7.3 Using a programmable timerProblems

8 An Introduction to Program Creation

8.1 A problem-solving routine - an algorithm8.2 Flowcharts8.3 Structured programming8.4 A simple linear program8.5 Double-precision or double-length addition8.6 A trace routine and trace table8.7 Monitor programProblems

vii

656768707377

78

78788081

82

8282828588899293

9 An Instruction Set and Addressing Modes

9.19.2

9.39.49.59.69.79.89.99.109.119.129.139.149.159.169.17

Introduction to the instruction setMachine code and assembly language representationof instructionsInstruction classificationData transfer instructionsArithmetic and logic instructionsTest and branch instructionsAddressing modes or addressing methodsImmediate addressingImplied addressing or inherent addressingDirect addressing"Zero page addressingRegister addressing or register direct addressingIndirect addressingRegister indirect addressingStack addressingIndexed addressingRelative addressing

94

94

94959596

101102102104105106106106107108108109

Page 8: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

viii

9.18 Addressing mode combinations9.19 Instructions in machine code form9.20 Instructions in assembly language form9.21 Pseudo-operations9.22 Lookup tables9.23 Indexed addressing - the use of looku p tables9.24 Using a lookup table for code conversionProblems

10 Programs with Loops

10.1 The need for loops in programs10.2 Adding hexadecimal data stored in a table10.3 An extended hexadecimal addition program10.4 Adding decimal data stored in a table10.5 A software time delay program10.6 A nested time delay program10.7 An alternative looping pattern10.8 A more complex looping patternProblems

11 Subroutines and the Stack

11.1 Subroutines11.2 Subroutine structure11.3 The stack11.4 A program with a subroutine11.5 Nested subroutines11.6 Parameter passingProblems

Contents

109109110112113114116116

118

118119125125125127129130131

132

132133134138140143143

12 Digital Input and Output

12.112.212.312.412.512.612.712.812.912.1012.11

IntroductionA programmable I/O (PIO) portPIO initialisationAn input/output control moduleA digital input and output programDigital input and output with a subroutineStepper motor drivesHandshake data transfers or strobed data transfersImplementing handshake transfersGeneral principle of an input handshake routineGeneral principle of an output handshake routine

145

145145147148148149152159161163163

Page 9: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

Contents ix

12.12 Handshake data transfer with a practical PIO 16412.13 The 8155 PIO status register 16612.14 A handshake data transfer between an input peripheral

and an output peripheral 167Problems 170

13 Analogue Input and Output 173

13.1 Introduction 17313.2 An R-2R DAC 17313.3 Generating a square wave using a DAC 17513.4 Sawtooth (ramp) and triangular wave generation using

a DAC 17613.5 Waveform generation using a lookup table 17813.6 A software-driven analogue-to-digital converter (ADC) 17913.7 A software-driven continuous balance ADC 18213.8 A software-driven successive-approximation ADC 18313.9 Interfacing a hardware ADC chip to a CPU 18813.10 Unipolar and bipolar operation of an ADC 192Problems 194

14 Interrupts 196

14.1 Introduction 19614.2 Comparison of interrupt facilities 19714.3 A typical interrupt handling sequence 19714.4 8085 interrupts 19814.5 8085 interrupt priority 20014.6 The interrupt mask or I register 20014.7 A general procedure for interrupt handling 20214.8 A program containing an interrupt 20414.9 Multiple interrupts 20614.10 PIO timer interrupts 20914.11 Determining the timing period of an 8155 programmable

timer 21214.12 An elapsed time interrupt using a programmable timer 21214.13 Interrupt controlled handshake data transfers 21414.14 A timing diagram for an interrupt-driven input handshake 21414.15 A timing diagram for an interrupt-driven output handshake 21514.16 8155 PIO handshakes 21614.17 A handshake transfer using polled interrupts 21714.18 An interrupt-driven handshake data transfer 218Problems 221

Page 10: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

x

Appendix A : 8085 Instruction Set by OpcodeAppendix B: 8085 Instruction Set by Clock Cycles

Solutions to Problems

Index of Useful Programs

Index

Contents

223229

231

234

235

Page 11: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

xi

Preface

The subjects of microelectronics and microprocessor-based systems are taught atlevels ranging from school to postgraduate. The purpose of this book is to providecoverage, in breadth and in depth, not only of microcomputer programming inassembly language and machine code , but also of microcomputer hardware .

The treatment is appropriate for many underg raduate courses in a range ofdisciplines including electronic and electrical engineering, physics, mechanicalengineering, science and other related engineering and science-based courses.Students attending BTEC Certificate, Diploma, HNC and HND courses that includemicroelectronic and microprocessor-based systems options will find the book ofvalue from level III to level V. Students taking 'A' level computer studies optionswill also benefit from the book .

Chapter 1 commences with an outline of numbers and numbering systems ; thisinformation is introduced at an early stage to provide background material. Chapters2, 3 and 4 lead logically from an introduction to microcomputers, through thefetch-execute cycle of the central processing unit to an appreciation of the bus­timing waveforms involved in data transfers .

Chapter 5 deals with data storage in ROMs and RAMs, and introduces the"memory map" of a typical microcomputer. Interfacing between a microcomputerand its peripherals in a small system is covered in chapter 6 and , in chapter 7,programmable timers are introduced.

Chapter 8 deals with important concepts of programming including algorithms,flowcharts, structured programming and trace routines. In chapter 9 the readermeets the instruction set of a typical microprocessor. The Intel 8085 has beenchosen for the model in this book since its instruction set includes all the instruc­tions in the popular Intel 8080 central processor , and is a vital sub-set not only ofthe Z80 CPU but also of the l e-bit 8086 and 8088 CPUs. Chapter 9 includes detailsof instruction classification , addressing modes, machine code and assembly languageforms of instructions, pseudo-operations and the use of lookup tables .

Chapter 10 deals with practical programs that include loops ; this chapter coversbinary and decimal addition, multi-byte addition and time delays. In chapter II,the reader is introduced to subroutines and the "stack", and also to work onnested subroutines and parameter passing.

The important aspect of digital data transfer between the microcomputer andinput/output peripherals is covered in chapter 12. This chapter deals with steppermotor drives, together with handshake data transfers and their method of imple-

Page 12: Microelectronics andMicroprocessor-basedSystems978-1-349-06978-1/1.pdf · Students attending BTEC Certificate, Diploma, HNC and HND courses that include microelectronic and microprocessor-based

xii Preface

mentation. Analogue data transfer using digital-to-analogue convertors (DAC) andanalogue-to-digital convertors (ADC) is described in chapter 13. Both hardwareand software-driven ADCs are included in this chapter, together with informationabout unipolar and bipolar operation.

Chapter 14 is devoted to interrupts in microprocessor-based systems. The chaptercovers interrupt facilities , interrupt priority (and also the method of changing thepriority), and a timer interrupt. Details are given about the method of programminga programmable timer, and its use in generating an elapsed-time interrupt. Informa­tion and programs are given relating to polled-interrupt and interrupt-driven hand­shake data transfers. Details of the Intel 8085 instruction set are laid out in appendixA and appendix B.

Illustrative examples and programs are provided throughout the book and end­of-chapter problems (with solutions) are included. For the convenience of thereader, a separate index of many useful programs in the book is given.

The programs in the book will run with little or no modification on the IntelSDK85 computer and on the MAT385 Microprocessor Applications Trainer manu­factured by Feedback Instruments Ltd of Crowborough, Sussex, U.K.

The author is indebted to the Intel Corporation, Feedback Instruments Ltd , andRS Components Ltd. The following colleagues at the North Staffordshire Poly­technic have also made a material contribution to the book: Dr F. Wright andMr F. W. Senior, M.Sc., of the Electrical and Electronic Department, and Mr S.Rakowski , M.Sc., of the Physics Department.

Finally, this book could not have been written without the support and help ofmy wife.

North Staffordshire Polytechnic Noel. M. MORRIS