You are on page 1of 11

Ajit Pal

Microcontrollers
Principles and Applications
+5 V
2K × 8

P2 8 bit dip
switch
8
Reset switch
Microcontroller
100E AT89S52
+5 V
+5 V 2.2K
10 uF RST P1(0-6) 7 Segment
& common anode
P3(0-6) LEDs
7×2
10K

22 pF 8
ADC
P0 0804
X1
XTAL SC
X2 P1.7
RD
22 pF Vin+
P3.7

Op-Amp
27K
+5 V
+12 V
47K 220 V
10K

D1
100K
2.2K

LM
35
1K
Heater
Microcontrollers
Microcontrollers
Principles and Applications

AJIT PAL
Professor
Department of Computer Science and Engineering
Indian Institute of Technology Kharagpur

New Delhi-110001
2011
MICROCONTROLLERS: Principles and Applications
Ajit Pal

© 2011 by PHI Learning Private Limited, New Delhi. All rights reserved. No part of this book may
be reproduced in any form, by mimeograph or any other means, without permission in writing from
the publisher.

ISBN-978-81-203-4392-4

The export rights of this book are vested solely with the publisher.

Published by Asoke K. Ghosh, PHI Learning Private Limited, M-97, Connaught Circus,
New Delhi-110001 and Printed by Raj Press, New Delhi-110012.
In the Loving Memory of
My Parents
Contents

Preface xv
Acknowledgements xvii
1. INTRODUCTION 1–17
Learning Objectives 1
1.1 Historical Background 2
1.2 Microprocessors versus Microcontrollers 5
1.3 Microcontroller Features 7
1.3.1 On-chip Oscillator 7
1.3.2 Large Number of Special-purpose Registers 7
1.3.3 Harvard Architecture 8
1.3.4 On-chip Program Memory 9
1.3.5 On-chip Data Memory 9
1.3.6 On-chip I/O Ports 9
1.3.7 Watchdog-Timer Reset 10
1.3.8 Powerful Interrupt Structure 11
1.3.9 Fast Context Switching 11
1.3.10 Built-in ADC 12
1.3.11 Built-in PWM 12
1.4 Educational Need 12
1.4.1 Hardware Design 13
1.4.2 Software Design 13
1.4.3 Hardware-Software Integration 14
1.5 Survey of Microcontrollers 14
1.6 Applications of Microcontrollers 16
Summary 16
Review Questions 17
Fill in the Blanks 17
Short Questions 17
vii
viii ● Contents

2. ARCHITECTURE OF THE INTEL 8051 18–38


Learning Objectives 18
2.1 On-chip Oscillator and CPU Timing 19
2.2 Memory Organization 21
2.3 Register Organization 22
2.4 Multifunction I/O Ports 24
2.5 ALU Capability of 8051 28
2.6 Reset Operation 31
2.6.1 Power-on Reset 31
2.7 Interrupt Structure 32
2.8 The 8051 Family 35
Summary 36
Review Questions 37
Fill in the Blanks 37
Short Questions 37

3. INSTRUCTION SET: VOCABULARY OF THE MACHINE 39–81


Learning Objectives 39
3.1 Data and Its Representation 41
3.2 Instruction Formats 44
3.2.1 Instruction Formats of 8051 47
3.3 Addressing Modes 48
3.3.1 Addressing Modes of 8051 56
3.4 Organization of the Instruction Set 59
3.4.1 Data Transfer Group 59
3.4.2 Logic Group 63
3.4.3 Arithmetic Group 66
3.4.4 Control Transfer Group 71
Summary 78
Review Questions 80
Fill in the Blanks 80
Short Questions 80

4. ASSEMBLY LANGUAGE PROGRAMMING 82–114


Learning Objectives 82
4.1 Software Design Steps 83
4.1.1 Problem Specification 83
4.1.2 Design 83
4.1.3 Coding 87
4.1.4 Testing and Debugging 88
4.1.5 Documentation and Maintenance 88
4.2 Why Assembly Language Programming? 88
4.3 Assembly Language Format 89
Contents ● ix

4.4 Simple Sequence Programs 91


4.4.1 Multi-byte Addition 91
4.4.2 Code Conversion 92
4.4.3 Binary to BCD Code Conversion 92
4.5 Program Looping 93
4.5.1 Multi-byte Addition 95
4.5.2 Checksum Byte Calculation 95
4.5.3 Delay Generation 96
4.5.4 Searching 99
4.5.5 Sorting 103
4.6 Subroutine Linkage 104
4.6.1 Parameter Passing Using Registers 107
4.6.2 Parameter Passing Using Memory 108
4.6.3 Parameter Passing Using Stack 109
4.7 Subroutine Call versus Interrupt 110
4.7.1 Software Interrupts 111
Summary 111
Review Questions 112
Fill in the Blanks 112
Short Questions 113

5. INTERFACING EXTERNAL MEMORY 115–142


Learning Objectives 115
5.1 Program Memories 116
5.1.1 Mask-programmable ROM 117
5.1.2 Programmable ROM 117
5.1.3 Electrically Programmable ROM 118
5.1.4 Electrically Erasable and Programmable ROM 119
5.1.5 Flash Memory 119
5.1.6 Non-volatile RAM 120
5.2 Data Memories 120
5.2.1 Static RAM 120
5.2.2 Dynamic RAM 121
5.3 Important Memory Characteristics 121
5.3.1 Electrical Characteristics 121
5.3.2 Memory Organization 121
5.3.3 Timing Characteristics 126
5.4 Interfacing External Memory to 8051 128
5.4.1 External Program Memory Address Space 129
5.4.2 External Data Memory Address Space 129
5.4.3 The System Bus 129
5.4.4 Interfacing of Program Memories 134
5.4.5 Interfacing of Data Memory 138
Summary 140
Review Questions 141
Fill in the Blanks 141
Short Questions 141
x ● Contents

6. DATA TRANSFER TECHNIQUES AND I/O PORTS 143–163


Learning Objectives 143
6.1 Data Transfer Techniques 144
6.1.1 Synchronous Mode 145
6.1.2 Asynchronous Mode 146
6.1.3 Interrupt-driven Mode 146
6.2 I/O Port 148
6.2.1 The 8255A Programmable Peripheral Interface (PPI) 149
6.2.2 Interfacing of 8255 to the Microcontroller 155
6.2.3 8051 I/O Port Progrmming 157
Summary 161
Review Questions 162
Fill in the Blanks 162
Short Questions 163

7. INTERFACING FOR HUMAN INTERACTION 164–200


Learning Objectives 164
7.1 Interfacing of DIP Switches 165
7.2 Keyboard 165
7.2.1 Interface Circuit 166
7.2.2 Interfacing Issues 168
7.2.3 Row-scanning Technique 170
7.2.4 Scanning by Hardware 175
7.3 Interfacing of Display Devices 176
7.3.1 Single LEDs 176
7.3.2 Bi-colour LEDs 179
7.3.3 Seven-segment LEDs 180
7.3.4 Interfacing Multiple Seven-segment LEDs 182
7.4 Liquid Crystal Displays 186
7.4.1 Multi-digit Seven-segment LCD Driver 187
7.4.2 Intelligent LCD Display Module 188
Summary 199
Review Questions 199
Fill in the Blanks 199
Short Questions 200

8. INTERFACING OF TRANSDUCERS, SENSORS AND ACTUATORS 201–248


Learning Objectives 201
8.1 Transducers 203
8.1.1 Temperature Transducers 204
8.1.2 Pressure and Displacement Transducers 206
8.1.3 Light Sensors 209
8.2 Signal Conditioning Circuits 210
8.3 Optocouplers 217
8.4 Relays 218
Contents ● xi

8.5 Digital-to-Analog Converters 220


8.5.1 DAC Parameters 221
8.5.2 DAC Realizations 222
8.6 Analog-to-Digital Converters 229
8.6.1 Single Ramp Comparison Type ADC 229
8.6.2 Dual-slope Integrator Type ADC 231
8.6.3 Direct Type ADC 232
8.6.4 Tracking Type ADC 233
8.6.5 The Successive Approximation ADC Counter 233
8.6.6 Microcontroller-based ADCs 235
8.6.7 ADC Chips 238
8.6.8 Bus Compatible ADCs 238
8.6.9 DAC/ADC Specifications 239
8.7 Sample and Hold Amplifier 240
8.8 Analog Multiplexer 242
8.9 Data Acquisition Systems 243
Summary 246
Review Questions 247
Fill in the Blanks 247
Short Questions 247

9. TIMER/COUNTER OPERATIONS 249–267


Learning Objectives 249
9.1 Software-based Approach 250
9.1.1 Clock Generation 251
9.1.2 Pulse Width Modulated Signal 251
9.2 Hardware-based Approach 252
9.2.1 Monostable Operation 254
9.2.2 Astable Operation 255
9.3 Combined Hardware–Software-based Approach 256
9.3.1 Registers Involved in Timer/Counter Operations 256
9.3.2 Timer/Counter Clock Source 258
9.3.3 Timer Modes of Operation 259
9.3.4 Counting External Events 261
9.3.5 Interaction between the Timer/Counter and the Processor 262
Summary 265
Review Questions 266
Fill in the Blanks 266
Short Questions 266

10. SERIAL MODE OF DATA TRANSFER 268–299


Learning Objectives 268
10.1 Serial Transmission Fundamentals 269
10.1.1 Modes of Data Transfer 270
Microcontrollers : Principles And
Applications

30%
OFF

Publisher : PHI Learning ISBN : 978812034 3924 Author : PAL, AJIT

Type the URL : http://www.kopykitab.com/product/74 89

Get this eBook

You might also like