microcontrollers and embedded systems · this chapter also covers the addressing modes supported by...

16

Upload: others

Post on 08-May-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions
Page 2: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

Microcontrollers and Embedded Systems

(For B. TECH, BE, M.TECH)

(Electronics and Communication Engineering,

Electronics and Computer Science)

Page 3: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

SOME OTHER BOOKS OF RELATED INTERESTWeb Technologies: A Systematic ApproachFirst Edition

Dr. Archana Kumar

ISBN: 81-85044-73-2

Introduction to Computers & Programming in C

Second Revised Edition

Dr. Archana Kumar

ISBN: 81-85044-65-1

Microprocessor: Programming & InterfacingFirst Edition

Dinesh Chaudhary

ISBN:81-85044-72-4

Digital Electronics (Theory with Experiments)First Edition

Anurag Arora

ISBN: 81-85044-89-9-3

Database Management SystemsFirst Edition

Sandeep Negi, Esha Saxena

ISBN: 81-85044-93-7

A Text Book on Laser Systems and ApplicationsFirst Edition

Dr. S.C. Gupta

ISBN: 81-85044-98-8

An Introduction to Electronics EngineeringFirst Edition

Dr. S.C. Gupta

ISBN: 81-85044-99-6

A Text Book of Operating SystemsFirst Edition

Gurjeet Singh, Neha Dutta, Sunny Thukral

ISBN: 81-85044-91-0

Page 4: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

MICROCONTROLLERS ANDEMBEDDED SYSTEMS

ANURAG ARORA

Department of Electronics and Communication

KIIT College of Engineering Gurgaon

Foreword by

PROF (DR.) SUNIL KUMAR GARG

Jt. Director

Savera Group of Institutions

Faruknagar (Gurgaon)

UDH Publishers & Distributors Pvt. Ltd.New Delhi-110002

Edited by

PROF. A.K. DUBEY

Department of ECE/EE

J B Knowledge Park Faridabad

Foreword by

PROF (DR.) N K AGARWAL

Former Scientist/Engineer-H

Vikram Sarabhai Space Centre

Indian Space Research Organisation

Trivandrum

Page 5: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

Information contained in this work has been obtained by UDH Publishers & Distributors (P) Ltd.

from sources believed to be reliable. However, neither UDH Publishers & Distributors (P) Ltd. nor

its authors guarantee the accuracy or completeness of any information published herein, and neither

UDH Publishers & Distributors (P) Ltd. nor its authors shall be responsible for any errors, omissions,

or damages arising out of use of this information. This work is published with the understanding

that UDH Publishers & Distributors (P) Ltd. and its author is supplying information but are not

attempting to render engineering or other professional services. If such services are required, the

assistance of an appropriate professional should be sought.

UDH Publishers & Distributors (P) Ltd.

2/27, Ansari Road, Darya Ganj, New Delhi - 110002

Phones: 43489013, 43489014, Fax: 41524591

4762-63/23, Ansari Road, Darya Ganj, New Delhi - 110002

Phones: 41562623, 41562603, Fax: 23256533

E-mail: [email protected] / [email protected]

Website: www.udhbooks.com

Price : `̀̀̀ 250/-

First Edition 2012

ISBN: 81-85044-71-6

© 2012 All Rights Reserved with Publisher

No part of this publication which is material protected by this copyright notice may be reproduced

or transmitted or utilized or stored in any form or by any means now known or hereinaffer invented,

electronic, digital or mechanical, including photocopying, scanning, recording or by any information

storage or retrieval system, without prior written permission from the publisher.

Information contained in this book has been published by K.K. Thukral for UDH Publishers &

Distributors (P) Ltd. and has been obtained by its author from sources believed to be reliable and

are correct to the best of their knowledge. However, the publisher and its author shall in no event

be liable for any errors, omissions or damages arising out of use of this information and specifically

disclaim any implied warranties or merchantability or fitness for any particular use.

Laser typeset by MS COMPUTERS, Patparganj, Delhi - 110092

Printed at Harsha Process

Page 6: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

Dedicated toDedicated toDedicated toDedicated toMy Parents

Sh. Bhavesh Arora

Smt. Harsh Arora

Page 7: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

FOREWORD

Due credit goes to the author for his commendable work in writing this book on "Microcontrollers and

Embedded systems".

The author has used his wide experience in preparing the manuscript to enable the reader understand the

concepts of Microcontrollers and Embedded systems in the simplest manner. This book would really allow

technocrats to use microcontroller for various applications in industry.

This book has covered 8051, PIC, 8096, Motorola microcontrollers, their architecture and peripheral support

in detail. Numerous programs have been provided for the readers to build their own applications. The content

of the book are well organized and written in a simple language.

I hope that all the readers i.e. hobbyists, undergraduate and PG students and professionals will have immense

interest in acquiring knowledge through this book.

Prof (Dr.) Sunil Kumar Garg

Jt. Director

Savera Group of Institutions

Faruknagar (Gurgaon)

FOREWORD

It is my pleasant privilege to write a foreword for this book "Microcontrollers and Embedded systems"

authored by Anurag Arora.

Microcontrollers are a tool for computing and communication. Knowledge of Microcontrollers and Embedded

systems are meaningful and very rewarding if it is applied to design a product that is useful in the industry

or for the society in general.

There has been an increase in the demand for a suitable textbook on "Microcontrollers and Embedded

systems". The level of presentation is suitable for self study. This book covers the complete new scheme

syllabus of MDU,UPTech and KU.

I believe that this book will serve as a useful text for the subject "Microcontrollers and Embedded systems"

in the undergraduate courses and as a ready reference for the course at postgraduate level.

Prof (Dr.) N K Agarwal

Former Scientist/Engineer-H

Vikram Sarabhai Space Centre

Indian Space Research Organisation

Trivandrum

2012

2012

Page 8: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

PREFACE

In this book, microcontrollers and their applications are mainly focused and targeted towards the automation of

industrial machines and processes. For studying their use, normally a short classroom work followed by

laboratory practice lasting for a semester is sufficient. At the beginning studying only one microcontroller is

good enough. However as one progresses, practice on more than one microcontroller will be required.

Considering these needs many practical examples with different microcontrollers are covered in this book. The

text can serve as a source and learning module for the undergraduate students of instrumentation, electronics

and computer engineering. Further, it will also be helpful for practicing engineers working in the field of

microcontrollers and design applications using these.

The potential applications of microcontrollers in the industry attracted the author towards the subject.

Microcontroller must be treated as a tool for computing and communication; knowledge of microcontrollers is

meaningful and very rewarding if it is applied to design a product that is useful in the industry or for the society

in general. This is a subject which has direct relevance to industrial product development and automation. This

inspired the author to write this book.

As we start journey into the world of Embedded System, lets consider number of embedded system we are

surrounded with in our daily life like mobile phone, microwave oven, set top box, smart cards, digital camera,

watches. Air conditioner and so on. Many of us do not know that these devices contain a processor with a lot

of software embedded. These embedded systems are focused to do a specific job.

With the advent of industrial automation embedded systems have been around in fields like

telecommunications, banking, health care, automobile semiconductor electronics, defence etc. in embedded

system. Recently breath taking development were seen, For example in microelectronics, processor speeds are

increasing tremendously and memory costs are dropping rapidly. Now we can make Embedded System Network

enabled and connect them to the Internet or corporate Intranet. This feature enhances utility of Embedded

System.

Revolutionary developments are also taking place in area of mobile devices. No longer its just a voice

communication device. It is also now used for accessing data, voice and video services using 3G (Third

Generation) Wireless Networks. Anytime anywhere communication for data, voice and video applications is

now a reality thanks to the power of Embedded software in mobile devices.

With the availability of tools operating system that occupy very small memory which facilitate fast

development and easy debugging. Tools are useful for testing the software before putting it in Embedded

system.

Last but not least still we have the challenges for Embedded software programmer to develop cost effective,

reliable embedded software and minimal development time. In addition the product should be delivered in the

market just in time.

—ANURAG ARORA

[email protected]

2012

Page 9: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

ABOUT THE BOOK

This book has been written in a very different fashion with specific objectives. Firstly, it covers both CISC and

RISC processors. Secondly, it will be useful for both students and practicing engineers. Further, it will be useful

for the beginners as well as experts or designers who are using microcontrollers. For the beginners it serves as

a learning module whereas for the practitioners it serves as a practical guide. Coverage of more than one

microcontroller is another unique feature of this book. This text considers MCS-51 as a starting point. It also

covers the popular PIC microcontrollers from Microchip which use the RISC architecture. Interfacing and

several industrial applications of microcontrollers is another salient feature of the book

The book is organized into 9 chapters:

Chapter 1: It covers the complete introduction to microcontrollers, their potential in industrial applications

and the history of microcontrollers. Concepts such as the CISC and RISC processors, embedded and external

memory devices are covered. A brief idea about the available microcontrollers from Intel and Microchip and is

given for the purpose of comparison.

Chapter 2: Is mainly targeted towards learning MCS-51 products. Their architectural features along with

registers, Pin diagram, basic connections and memory organization are covered in this chapter. I/O port structure

is also discussed in this chapter. Emphasis is laid on the hardware aspect of the 8051 microcontroller.

This chapter also covers the addressing modes supported by MCS-51.

Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions of writing simple programs.

Operations with registers, stack memory, etc. are discussed initiating programming the 8051 microcontroller.

Chapter 4: The programming aspects of 8051 microcontrollers are covered in this chapter 4 is also devoted to

the interrupt, timer counting and serial communication facilities supported by 8051. Hardware aspects and

several programming examples are the major highlights of this chapter.

Chapter 5: Interfacing and design applications are covered. This is to penetrate the design issues in general.

Therefore, interfacing data input and presentation devices are the issues discussed in this chapter and LCD,

keyboard, ADC appliations are focused. The whole idea is to emphasise the hardware interfacing and

programming issues of all MCS-51 microcontrollers.

Chapter 6: Describe the programmable interface controller and its family in detail with SPI and I2C mode.

Chapter 7: Presents the basic concepts of embedded systems and reviews trends in embedded software

development and the issues in developing embedded software.

It also provides the introduction of operating system types of embedded operating systems.

It also discuss the issue involved in embedded software development. The focus is on the process of

embedded software development, comparing and contrasting the application software development with

embedded software development.

It also presents the case study of embedded system. It’s also described the hardware and software

languages used for embedded system.

Chapte 8: Discuss about PPI and its interfacing with microprocessor.

Chapter 9: Discuss about Intel 8096 and MC68HC11 microcontroller.

Page 10: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

ACKNOWLEDGMENT

I deeply express my heartful thanks to Chief executive officer Dr. Harsh Vardhan, Registrar Dr.

Neelima, Executive director Dr. S.S. Agrawal, Principal Dr. V.K. Syal, (HOD) Dr. NK Agarwal,

(HOD) Dr. Vikram Singh of KIIT college of Engineering and Prof(Dr) Sunil Kumar Garg (Jt.

Director) of Savera group of institutions for their valuable technical suggestions and constant

encouragement, without which this book would not have come into existence.

I am specially thankful to Prof. A.K.Dubey (J B Knowledge Park) for first proof reading of the

manuscript. I would like to express my sincere thanks to Mr.Om Prakash Singh (WIT college of

Engineering), Mr. Pawan (J B Knowledge Park) for their time to time, much needed valuable guidance.

Special thanks to all the students I have taught and interacted, whose probing and incisive questions

have only bettered my own understanding of my subject matter I also thank the entire editorial team of

UDH publishers & Distributors for the help and support they have provided during the preparation of

this book. Special thanks to Mr. K.K. Thukral who took a responsibility of publishing this book.

I would also like to express my deep gratitude to my parents who are always an encouragement for

me. I own a lot to them. My father Sh. Bavesh Arora and My Mother Smt.

Harsh Arora are always an inspiration for me who supported a lot to write this book. I would also like

to thank my loved ones Girish Saluja, Shweta Arora Saluja, Shipra, Shikha and Shivani who

played a vital role in the preparation of manuscript. Finally I would like to convey my special thanks to

my uncle Mr. Chander prakash Valecha, and my aunt Mrs. Asha Valecha who always kept me

motivated enough to be able to make this book a reality. Last but not the least I would also like to thank

my grand Mother Late Smt. Shanti devi who played a vital role in shaping my future.

—ANURAG ARORA

Page 11: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

SYLLABUS FOR MDUEE-312-F (MICROCONTROLLERS & EMBEDDED SYSTEMS)

SECTION A

INTRODUCTION OF MICROCONTROLLER: Different types of microcontrollers: Embedded microcontrollers,

External memory microcontrollers; Processor Architectures: Harvard V/S Princeton , CISC V/S RISC;

microcontrollers memory types; microcontrollers features: clocking, i/o pins, interrupts, timers, peripherals.

SECTION B

MICROCONTROLLER ARCHITECTURE: Introduction to PIC microcontrollers, Architecture and pipelining,

program memory considerations, Addressing modes, CPU registers, Instruction set, simple operations.

SECTION C

Microcontrollers - Microcontroller 8051- Architecture, Pin Diagram, I/O Ports, Internal RAM and Registers,

Interrupts, Addressing Modes, Memory Organization and External Addressing, Instruction Set, Assembly

Language Programming, Real Time Applications of MicrocontrollerInterfacing with LCD, ADC, DAC, Stepper

Motor, Key Board and Sensors.

SECTION D

Embedded Systems- Introduction, Classification, Processors, Hardware Units, Software Embedded into System,

Applications and Products of Embedded Systems, Structural Units in Processor, Memory Devices, I/O Devices,

Buses, Interfacing of Processor Memory and I/O Devices, Case Study of an Embedded System for a Smart

Card.

Page 12: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

SYLLABUS FOR UPTECHEIC-601 (MICROCONTROLLERS)

I. Introduction Microcontrollers and Embedded processors, Overview of the 8051, Inside the 8051,

Addressing modes,

II. Introduction to 8051 assembly programming, Assembling and running an 8051 program, The program

counter and ROM space in the 8051, 8051 data types and directives, 8051 flag bits and the PSW

register, 8051 register banks and stack, 8051 I/O programming, I/O bit manipulation programming.

III. Programming the 8051 timers, Counter programming, Basics of serial communications, 8051 connection

to RS-232, 8051 serial port programming assembly, 8051 interrupts, Programming timer interrupts,

programming external hardware interrupts, programming the Serial communication interrupts, Interrupts

priority in the 8051,

IV. Interfacing with 8051: Memory address decoding 8031/ 51 interfacing with external ROM, 8051 data

memory space, LCD, Keyboard, Parallel and Serial ADC, DAC interfacing, Sensor interfacing and

Signal Conditioning, Stepper motor and DC motor,

V. Programming the 8255 and Interfacing, Introduction to Intel 8096 and MC68HC11 microcontroller*.

Page 13: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions
Page 14: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

CONTENTS

Preface ........................................................................................................................................................... vii

Acknowledgment ............................................................................................................................................ ix

1. INTRODUCTION TO MICTROCONTROLLER ....................................................................... 1—23

1.1 Introduction ......................................................................................................................................... 1

1.2 Microcontroller versus general-purpose microprocessor ................................................................. 2

1.3 History of Microcontrollers and Mictroprocessors ........................................................................... 6

1.4 Types of Mictrocontrollers .................................................................................................................. 7

1.4.1 8-BIT and 16-BIT Mictrcontrollers ...................................................................................... 7

1.5 Embedded and External Memory Microcontrollers ............................................................................ 8

Embedded Microcontrollers ............................................................................................................... 8

External Memory Microcontrollers ..................................................................................................... 9

1.6 CISC and RISC Architecture Microcontrollers ................................................................................. 10

1.6.1 RISC Characteristics .......................................................................................................... 11

1.7 Harvard and Princeton Memory Architecture Microcontrollers ..................................................... 13

1.7.1 Harvard and Von-Neumann CPU detailed Architectures ................................................. 14

1.8 Examples of Popular Mictrocontrollers ............................................................................................. 15

1.8.1 8051, Extended 8051XA, and 8051 MX Families ............................................................... 15

1.8.2 MC68HC11/68HC12 Families ............................................................................................. 17

1.9 Mictrocontroller Features .................................................................................................................. 17

1.9.1 Power Source ...................................................................................................................... 17

1.9.2 Oscillator Circuit and Clocking Units ................................................................................ 18

1.9.3 System Timers and Real Time Clock ................................................................................. 18

1.9.4 Memory .............................................................................................................................. 18

1.9.5 Input, Output Ports ............................................................................................................ 18

1.9.6 Communication Interfaces ................................................................................................. 19

1.9.7 Interfacing Driver Circuits ................................................................................................. 19

1.9.8 Interrupt-Handler ............................................................................................................... 19

1.9.9 Processor ............................................................................................................................ 20

1.10 Microcontroller Necessary Features ................................................................................................. 20

REVIEW QUESTIONS ....................................................................................................................... 23

2. 8051 MICTROCONTROLLER ................................................................................................ 24—57

2.1 Introduction to Microcontroller ........................................................................................................ 24

2.2 Features of 8051 Microcontroller ..................................................................................................... 26

2.3 MCS-51 Architecture ......................................................................................................................... 28

2.4 Registers in MCS-51 .......................................................................................................................... 29

2.4.1 General-purpose or Working Registers ............................................................................. 30

2.4.2 Stack Pointer and Program Counter .................................................................................. 31

2.4.3 Special Function Registers (SFR) ...................................................................................... 32

Page 15: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

(xiv) Contents

2.5 Register banks in the 8051 ................................................................................................................. 35

2.6 Stack in the 8051 ................................................................................................................................ 37

2.6.1 Pushing Operation ............................................................................................................. 37

2.6.2 Popping from the stack ...................................................................................................... 39

2.6.3 The upper limit of the stack ............................................................................................... 39

2.6.4 CALL instruction and the stack ........................................................................................ 39

2.7 8051 Pin Description .......................................................................................................................... 40

2.8 Ports of 8051 ....................................................................................................................................... 41

2.9 Pin 9 (RST) ......................................................................................................................................... 42

2.10 Oscillator circuit of 8051 .................................................................................................................... 43

2.11 I/O port pins and their functions ..................................................................................................... 44

2.12 Memory organization ......................................................................................................................... 47

2.13 Addressing Modes ............................................................................................................................ 49

2.13.1 Immediate addressing mode .............................................................................................. 49

2.13.2 Register addressing mode ................................................................................................. 49

2.13.3 Direct addressing mode ..................................................................................................... 50

2.13.4 Register indirect addressing mode .................................................................................... 52

2.13.5 Indexed addressing mode and on-chip ROM access ....................................................... 53

2.14 Summary of 8051 Addresing modes .................................................................................................. 53

REVIEW QUESTIONS ....................................................................................................................... 56

3. 8051 INSTRUCTIONS .......................................................................................................... 58—116

3.1 Instructions set of 8051 ..................................................................................................................... 58

3.1.1 Arithmetic Instructions ...................................................................................................... 59

3.1.2 Branch Instructions ........................................................................................................... 60

3.1.2.1 Unconditional jump instructions ....................................................................................... 60

3.1.2.2 Conditional jump instruction ............................................................................................. 60

3.1.5 Boolean variable manipulation instructions ..................................................................... 64

3.2 Descriptions of all 8051 instructions ................................................................................................. 65

3.3 Instructions Set .................................................................................................................................. 68

3.4 Developing a Program in Embedded System .................................................................................. 114

3.4.1 Writing Program in Assembler ......................................................................................... 114

3.4.2 Compiling into Machine Code ......................................................................................... 114

3.4.3 Copy Program to a Microcontroller ................................................................................ 115

REVIEW QUESTIONS ..................................................................................................................... 116

4. ASSEMBLY LANGUAGE PROGRAMMING USING 8051 ................................................ 117—178

4.1 Timers of 8051 ................................................................................................................................. 126

4.1.1 Programming 8051 Timers ................................................................................................ 126

4.2 Mode 1 Programming ....................................................................................................................... 130

4.2.1 Generating a Large Time Delay ....................................................................................... 136

4.3 Mode 2 Programming ....................................................................................................................... 138

Page 16: Microcontrollers and Embedded Systems · This chapter also covers the addressing modes supported by MCS-51. Chapter 3: The MCS-51 instruction set prepares for using the MCS-51 instructions

Microcontrollers and Embedded SystemseBook

Publisher : UDH Publishers andDistributors ISBN : 8185044716 Author : Anurag Arora

Type the URL : http://www.kopykitab.com/product/1152

Get this eBook