8051 m · pdf file... single-chip and easy to program. a microcontroller contains data and...

16

Upload: dangminh

Post on 16-Mar-2018

231 views

Category:

Documents


3 download

TRANSCRIPT

8051 Microcontroller

eMbeded SySteM deSign and PlcS

An ISO 9001:2008 CertIfIed COmpAny

Vayu education of india2/25, Ansari Road, Darya Ganj, New Delhi-110 002

arun ranaAssistant Professor

Department of Electronics & communication EngineeringDoon Valley Institute of Engineering & Technology

Karnal, Haryana

First Edition

8051 Microcontroller Embeded System Design and PLCs

Copyright ©VAYU EDUCATION OF INDIA

ISBN: 978-93-82174-14-1

First Edition: 2013

290/-

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the Author and Publisher.

Printed & bound in India

Published by:

An ISO 9001:2008 CertIfIed COmpAnyVAYU EDUCATION OF INDIA2/25, Ansari Road, Darya Ganj, New Delhi-110 002Ph.: 91-11-43526600, 41564445Fax: 91-11-41564440E-mail: [email protected], [email protected]: www.veiindia.com

Computers now form an integral part of most real-time control systems.With the advent of the microprocessors and microcontrollers in the last few decades the use of computers

in control applications has been ever growing. Microcontrollers are single-chip computers which can be used to control real-time systems. Such controllers are also referred to as embedded real-time computers. These devices are low-cost, single-chip and easy to program.

A microcontroller contains data and program memory, serial and parallel I/O, timers, and external and internal interrupts-all integrated into a single chip that can be purchased for as little as two dollars. About 40 percent of all microcontroller applications are found in office equipment, such as PCs, laser printers, fax machines, and intelligent telephones. About one third of all microcontrollers are found in consumer electronic goods. Products like CD players, hi-fi equipment, video games, washing machines, and cookers fall into this category. The communications market, the automotive market, and the military share the rest of the applications.

A programmable logic controller (PLC) or programmable controller is a digital computer used for automation of electromechanical processes,such as control of machinery on factory assembly lines, amusement rides, or lighting fixtures. PLCs are used in many industries and machines. Unlike general-purpose computers, the PLC is designed for multiple inputs and output arrangements, extended temperature ranges, immunity to electrical noise, and resistance to vibration and impact.

This book is written for advanced students, for practicing engineers, and for hobbyists who want to learn more about the programming and applications of 8051 microcontroller & PLCs. Knowledge of the Assembly programming language will be useful, and familiarity with at least one member of the 8051 microcontroller will be an advantage.

Chapter 1: presents the basic features of microcontrollers, Microcontroller architectures Microcontroller packaging and appearance, criteria in Choosing a Microcontroller , Microcontrollers versus Microprocessors,Application of microcontrollers

Chapter 2: reviews the Pinout Description 8051,block diagram of 8051, Oscillator Characteristics, TIMER/COUNTER,SFR,Interrupt

Chapter 3: reviews the 8051 instruction set, Addressing modes,Writing assembly language programming,Lookup tables.

Chapter 4: reviews the Interfacing of LEDs,Keyboard,LCD,ADCs & DACs.Chapter 5: reviews the basic idea of 8051 projects.Chapter 6: reviews the introduction of PLCs,working of PLCs,application of PLCs. Chapter 7: introduction of emsdded system and application

– Arun Rana

Preface

Acknowledgement

God is omnipotent, omnipresent and omniscient. I bow before him for showing his blessing on me. The present book is an outcome of blessing of god and the good wishes of my

parents, colleagues and friends.I express my deepest gratitude to my father Sh. Mahender Singh Rana and Brother Ajay

Singh Rana for motivating me at all the stages while writing this book.I am indebted to Dr. Rajesh Malik ,HOD of ECE dept. in NC College, Israna, Dr. J.P.Chauhan,

Dr. N.K. Batra, Dr. Jagdish Chaudhary, Dr. K.K. Saini, Dr. A.K.Garg, Dr. Sharad Sharma, Dr. Ashish Chopra, Dr. Paras Chawala & Dr. Vinit Singla, for their kind co-operation and motivation for writing this book.

I would like to extend my thanks to Dr. Mohit Agarwal, Project Director of DIET, for bringing out this book in such an excellent form.

I would like to thanks to Dr. Rajeev Jain, Mr.Vijay Saini, Publisher of this book (VAYU EDUCATION OF INDIA), who Complete my dream Nicely.

I also would like to thanks to Mr. Rajeev Gaba, Librarian Of DIET, Karnal, who give me direction to make book useful for the students.

I express my gratefulness and appreciation to Er. Prabhdeep singh, Er. Ravinder Singh Bisht, Er. Sumit Rana, Er. Sanjeev Ohiman, Er. B.S. Saini, Er. Neha, Er. Satish, Er. Gorav, Er. Hitesh, Er. Gagan, Er. Dhurv, Er. Rajeev Kamboj,Er. Gurudev Sir,Er. Balvindr Singh, Mr. Susil Chauhan,Er. Swati Mittal, Er. Nidhi Mittal, Er. Nidhi Uppal, Er. Gitika Dua, Er. Dipti Chaudhary, Er. Ritu Chabra, Vijay Saini and All academic colleagues who gave me valuable suggestion during the course of preparation of this book.

Suggestions and comments for further improvement of the book will be gratefully acknowleged

– Arun Rana

Contents

1. INTRODUCTION .......................................................................................................1

1.1 Microcontroller systems ................................................................................................1

1.2 Microcontroller Memory ...............................................................................................2

1.3 Microcontroller Features ...............................................................................................3

1.4 Microcontroller Architectures ......................................................................................8

1.5 Microcontroller Packaging and Appearance .................................................................9

1.6 criteria in Choosing a Microcontroller .......................................................................10

1.7 Microcontrollers Versus Microprocessors ...................................................................11

1.8 Application of Microcontrollers .................................................................................12

1.9 Survey of Microcontroller ...........................................................................................15

1.11 Versions of 8051 ..........................................................................................................18

1.12 Technological Trends in Microcontrollers Development ..........................................19

Questions ....................................................................................................................19

2. 8051 ARChITECTURE ...........................................................................................21

2.1 Introduction .................................................................................................................21

2.2 Pinout Description .......................................................................................................21

2.3 Block Diagram of 8051 ...............................................................................................23

2.4 Internal RAM And ROM .............................................................................................31

2.5 What Are SFRs? .........................................................................................................33

2.6 Input/Output Ports (I/O Ports) .....................................................................................38

x 8051 Microcontroller, Embedded System Design and PLCs

2.7 External Memory Connection ....................................................................................42

2.8 Stack Pointer ...............................................................................................................44

2.8 Oscillator .....................................................................................................................45

2.9 Clock ...........................................................................................................................47

2.10 Timer/Counter .............................................................................................................49

2.11 Interrupt .......................................................................................................................60

2.12 Reset ............................................................................................................................68

2.13 Serial Communication .................................................................................................69

2.14 Reset Sources ..............................................................................................................76

2.15 Introduction of Program Memory ...............................................................................78

2.16 Expanding I/O .............................................................................................................81

2.17 Memory Mapped I/O ...................................................................................................84

Questions ....................................................................................................................85

3. 8051 INSTRUCTION SET AND PROGRAMMING ............................................89

3.1 Assembly Language ....................................................................................................89

3.2 Writing Assembly Language Program ........................................................................89

3.3 Elements of Assembly Language ................................................................................90

3.4 Syntax of Assembly Language ....................................................................................90

3.5 Assembly Language Programming Example ..............................................................96

3.6 Addressing Modes .....................................................................................................114

3.7 Lookup Table .............................................................................................................116

3.8 Arithmetic Operations ...............................................................................................117

3.9 Logical Operations ....................................................................................................119

3.10 Data Transfer Inst ......................................................................................................121

3.11 Boolean Variable Instructions ...................................................................................124

3.12 Program Branching Instruction .................................................................................128

3.13 Time Delays ..............................................................................................................132

xiContents

3.14 Software Polled Timer ...............................................................................................133

3.15 Serial Data Transmission ...........................................................................................136

Questions ..................................................................................................................138

4. 8051 aPPlicationS ....................................................................................................142

4.1 Keyboards ..................................................................................................................142

4.2 Displays .....................................................................................................................151

4.3 Interfacing an LCD to the 8051 Microcontroller ......................................................155

4.4 Serial Communication ..............................................................................................170

4.5 Analog To Digital Converter (ADC0809) ................................................................181

4.6 Interfacing DAC to 8051 ...........................................................................................185

Questions ..................................................................................................................190

5. BASIC IDEA OF 8051 PROjECTS ......................................................................192

5.1 Pick And Place Robot ...............................................................................................192

5.2 Automatic Car Parking Indicator Using Microcontroller Description ......................195

5.3 Level Computing and Storage Device ......................................................................196

5.4 Person counter and Password Detector ....................................................................198

5.5 Temperature & Light Monitoring and Controlling....................................................199

5.6 Electronic Voting Machine .......................................................................................200

5.7 Rolling display using Matrix LEDs .........................................................................201

5.8 Remote Surveillance Vehicle Using AVR AT Mega16 .............................................202

5.9 Controller Area Network ...........................................................................................203

5.10 Water Spy - A Submarine Robot ...............................................................................204

5.11 Greenhouse Robot .....................................................................................................210

5.12 Landrover Robot Operated by Cellphone ................................................................211

5.13 Password Based Door Locking .................................................................................212

5.14 Automatic Room light Controller with Visitor Counter ...........................................213

5.15 Automatic Bell For Colleges ....................................................................................214

xii 8051 Microcontroller, Embedded System Design and PLCs

5.16 Microcontroller Based Data Logger ..........................................................................215

5.17 Other Useful Project for Student ...............................................................................217

Questions ..................................................................................................................223

6. PLC hISTORY ........................................................................................................224

6.1 PLC History ...............................................................................................................224

6.2 The Guts Inside .........................................................................................................225

6.3 PLC Operation ...........................................................................................................226

6.4 Response Time ..........................................................................................................227

6.5 Response Time Concerns ..........................................................................................227

6.6 Relays ........................................................................................................................229

6.7 Replacing Relays .......................................................................................................230

6.8 Basic Instructions ......................................................................................................231

6.9 PLC Registers ............................................................................................................234

6.10 A Level Application ..................................................................................................235

6.11 The Program Scan .....................................................................................................236

6.12 Latch Instructions ......................................................................................................237

6.13 Counters ....................................................................................................................239

6.14 Timers ........................................................................................................................242

6.15 Timer Accuracy .........................................................................................................244

6.16 One-shots ...................................................................................................................246

6.17 Master Controls .........................................................................................................247

6.18 Shift Registers ...........................................................................................................250

6.19 Getting and Moving Data ..........................................................................................253

6.20 Math Instructions .......................................................................................................256

6.21 Boolean Math ............................................................................................................259

6.22 DC Inputs ..................................................................................................................261

6.23 AC Inputs ..................................................................................................................263

xiiiContents

6.24 Relay Outputs ............................................................................................................265

4.25 Transistor Outputs .....................................................................................................267

6.26 Using RS-232 with Ladder Logic .............................................................................269

Questions ...................................................................................................................271

7. EMBEDDED SYSTEM DESIGN ..........................................................................271

7.1 Introduction ...............................................................................................................271

7.2 Embedded Versus External Memory Devices ...........................................................275

7.3 Microcontroller Features ...........................................................................................276

7.4 Microcontroller and Embedded Processors ...............................................................280

7.5 Basic of PIC Microcontrollers ...................................................................................284

7.6 Architecture and Pipelining .......................................................................................286

7.7 Program Memory Consideration ...............................................................................289

7.8 Addressing Modes .....................................................................................................293

7.9 CPU Registers ...........................................................................................................297

7.10 Instruction Set ...........................................................................................................300

7.11 Embedded System Design Program ..........................................................................306

Questions ..................................................................................................................332

Appendix ...................................................................................................................333

Glossary ....................................................................................................................431

Index .........................................................................................................................435

1.1 Microcontroller systeMsMicrocontrollers are general purpose microprocessors which have additional parts that allow them to control external devices. Basically, a microcontroller executes a user program which is loaded in its program memory. Under the control of this program, data is received from external devices (inputs), manipulated and then data is sent to external output devices. A microcontroller is a very powerful tool that allows a designer to create sophisticated I/O data manipulation algorithms. Microcontrollers are classified by the number of bits in a data word. 8-bit microcontrollers are the most popular ones and are used in many applications. 16-bit and 32-bit microcontrollers are much more powerful, but usually more expensive and not required in many small to medium general purpose applications where microcontrollers are used. The simplest microcontroller architecture consists of a microprocessor, memory, and I/O as shown in fig.1.1. The microprocessor consists of a central processing unit (CPU) and the control unit (CU). The CPU is the brain of a microprocessor and is where all of the arithmetic and logical operations are performed.

Fig. 1.1

The control unit controls the internal operations of the microprocessor and sends out control

IntroductIon

Chapter - 1

2 8051 Microcontroller, Embedded System Design and PLCs

signals to other parts of the microprocessor to carry out the required instructions.

1.2 Microcontroller MeMoryMemory is an important part of a microcomputer system. Depending upon the application, we can classify memories into two groups: program memory and data memory. Program memory stores all the program code and this memory is usually non-volatile, i.e. data is not lost after the removal of power. Data memory is where the temporary user data is stored during the various arithmetic and logical operations. Data memories are usually volatile. Simplified model of memory unit is shown in Fig. 1.2.

Fig. 1.2

There are basically five types of memories as summarized below:

1.2.1 rAMRAM means Random Access Memory. It is a general purpose memory which usually stores user data. RAM is volatile, i.e. data is lost after the removal of power. Most microcontrollers have some amount of internal RAM. Generally, 256 bytes is a common amount, although some microcontrollers have more, some less.

1.2.2 roMROM is Read Only Memory. This type of memory usually holds program or fixed user data. ROM memories are programmed at the factory and their contents cannot be changed by the user. ROM memories are only useful if you have developed a program and wish to order several thousands copies of it.

1.2.3 eProMEPROM is Erasable Programmable Read Only Memory. This is similar to ROM but the EPROM

3Introduction

can be programmed using a suitable programming device. EPROM memories have a small clear window on the chip where the data can be erased under an UV light. Many development versions of microcontrollers are manufactured with EPROM memories where the user program is usually stored. These memories are erased and re-programmed until the user is satisfied with the program. Some versions of EPROMs, known as OTP (One Time Programmable), can be programmed using a suitable programmer device but these memories cannot be erased. OTP memories cost much less than the EPROMs. OTP is useful after a project has been developed completely and it is required to make hundreds of copies of the program memory. Most microcontrollers have some amount of built-in EPROM. 2k bytes is a typical capacity, although some may have more and some less.

1.2.4 eeProMEEPROM is Electrically Erasable Programmable Read Only Memory. These memories can be erased and also be programmed under program control. EEPROMs are used to save configuration information, maximum and minimum values, identification data etc. Some microcontrollers have built-in EEPROM memories (e.g. PIC16F84 contains a 64-byte EEPROM memory where each byte can be programmed and erased directly by software). EEPROM memories are usually very slow compared to other types of semiconductor memories.

1.2.5 Flash eeProMThis is another version of EEPROM type memory. This type of memory is becoming popular recently and is used in many microcontrollers to store the program data. The data on a Flash EEPROM is erased and then re-programmed using a programming device. The entire contents of the memory should be erased and then re-programmed. Flash EEPROMs are usually very fast. One important distinction between a microcontroller and a microprocessor is that a microcontroller has special hardware in the form of input/output (I/O) ports for dealing with the outside world. I/O ports allow external signals and devices to be connected to the microcontroller. These ports are usually organized into groups of 8 bits and each group is given a name. For example, the PIC16F84 microcontroller contains two I/O ports named port A and port B. It is very common to have at least 8 I/O lines. Some microcontrollers have 32 or even 96 I/O lines, while some others may have only 6. On most microcontrollers the direction of the I/O port lines is programmable so that different bits can be programmed as inputs or outputs. Some microcontrollers provide bidirectional I/O ports where each port line can be used as either input or output. Some microcontrollers have “open-drain” outputs where the output transistors are left floating. External pull-up resistors are normally used with such output port lines.

1.3 Microcontroller FeAturesMicrocontrollers from different manufacturers have different architectures and different capabilities. Some may suit to a particular application while some others may be totally unsuitable. The hardware features of microcontrollers in general are described in this section.

1.3.1 supply VoltageMost microcontrollers operate with the standard +5 V supply. Some microcontrollers can operate at as low as +2.7 V and some will tolerate +6 V without any problems. You should check the

8051 Microcontroller Embedded SystemDesign and PLCs

Publisher : Vayu Education ISBN : 9789382174141 Author : Arun Rana

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

Get this eBook