e&i microprocessors and microcontrollers
TRANSCRIPT
A Nagoor Kani
MICROPROCESSORS and MICROCONTROLLERS
EEE E&I ICE Courses| |
for Anna University
A N
ag
oo
r Kani
9 789354 661563
ISBN: 978-93-5466-156-3
4819/XI, Prahlad Street, 24 Ansari Road, Daryaganj, New Delhi 110 002, IndiaE-mail: [email protected], [email protected]; Website: www.cbspd.comNew Delhi | Bengaluru | Chennai | Kochi | Kolkata | Lucknow | Mumbai
| | | | |Hyderabad Jharkhand Nagpur Patna Pune Uttarakhand
MICROPROCESSORS and MICROCONTROLLERSfor Anna Universityis primarily designed for the latest syllabus of Anna University—EEE E&I ICE | |courses. This book deals with 8085 microprocessor and 8051 microcontroller architectures, programming, interfacing with peripherals and application case studies.
The book is organized into 5 chapters. The fundamental concepts of architectures and assembly language programming of 8085 microprocessor and 8051 microcontroller are presented in an easy and elaborative manner. The assembly language programs are illustrated with problem analysis, algorithm and flowchart for better understanding. The assembly language program codes are run on assemblers with sample data and list file and the results are presented for clear understanding of the reader also useful for laboratory exercises. Salient Features• Solution for university questions will enable students to score better in
examinations.• Clear explanation of memory and peripheral interfacing with appropriate
diagrams.• Different types of fonts for text, examples and programs for better
understanding.• Step-by-step explanation of program and interfacing concepts. • Application case studies are explained with appropriate diagrams and
sample programs.
A Nagoor Kani BE, MS
is a multifaceted personality with an efficient technical expertise and management skills. He obtained his BE in EEE from Thiagarajar College of Engineering, Madurai, and MS (Electronics and Control) through Distance Learning Program from BITS, Pilani.
He started his career as a self-employed industrialist (1986–1989) and then changed his career to teaching in 1989. He worked as Lecturer in Dr MGR Engineering College (1989–1990) and as Assistant Professor in Satyabhama Engineering College (1990–1997). He started his own coaching center for BE students named Institute of Electrical Engineering which was renamed as RBA Tutorials in 2005. The well-known companies currently run by him are RBA Engineering (manufacturing laboratory equipment and microprocessor trainer kits), RBA Innovations (involved in developing projects for engineering students and industries), RBA Tutorials (conducting coaching classes for engineering and GATE students) and RBA Publications (publishing of engineering books). He is an eminent writer and has written 13 engineering books.
MICROPROCESSORS and MICROCONTROLLERS
Microprocessors and Microcontrollers
for Anna UniversityEEE | E&I | ICE Courses
Other CBS Titles by A Nagoor Kani
z A Simplified Text in Electrical Machine Design, 3/ez Advanced Control Theory, 3/ez Circuit Analysis, 2/e (Anna University/ECE)z Control Systems, 5/ez Control Systems (Anna University/EEE)z Control Systems Engineering (Anna University/ECE)z Control Systems Engineering, 2/ez Circuit Theory, 2/e (Anna University/EEE)z Design of Electrical Apparatus (Anna University/EEE)z Digital Signal Processing, 3/ez Microprocessors and Microcontrollers (Anna University/ECE)z Microprocessors and Microcontrollers, 3/ez Power System Analysis z Signals and Systems–Simplified, 2/e (for Anna University)z 8085 Microprocessor and its Applications, 4/ez 8086 Microprocessor and its Applications, 3/ez Digital Electronics (in Press)z Digital Logic Circuits (in Press)z Digital Electronics (Anna University/ECE) (in Press)z Digital Logic Circuits (Anna University/EEE) (in Press)z Digital Principles and System Design (in Press)z Digital Principles and System Design (Anna University/CSE/IT) (in Press)z Digital Signal Processing (Anna University/EEE) (in Press)z Discrete Time Signal Processing (Anna University/ECE) (in Press)z Electric Circuits, 2/e (in Press)z Signals and Systems, 2/e (in Press)
Microprocessors and Microcontrollers
for Anna UniversityEEE | E&I | ICE Courses
A Nagoor KaniFounder, RBA Educational Group
Chennai
CBS Publishers & DistributorsCBS Publishers & Distributors Pvt LtdPvt LtdNew Delhi • Bengaluru • Chennai • Kochi • KolkataNew Delhi • Bengaluru • Chennai • Kochi • Kolkata • Lucknow • Lucknow • Mumbai • Mumbai
Hyderabad • Jharkhand • Nagpur • Patna • Pune • UttarakhandHyderabad • Jharkhand • Nagpur • Patna • Pune • Uttarakhand
ISBN: 978-93-5466-156-3
Copyright © Author and Publisher
First Edition: 2022
All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system without permission, in writing, from the authors and the publisher.
Published by Satish Kumar Jain and produced by Varun Jain forCBS Publishers & Distributors Pvt Ltd 4819/XI Prahlad Street, 24 Ansari Road, Daryaganj, New Delhi 110 002, India Ph: 011-23289259, 23266861, 23266867 Fax: 011-23243014Website: www.cbspd.com e-mail: [email protected]; [email protected]
Corporate Office: 204 FIE, Industrial Area, Patparganj, Delhi 110 092, IndiaPh: 011-49344934 Fax: 011-49344935 e-mail: [email protected]; [email protected]
Branches• Bengaluru: Seema House 2975, 17th Cross, K.R. Road, Banasankari 2nd Stage, Bengaluru 560 070, Karnataka, India Ph: +91-80-26771678/79 Fax: +91-80-26771680 e-mail: [email protected]• Chennai: 7, Subbaraya Street, Shenoy Nagar, Chennai 600 030, Tamil Nadu, India Ph: +91-44-26680620, 26681266 Fax: +91-44-42032115 e-mail: [email protected]• Kochi: 42/1325, 1326, Power House Road, Opposite KSEB, Power House, Ernakulum-682018, Kochi, Kerala, India Ph: +91-484-4059061-67 Fax: +91-484-4059065 e-mail: [email protected]• Kolkata: 147, Hind Ceramics Compound, 1st Floor, Nigunj Road, Belghoria, Kolkata-700056, West Bengal, India Ph: +91-33-22891126, 22891127, 22891128 e-mail: [email protected]• Lucknow: Basement, Khushuma Complex, 7 Meerabai Marg (Behind Jawahar Bhawan), Lucknow-226001, UP, India Ph: +522-40000032 e-mail: [email protected]
• Mumbai: PWD Shed, Gala No. 25/26, Ramchandra Bhatt Marg, Next JJ Hospital Gate No. 2 Opp. Union Bank of India, Noorbaug, Mumbai-400009, Maharashtra, India Ph: +91-22-66661880/89 Mob: 0-8424005858 e-mail: [email protected]
Representatives• Hyderabad 0–9885175004 • Jharkhand 0–9811541605 • Nagpur 0–9421945513
• Patna 0–9334159340 • Pune 0–9623451994 • Uttarakhand 0–9716462459
Printed at: Mudrak, Noida, UP, India.
DisclaimerScience and technology are constantly changing fields. New research and experience broaden the scope of information and knowledge. The author has tried his best in giving information available to him while preparing the material for this book. Although all efforts have been made to ensure optimum accuracy of the material, yet it is quite possible some errors might have been left uncorrected. The publisher, the printer and the author will not be held responsible for any inadvertent errors or inaccuracies.
to
My Father-in-law Capt R Chandrasekaran and
Mother-in-law Mrs Amala Chandra
PREFACE
This text on microprocessor and microcontroller has been crafted and designed for the latest syllabus of Anna university EEE/E&I/ICE courses. The various concepts of 8085 microprocessor are discussed in Chapters 1 and 2 and the concepts of 8051 microcontroller are discussed in Chapters 3 and 5. Interfacing of peripherals with 8085 and 8051 are discussed in Chapter 4.
Chapter 1 briefs about evolution of microprocessor and the basic terms involved in a microprocessor literature. The architecture, memory organisation and timing diagram of machine cycles of 8085 microprocessor are discussed in detail in Chapter 1. A brief discussion about semiconductor memory and peripheral devices and their interfacing with an 8085 microprocessor are presented in Chapter 1. Design examples are also included for better understanding of the concept of the memory and IO interfacing with an 8085 microprocessor. The importance of interrupts and the various interrupts of an 8085 processor are also discussed in Chapter 1.
The instruction set and assembly language programming concepts of 8085 microprocessor are discussed in Chapter 2. The timing diagram of some instructions are presented clearly for better understanding of execution of instructions. A number of 8085 microprocessor assembly language programming examples are included in Chapter 2 which are useful for microprocessor practical laboratory exercises.
Chapter 3 briefs about the basic concepts of 8051 microcontroller, architecture and memory organisation. The machine cycles of 8051 microcontroller with timing diagrams and instruction set of 8051 are also explained in detail in Chapter 3. The various interrupts of 8051 are also discussed in Chapter 3.
The popular peripheral devices 8255, 8259, 8254, 8279, ADC0809 and DAC0800 and their interfacing with 8085 and 8051 are discussed in detail in Chapter 4. Programming examples of ADC and DAC interface with 8051 are also presented in Chapter 4.
A number of 8051 microcontroller assembly language programming examples are included in Chapter 5 which are useful for microcontroller practical laboratory exercises. Detailed discussion about the timers of 8051, serial communication using serial port of 8051, interrupts of 8051 and keyboard and LCD interface with ports of 8051 along with programming examples are included in Chapter 5. Some application case studies of 8051 microcontroller-based system and programming are also presented in Chapter 5.
The instruction set of 8085 and 8051 are listed in Appendices II to IV, for the use of assembly language programmers. Anna university question papers are given at the end of the book. I have taken care to present the concepts of 8085 microprocessor and 8051 microcontroller in a simple manner and hope that the teaching and student community will welcome the book. The readers can feel free to convey their criticism and suggestions to [email protected] for further improvement of the book.
A Nagoor Kani
ACKNOWLEDGEMENTS
I express my heartfelt thanks to my wife Ms C Gnanaparanjothi Nagoor Kani and my sons N Bharath Raj Alias Chandrakani Allaudeen and N Vikram Raj for the support, encouragement and cooperation they have extended to me throughout my career. I thank Ms T A Benazir, Manager, RBA Group, and all my office-staff for their cooperation in carrying out my day-to-day activities.
It is my pleasure to acknowledge the contributions of our technical editors, Ms S Saranya and Ms P Kanimozhi and Ms K G Sathyapriya for editing, proof-reading and type-setting of the manuscript and preparing the layout of the book.
My sincere thanks to all reviewers for their valuable suggestions and comments which helped me to explore the subject to a greater depth.
I am also grateful to Mr Satish K Jain, CMD, CBS Publishers & Distributors, for his keen interest in publishing this work in CBS banner. My sincere thanks to all team members of CBS Publishers & Distributors, for their concern and care in publishing this work.
Finally, a special note of appreciation is due to my sisters, brothers, relatives, friends, students and the entire teaching community for their overwhelming support and encouragement to my writing.
A Nagoor Kani
CONTENTS
viiPreface
List of Abbreviations xv
CHAPTER 1: 8085 Processor 1.1–1.86
1.1 Introduction to Microprocessors 1.11.1.1 Terms used in Microprocessor Literature 1.11.1.2 Evolution of Microprocessors 1.31.1.3 Functional Building Blocks of a Microprocessor 1.61.1.4 Microprocessor Based System (Organization of a Microcomputer) 1.71.1.5 Concept of Multiplexing in Microprocessor 1.8
1.2 Hardware Architecture and Pinouts 1.91.2.1 Pin Configuration of 8085 1.101.2.2 Hardware Architecture of 8085 1.14
1.3 Memory Organization 1.171.3.1 Interfacing Static RAM and EPROM 1.171.3.2 Memory Organization in 8085 - Based System 1.22
1.4 IO Ports and Data Transfer Concepts 1.261.4.1 Interfacing IO and Peripheral Devices 1.271.4.2 Parallel Data Communication Interface 1.44
1.5 Timing Diagram 1.471.5.1 Processor Cycles 1.47 1.5.2 Machine Cycle of 8085 1.471.5.3 Opcode Fetch Machine Cycle of 8085 1.481.5.4 Memory Read Machine Cycle of 8085 1.491.5.5 Memory Write Machine Cycle of 8085 1.491.5.6 IO Read Cycle of 8085 1.501.5.7 IO Write Cycle of 8085 1.511.5.8 Interrupt Acknowledge Machine Cycle of 8085 1.511.5.9 Interrupt Acknowledge Cycle of 8085 with RST n Instruction 1.51
1.5.10 Interrupt Acknowledge Cycle of 8085 with CALL Instruction 1.531.5.11 Bus Idle Machine Cycle 1.551.5.12 Machine Cycle with Wait States 1.55
x Microprocessors and Microcontrollers
1.6 Interrupts 1.571.6.1 Classification of Interrupts 1.581.6.2 Interrupts of 8085 1.591.6.3 Enabling, Disabling and Masking of 8085 Interrupts 1.61 1.6.4 INTR and ITS Expansion 1.64
1.7 Short-Answer Questions 1.65
1.8 Exercises 1.80
CHAPTER 2: Programming of 8085 Processor 2.1–2.124
2.1 Instruction Format of 8085 2.1
2.2 Addressing Modes 2.1
2.3 Assembly Language Format 2.2
2.4 Instruction Set 2.3
2.5 Data Transfer Instructions 2.12
2.6 Data Manipulation and Control Instructions 2.202.6.1 Arithmetic Instructions 2.202.6.2 Logical Instructions 2.272.6.3 Branching Instructions 2.342.6.4 Machine Control Instructions 2.37
2.7 Timing Diagram of 8085 Instructions 2.392.7.1 Timing Diagram of STA Instruction 2.402.7.2 Timing Diagram of PUSH Instruction 2.412.7.3 Timing Diagram of IN Instruction 2.422.7.4 Timing Diagram of OUT Instruction 2.432.7.5 Timing Diagram of INR M Instruction 2.442.7.6 Timing Diagram of CALL Instruction 2.452.7.7 Timing Diagram of RET Instruction 2.47
2.8 Levels of Programming 2.482.8.1 Machine Level Programming 2.482.8.2 Assembly Level Programming 2.482.8.3 High Level Programming 2.49
2.9 Flowchart 2.49
2.10 Assembly Language Program Development Tools 2.502.10.1 Editor (Text Editor) 2.51 2.10.2 Assembler 2.51 2.10.3 Library Builder 2.522.10.4 Debugger 2.52
Contents xi
2.10.5 Simulator 2.532.10.6 Emulator 2.53
2.11 Modular Programming 2.552.11.1 Linking and Relocation 2.552.11.2 Subroutine 2.562.11.3 Handling Subroutine 2.562.11.4 Delay Routine 2.562.11.5 Stack 2.57
2.12 Assembly Language Programming 2.582.12.1 Simple Program 2.582.12.2 Programs with Loop Structure and Counter 2.712.12.3 Program with Indexing 2.852.12.4 Program with Loopup Table 2.902.12.5 Program with Subroutine 2.922.12.6 Program Involving Stack 2.100
2.13 Short-Answer Questions 2.105
2.14 Exercises 2.115
CHAPTER 3: 8051 Microcontroller 3.1–3.58
3.1 Introduction to Microcontrollers 3.13.1.1 Comparison of Microprocessors and Microcontrollers 3.13.1.2 Functiona Building Blocks of a Microcontroller 3.1
3.2 Hardware Architecture and Pinouts 3.23.2.1 Pins and Signals of 8051 3.23.2.2 Architecture of 8051 3.63.2.3 Programming Model of 8051 3.93.2.4 Special Function Registers (SFR) of 8051 3.10
3.3 Memory Organization 3.16
3.4 IO Ports and Data Transfer Concepts 3.18
3.5 Machine Cycles and Timing Diagram 3.213.5.1 External Program Memory Fetch Cycle 3.223.5.2 External Data Memory Read Cycle 3.233.5.3 External Data Memory Write Cycle 3.243.5.4 Port Operation Cycle 3.253.5.5 Timing Diagram of 8051 Instructions 3.253.5.6 Timing Diagram of MOVX A,@DPTR 3.27
3.6 Interrupts in 8051 3.28
3.7 Instruction Set 3.29
xii Microprocessors and Microcontrollers
3.8 Addressing Modes 3.30
3.9 Data Transfer Instructions 3.31
3.10 Data Manipulation Instructions 3.353.10.1 Arithmetic Instructions 3.353.10.2 Logical Instructions 3.37
3.11 Control Instructions 3.403.11.1 Program Branching Instructions 3.413.11.2 Boolean Instructions 3.44
3.12 IO Instructions 3.46
3.13 Comparison of 8085 and 8051 Assembly Language Programming 3.47
3.14 Short-Answer Questions 3.47
3.15 Exercises 3.51
CHAPTER 4: Peripheral Interfacing 4.1–4.76
4.1 Introduction 4.1
4.2 Programmable Peripheral Interface - INTEL 8255 4.14.2.1 Interfacing of 8255 with 8085 Processsor 4.44.2.2 Interfacing of 8255 with 8051 Microcontroller 4.54.2.3 Programming (or Initializing) 8255 4.6
4.3 Programmable Interrupt Controller - INTEL 8259 4.104.3.1 Interfacing 8259 with 8085 Microprocesssor 4.104.3.2 Functional Block Diagram of 8259 4.124.3.3 Processing of Interrupts by an 8259 4.134.3.4 Programming (or Initializing) 8259 4.15
4.4 Programmable Timer - INTEL 8254 4.20 4.4.1 Interfacing 8254 with 8085 Processor 4.224.4.2 Programming 8254 4.234.4.3 Operating Modes of 8254 4.25
4.5 Keyboard/Display Controller - INTEL 8279 4.314.5.1 Block diagram of 8279 4.324.5.2 Programming the 8279 4.344.5.3 Keyboard and Display Interface using 8279 4.364.5.4 Interfacing 8279 with 8085 Processor 4.364.5.5 Interfacing 8279 with 8051 Microcontroller 4.39
4.6 DAC Interface 4.404.6.1 DAC0800 4.424.6.2 Interfacing DAC0800 with 8085 4.44
Contents xiii
4.6.3 Interfacing DAC0800 with 8051 Microcontroller 4.454.6.4 Programming the DAC Interfaced (DAC0800) with 8051 4.47
4.7 ADC Interface 4.564.7.1 ADC0809 4.574.7.2 Interfacing ADC0809 with 8085 Microprocessor 4.614.7.3 Interfacing ADC0809 with 8051 Microcontroller 4.624.7.4 Programming the ADC Interfaced (ADC 0809) with 8051 4.64
4.8 Short-Answer Questions 4.66
4.9 Exercises 4.72
CHAPTER 5: Microcontroller Programming and Applications 5.1–5.84
5.1 Simple Programming Exercises 5.1
5.2 Programming 8051 Timers 5.305.2.1 Timer Mode Control (TMOD) Register 5.305.2.2 Timer Control (TCON) Register 5.325.2.3 Calculating the Time Delay 5.335.2.4 Examples of Timer Programming in the 8051 Controller 5.34
5.3 Serial Port Programming 5.375.3.1 Serial Data Buffer (SBUF) Register 5.385.3.2 Power Control Register (PCON) 5.385.3.3 serial Port Control Register (SCON) 5.385.3.4 Baud Rate in 8051 5.405.3.5 Examples of Serial Port Programming in 8051 Controller 5.41
5.4 Interrupt Programming 5.445.4.1 Interrupts in 8051 5.445.4.2 Interrupt Enable (IE) Register 5.455.4.3 Interrupt Priority (IP) Register 5.455.4.4 Handling Interrupts of 8051 5.465.4.5 Examples of Interrupt Programming in 8051 Controller 5.47
5.5 Keyboard Interfacing in 8051 Controller 5.525.5.1 Keyboard Interfacing Using Ports of 8051 5.52
5.6 Display Interfacing with the 8051 Microcontroller 5.565.6.1 Example Program for LCD Display 5.56
5.7 System Design Using the 8051 Microcontroller 5.60
5.8 Servo Motor 5.625.8.1 Control of Servo Motor 5.62
5.9 Stepper Motor Control using the 8051 Microcontroller 5.695.9.1 Example Program for Stepper Motor Control 5.70
xiv Microprocessors and Microcontrollers
5.10 Application to Automation Systems 5.735.10.1 Sensor Interface in 8051 for Automation System 5.745.10.2 Temperature Control System with the 8051 Microcontroller 5.76
5.11 Short-Answers Questions 5.79
5.12 Exercises 5.81
APPENDICES A1–A10
APPENDIX I List of Microprocessor Released by INTEL A.1
APPENDIX II 8051 Instructions in Hexadecimal Order A.3
APPENDIX III 8051 Instruction in Alphabetical Order A.5
APPENDIX IV 8085 Instructions in Hexadecimal Order A.7
APPENDIX V 8085 Instructions in Alphabetical Order A.9
ANNA UNIVERSITY QUESTION PAPER Q1–Q4
GENERAL INDEX I.1–I.5
CHIP INDEX I.6
LIST OF ABBREVIATIONS
Abbreviations
ADC - Analog to Digital Converter
AF - Auxiliary carry Flag
ALE - Address Latch Enable
ALU - Arithmetic Logic Unit
ASCII - American Standard Code for Informa-tion Interchange
BCD - Binary Coded decimal
CF - Carry Flag
CMOS - Complementary Metal Oxide Semicon-ductor
CPU - Central Processing Unit
CRT - Cathode Ray Tube
DAC - Digital to Analog Converter
DIP - Dual In-line Package
DMA - Direct Memory Access
DRAM - Dynamic Random Access Memory
EEPROM - Electrically Erasable Programmable Read Only Memory
EOI - End of Interrupt
EPROM - Erasable-Programmable Read Only Memory
FIFO - First In First Out
HMOS - High density Metal Oxide Semiconduc-tor
IC - Integrated Circuit
IO - Input-Output
IP - Instruction Pointer
IR - Instruction Register
IRR - Interrupt Request Register
ISP - In-System Programmable
ISR - Interrupt Service Routine/In-Service Register
ISS - Interrupt Service Subroutine
LCD - Liquid Crystal Display
LDT - Local Descriptor Table
LED - Light Emitting Diode
LIFO - Last In First Out
LRU - Least Recently Used
LSB - Least Significant Byte
LW - Lower Word
MSB - Most Significant Byte
MSW - Machine Status Word
NDRO - Non-Destructive Read Out Memory
NMI - Non Maskable Interrupt
NMOS - N-type Metal Oxide Semiconductor
NVRAM - Non Volatile Random Access Memory
OCW - Operational Common Word
OF - Overflow Flag
PC - Program Counter/ Personal Computer
PCB - Printed Circuit Board
PF - Parity Flag
PGA - Pin Grid Array
PMOS - P-type Metal Oxide Semiconductor
PROM - Programmable Read Only Memory
PS - Priority Resolver
PSW - Program Status Word
PWM - Pulse Width Modulation
RAM - Random Access Memory
RI - Receive Interrupt
SEC - Single Edge Connector
SF - Sign Flag
SFR - Special Function Registers
SI - Source Index
SIMD - Single Instruction Multiple Data
SP - Stack Pointer
SPP - Speed Power Product
xvi Microprocessors and Microcontrollers
TI - Transmit Interrupt
TLB - Translation Look Aside Buffer
TTL - Transistor Transistor Logic
UART - Universal Asynchronous Receiver Trans-mitter
USART - Universal Synchronous AsynchronousReceiver Transmitter
UV - Ultra Violet
VLSI - Very Large Scale Integration
WDT - Watchdog Timer
ZF - Zero Flag
Symbols
& - Logical AND
| - Logical OR
^ - Logical Exclusive OR
~ - Logical NOT
$ - Denote the end of a String