Embedded Systems: Technical Publications

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Technical Publications

Embedded Systems
A Conceptual Approach

A. R Godse, A. 0. Mulani

TECHNICAL
PUBLICATIONS technical@vtubooks.com
An U p-Thrust lo r Knowledge www.technicalpublications.org
Embedded Systems

(i)
About the Author
A. P. Godse

• Completed M.S in Software Systems with distinction from Birla Institute of Technology.
• Completed B.E. in Industrial Electronics with distinction from University of Pune in 1990.
• Worked as a Professor at Vishwakarma Institute of Technology, Pune.
• Worked as a Technical Director at Noble Institute of Technology, Pune.
• Worked as selection Committee member for M. S. admission for West Virginia University,
Washington D.C.
• Developed Microprocessor Based Instruments in co-ordination with Anna Hazare for
Environmental Studies Laboratory, at Ralegan Siddhi.
• Developed Microprocessor Lab in-house for Vishwakarma Institute of Technology.
• Worked as Subject Expert for a State Level Technical Paper Presentation Competition, Pune.
• Awarded on 26th Ja n 2 0 0 1 by Pune Municipal Corporation for contributing in education field
and technical writing.
• Awarded as a “Parvati Bhushan Puraskar” for contributing in the education field.
• Since 1996, writing books on various engineering subjects. Over the years, many of books are
recommended as the reference books and text books in various national and international
engineering universities.

(ii)
E mbedded Systems
Atul P Godse
M. S. Software Systems (BITS Pilani)
B.E. Industrial Electronics
Formerly Lecturer in Department of Electronics Engg.
Vishwakarma Institute of Technology
Pune

Altaf O. Mulani
M.Tech. [Electronics - Digital System]
Lecturer in E & Tc Dept.
Vishwakarma Institute of Information Technology
Pune

Price : ' 325/-


® ISBN 978-93-5099-317-0

TECHNICAL
PUBLICATIONS
An Up-Thrust for Knowledge

Pune Nashik Bangalore Chennai Hyderabad


Ahmedabad Bhopal Lucknow Jaipur Delhi

(iii)
Embedded Systems

First E d itio n : Ja nuary 2 0 1 4


R ep rint : M a rc h 2 0 1 5
S econd R ep rint : Ja nuary 2 0 1 6
R ep rint : M a rc h 2 0 1 9

© Copyright with Authors

All publishing rights (printed and ebook version) reserved with Technical Publications. No part of this book
should be reproduced in any form, Electronic, Mechanical, Photocopy or any information storage and
retrieval system without prior permission in writing, from Technical Publications, Pune.

Published b y :
® TM Amit Residency, Office No.1, 412, Shaniwar Peth, Pune - 411030, M.S. INDIA.
TECHNICAL P h .: +91 - 0 2 0 -2 4 4 9 5 4 9 6 /9 7 , T e le fa x : +91 -0 2 0 -2 4 4 9 5 4 9 7
P U B LIC A T IO N S Email : technical@vtubooks.com Website : www.technicalpublications.org

Printer :
Repro India Ltd.
5 0 /2 T T C , M ID C ,
M ahape, N avi M um bai

Price : ' 325/-


I SBN 978-93 -5099-317- 0

9 7 8 9 3 5 0 9 9 3 |- O

IS B N 9 7 8 9 3 5 0 9 9 3 1 7 0 (P rin te d B o o k )

(iv)
9789350993170 [1] 9789350995020 [1]
Preface
T h e im p o rta n c e o f E m b e d d e d S y s te m s is w e ll k n o w n in v a rio u s e n g in e e rin g fie ld s .
O v e rw h e lm in g re s p o n s e to o u r b o o k s o n v a rio u s s u b je c ts in s p ire d us to w rite th is b o o k .
T h e b o o k is s tru c tu re d to c o v e r th e key a s p e cts o f th e s u b je c t E m b e d d e d S ystem s.

T h e b o o k uses p la in , lu c id la n g u a g e to e x p la in fu n d a m e n ta ls o f th is s u b je c t. T he b o o k
p ro v id e s lo g ic a l m e th o d o f e x p la in in g v a rio u s c o m p lic a te d c o n c e p ts a n d ste p w is e m e th o d s
to e x p la in th e im p o rta n t to p ic s . Each c h a p te r is w e ll s u p p o rte d w ith nece ssa ry illu s tra tio n s ,
p ra c tic a l e x a m p le s a n d s o lv e d p ro b le m s . A ll th e c h a p te rs in th e b o o k a re a rra n g e d in a
p ro p e r s e q u e n c e th a t p e rm its e a c h to p ic to b u ild u p o n e a rlie r s tu d ie s. A ll c a re has be e n
ta k e n to m a k e s tu d e n ts c o m fo rta b le in u n d e rs ta n d in g th e b a s ic c o n c e p ts o f th e s u b je c t.

T h e b o o k n o t o n ly co v e rs th e e n tire s c o p e o f th e s u b je c t b u t e x p la in s th e p h ilo s o p h y o f
th e s u b je c t. This m a k e s th e u n d e rs ta n d in g o f this s u b je c t m o re c le a r a n d m a k e s it m o re
in te re s tin g . T h e b o o k w ill b e ve ry useful n o t o n ly to th e s tu d e n ts b u t a ls o to th e s u b je c t
te a c h e rs . T h e s tu d e n ts h a v e to o m it n o th in g a n d p o s s ib ly h a v e to c o v e r n o th in g m o re .

W e w ish to express o u r p ro fo u n d th a n k s to a ll th o s e w h o h e lp e d in m a k in g th is b o o k a
re a lity . M uch needed m o ra l s u p p o rt and e n c o u ra g e m e n t is p ro v id e d on n u m e ro u s
o c c a s io n s by o u r w h o le fa m ily . W e w ish to th a n k s th e Publisher a n d th e e n tire te a m o f
Technical Publications w h o h a v e ta k e n im m e n s e p a in to g e t th is b o o k in tim e w ith q u a lity
p rin tin g .

A n y s u g g e s tio n fo r th e im p ro v e m e n t o f th e book w ill be a c k n o w le d g e d and w e ll


a p p re c ia te d .

Authors
A. P. Godse
A. O. Mulani

Dedicated to Neha, Raturaj.


- tyjcisc

Dedicated to my Mother, Father, Sister, Brother and last but not the least my
Wife and my Child's Alvia and Subhan.
- /dliafi /Hulani
(V)
Table of Contents (Detail)
Chapter -1 Embedded Computing (1 -1) to (1 - 30)

1.1 Introduction............................................................................................. 1 -1
1.2 Complex Systems and Microprocessors............................................... 1 - 1
1.2.1 Embedding Computers.......................................................................................................... 1 -8
1.2.1.1 Processor Embedded into a System................................................................................. 1 -9
1.2.2 Characteristics of Embedded System Applications............................................................ 1 -9
1.3 Embedded System Design Process..................................................... 1 - 1 0
1.4 Formalisms for System Design............................................................1 -1 2
1.4.1 Structural Description.......................................................................................................... 1- 13
1.4.1.1 Class Diagram................................................................................................................ 1-13
1.4.1.2 Object D iagram ............................................................................................................ 1-14
1.4.2 Behavioral Description........................................................................................................ 1- 16
1.4.2.1 Sequence Diagram........................................................................................................ 1-17
1.5 Design Exam ple.................................................................................... 1 - 1 9
1.5.1 Model Train Controller........................................................................................................ 1- 19
Review Questions.......................................................................................1 - 2 8

Chapter - 2 The 8051 Architecture (2 -1) to (2 - 36)

2.1 Introduction ..............................................................................................2 - 1


2.2 Features of 8051 ..................................................................................... 2 - 2
2.3 8051 Microcontroller Flardware.............................................................2 - 3
2.3.1 Pin-out of 8051 ..................................................................................................................... 2 - 4
2.3.2 Central Processing Unit (CPU) .............................................................................................. 2 - 6
2.3.3 Internal RAM ............................................................................................................................2 - 6
2.3.4 Internal R O M ............................................................................................................................2 - 8
2.3.5 Input/Output P o rts ................................................................................................................... 2 - 8
2.3.6 Register Set of 8051 ............................................................................................................. 2 - 9

(vi)
2.3.6.1 Register A (Accum ulator).......................................................................................................... 2 - 9
2.3.6.2 Register B ............................................................................................................................... 2 - 1 0
2.3.6.3 Program Status Word (Flag R e g is te r ) .................................................................................2 - 1 0
2.3.0. 4 Stack and Stack P ointer..................................................................................................... 2 - 1 0
2.3.6.5 Data Pointer (D P T R )...........................................................................................................2- 11
2.3.0. 6 Program C o u n t e r .............................................................................................................. 2- 11
2.3.0. 7 Special Function Registers..................................................................................................2 - 1 2

2.4 Memory Organization in 8051 ............................................................. 2 - 14


2.5 Input/Output Pins, Ports and C ircuits...................................................2 - 1 5
2.6 Timers and Counters.............................................................................2 - 1 8
2.6.1 Timer/Counter Control L o g ic ................................................................................................ 2 - 1 8
2.6.2 Timer 0 and Timer 1 ............................................................................................................... 2 - 1 9
2.7 Serial P ort...............................................................................................2 - 2 3
2.7.1 Operating Modes for Serial Port............................................................................................2 - 2 4
2.7.2 Serial Port Control Register.................................................................................................. 2 - 2 5
2.7.3 Generating Baud R a tes.........................................................................................................2 - 2 5
2.8 Interrupt Structure.................................................................................2 - 27
2.8.1 Priority Level Structure...........................................................................................................2 - 2 8
2.8.2 External Interrupts................................................................................................................. 2 - 3 0
2.8.3 Single-Step O peration...........................................................................................................2 - 3 0
2.9 Clock and Oscillator............................................................................. 2 - 30
2.10 Power Saving O ptions....................................................................... 2 - 3 2
2.10.1 Idle M ode.............................................................................................................................. 2 - 3 3
2.10.2 Power Down M ode............................................................................................................... 2 - 3 3
2.11 Multiprocessor Communication in MCS-51.......................................2 - 36
Review Questions.......................................................................................2 - 3 6

Chapter - 3 Assembly Language Programming and


Instruction Set of 8051 (3 -1) to (3 - 92)

3.1 Introduction..............................................................................................3 - 1
3.1.1 Steps Involved in Programming........................................................................................... 3 -1
3.1.2 Flow C h a rt.............................................................................................................................. 3 -2
3.1.3 Languages used for Programming..........................................................................................3 -3
3.1.3.1 Machine L a n g u a g e ................................................................................................................3 - 3
(vii)
3.1.3.2 Assembly Language.................................................................................................................. 3 - 3
3.1.3.3 High-Level L a n g u a g e .............................................................................................................. 3 - 4
3.1.3.4 Comparison between Programming L angua ges....................................................................3 - 4

3.2 Addressing Modes and Instruction S e t...................................................3 -6


3.3 Addressing Modes................................................................................... 3 -6
3.4 Data Moving (Data Transfer) Instructions.............................................. 3 -8
3.4.1 Instructions to Access External Data M em ory.....................................................................3 - 1 3
3.4.2 Instructions to Access External ROM / Program M em ory................................................. 3 - 1 5
3.4.3 PUSH and POP Instructions.................................................................................................. 3 - 1 7
3.4.3.1 P U S H ........................................................................................................................................3 - 1 7
3.4.3.2 POP............................................................................................................................................3 - 1 9
3.4.4 Data Exchange Instructions.................................................................................................. 3 - 2 0
3.5 Logical Instructions...............................................................................3 - 23
3.5.1 Byte Level Logical Operations............................................................................................... 3 - 2 3
3.5.2 Bit Level Logical Operations................................................................................................. 3- 31
3.5.3 Rotate and Swap O perations............................................................................................... 3 - 3 6
3.6 Arithmetic Instructions.......................................................................... 3 - 39
3.6.1 F lags........................................................................................................................................3 - 3 9
3.6.2 Incrementing and Decrementing...........................................................................................3 - 4 0
3.6.3 Addition................................................................................................................................... 3 - 4 3
3.6.4 Subtraction............................................................................................................................. 3 - 4 5
3.6.5 Multiplication and Division......................................................................................................3 - 4 7
3.6.6 Decimal Arithmetic.................................................................................................................. 3 - 4 9
3.7 Jump and CALL Instructions................................................................3 - 51
3.7.1 Jump and Call Program R a nge............................................................................................3 - 5 2
3.7.2 Jump.........................................................................................................................................3 - 5 2
3.7.3 CALL and Subroutines...........................................................................................................3 - 6 3
3.8 Programming Examples....................................................................... 3 - 66
Review Questions.......................................................................................3 - 91

Chapter - 4 8051 Timer Serial Communication and


Interrupt Programming in Assembly (4 -1) to (4 - 40)

4.1 8051 Tim ers...........................................................................................4 - 1


4.1.1 Timer Registers..................................................................................................................... 4 -1
(viii)
4.1.2 Programming 8051 Timers...................................................................................................... 4 - 3
4.1.2.1 Mode 0 ....................................................................................................................................... 4 - 3
4.1.2.2 M o d e l....................................................................................................................................... 4 - 4
4.1.2.3 Mode 2 ....................................................................................................................................... 4 - 5
4.1.2.4 M ode3 ....................................................................................................................................... 4 - 5
4.1.3 Loading Timer R egisters.........................................................................................................4 - 8
4.2 Programming Counters.......................................................................... 4 - 9
4.3 Serial Communication.......................................................................... 4 - 1 3
4.3.1 Basics of Serial Communication............................................................................................4 - 1 3
4.3.1.1 C lassifica tio n...........................................................................................................................4 - 1 3
4.3.1.2 S im p le x ................................................................................................................................... 4 - 1 3
4.3.1.3 Half D uple x............................................................................................................................... 4 - 1 4
4.3.1.4 Full D u p le x ............................................................................................................................... 4 - 1 4
4.3.1.5 Transmission Formats.............................................................................................................. 4 - 1 4
4.3.1.6 RS 232 Standard.......................................................................................................................4 - 1 6
4.3.2 8051 Connections to RS 232C..............................................................................................4 - 2 0
4.3.3 8051 Serial Communication Programming...........................................................................4 - 2 0
4.3.3.1 Operating Modes for Serial P o rt............................................................................................. 4 - 2 0
4 .3 .3 .2 S B U F ....................................................................................................................................... 4- 21
4.3.3.3 Serial Port Control Register......................................................................................................4 - 2 2
4.3.3.4 Generating Baud R a te s ..........................................................................................................4 - 2 3
4.3.3.5 Programming 8051 for Serial Data T ra n s fe r........................................................................ 4 - 2 4
4.3.3.6 Programming 8051 for Receiving Serial D ata........................................................................4 - 2 6
4.3.3.7 Doubling the Baud Rate in the 8051 ................................................................................ 4-27
4.3.4 Programming the Second Serial Port................................................................................... 4 - 2 8
4.3.4.1 Addresses for all SCON and SBUF Registers........................................................................ 4 - 2 9
4.3.4.2 Programming the Second Serial Port using Timer 1 ........................................................... 4 - 2 9
4.3.4.3 More E x a m p le s .......................................................................................................................4 - 3 0

4.4 Interrupt Programming......................................................................... 4 - 32


4.4.1 8051 Interrupts........................................................................................................................4 - 3 2
4.4.2 Interrupt Vector Table.............................................................................................................4 - 3 2
4.4.3 Enabling and Disabling an Interrupt..................................................................................... 4 - 3 3
4.4.4 Programming Timer Interrupts..............................................................................................4 - 3 3
4.4.5 Programming External Hardware Interrupts.........................................................................4 - 3 5
(ix)
4.4.6 Programming the Serial Communication Interrupts......................................................... 4 - 3 6
4.4.7 Interrupt Priority in the 8051/52 ......................................................................................... 4 - 3 8
4.4.7.1 Nested Interrupts............................................................................................................4- 39
4.4.7.2 Software Triggering of Interrupt.....................................................................................4- 39
Review Questions ......................................................................................4 - 39

Chapter - 5 Applications : Interfacing 8051 to External World (5 -1 ) to (5 -102)

5.1 Introduction............................................................................................. 5 - 1
5.2 External RAM and R O M ........................................................................ 5 - 1
5.2.1 Program M em ory................................................................................................................... 5 -1
5.2.2 Data M em ory......................................................................................................................... 5 -3
5.2.3 Important Points to Remember inAccessing External Memory............................................ 5 - 6
5.2.4 Memory Interfacing................................................................................................................. 5 -6
5.2.5 Interfacing Example............................................................................................................... 5 - 1 0
5.3 Interfacing Keyboard.............................................................................. 5 - 1 2
5.3.1 Key Debounce using Hardware............................................................................................5 - 1 3
5.3.2 Key Debouncing using S oftw are..........................................................................................5 - 1 4
5.3.3 Simple Keyboard Interface.....................................................................................................5 - 1 4
5.3.4 Matrix Keyboard Interface.....................................................................................................5 - 1 6
5.4 Interfacing Display................................................................................5 - 20
5.4.1 LED Displays..........................................................................................................................5 - 2 0
5.4.2 Interfacing LED D isplays.......................................................................................................5 - 2 2
5.5 Interfacing LCD Display....................................................................... 5 - 26
5.6 Interfacing DAC to 8051....................................................................... 5 - 33
5.6.1 IC DAC 1408 ....................................................................................................................... 5 - 3 3
5.6.1.1 Important Electrical Characteristics for IC 1408 ....................................................... 5-37
5.6.2 Interfacing DAC 1408 / DAC 0808 with 8051 .................................................................... 5 - 37
5.7 Interfacing ADC to 8051....................................................................... 5 - 41
5.7.1 ADC 0804 Fam ily................................................................................................................... 5- 41
5.7.2 ADC 0808/0809 F a m ily.........................................................................................................5 - 4 3
5.7.3 Interfacing of ADC 0803/0804/0805 with 8051.................................................................. 5 - 4 8
5.7.4 Sensor Interfacing - Practical Application............................................................................. 5 - 4 9
5.7.5 Interfacing of ADC 0844/0848 ............................................................................................ 5 - 5 0
5.7.6 Serial ADC Chip MAX1112/ MAX11 1 3 ............................................................................... 5 - 5 4
M
5.8 Stepper Motor Interface....................................................................... 5 - 59
5.9 DC Motor Interfacing............................................................................ 5 - 63
5.9.1 Pulse Width Modulation (PW M )............................................................................................5 - 6 4
5.9.2 DC Motor Control with Optoisolator...................................................................................5 - 6 5
5.10 Interfacing Examples......................................................................... 5 - 66
5.11 Multiple Interrupts................................................................................ 5 - 7 2
5.12 I/O Expansion using 8255.................................................................. 5 - 73
5.12.1 8255 Programmable Peripheral Interface (PPI)................................................................ 5 - 7 3
5.12.1.1 Features of 8 2 5 5 A .............................................................................................................. 5 - 7 5
5.12.1.2 Pin D escription.......................................................................................................................5 - 7 6
5.12.1.3 Block D ia g ra m .......................................................................................................................5 - 7 7
5.12.1.4 Operation M o d e s .................................................................................................................. 5 - 7 9
5.12.1.5 Control Word F o rm a ts ..........................................................................................................5 - 8 0
5.12.2 Connecting the 8031/51 to 8255 ..................................................................................... 5 - 8 3
5.12.3 8031 System with 8255 .................................................................................................... 5 - 8 8
5.12.4 Typical MCS-51 Based System ..........................................................................................5 - 9 0
5.12.5 8255 Interfacing................................................................................................................... 5- 91
5.12.5.1 Stepper Motor Interfacing using 8255 ............................................................................ 5- 91
5.12.5.2 LCD Interfacing using 8255 ............................................................................................. 5-92
5.12.5.3 ADC Interfacing using 8255 ............................................................................................. 5-94
5.12.6 Interfacing Exam ples...........................................................................................................5 - 9 6
Review Questions........................................................................................ 5 - 9 9

Chapter - 6 Introduction to Real-Time Operating Systems (6 -1 ) to (6 - 20)

6.1 Introduction ..............................................................................................6 - 1


6.2 Tasks and Task S tates............................................................................6 - 5
6.3 Tasks and Data....................................................................................... 6 - 8
6.4 Semaphores and Shared Data ...........................................................6 -1 0
6.4.1 Counting Semaphore.............................................................................................................6- 11
6.4.2 Multiple Semaphores.............................................................................................................6 - 1 2
6.4.3 Binary Semaphore................................................................................................................. 6 - 1 2
6.4.4 Semaphores as a Signalling Device................................................................................... 6 - 1 2
6.4.5 Semaphore Problems.............................................................................................................6 - 1 3

(xi)
6.5 Priority Inversion.................................................................................... 6 - 1 3
6.6 Message Queues................................................................................... 6 - 1 4
6.7 Mailboxes................................................................................................6 - 1 5
6.8 Pipes....................................................................................................... 6 - 1 5
6.9 Timer Functions..................................................................................... 6 - 1 6
6.10 Events................................................................................................... 6 - 1 6
6.11 Memory Management..........................................................................6 - 1 6
6.12 Interrupt Routines in an RTOS Environment..................................... 6 - 1 7
6.13 Comparison of the Methods for Intertask Communication................ 6 - 1 8
6.14 Comparison of the Three Methods of Protecting Shared Data....... 6 -1 8
Review Questions........................................................................................ 6 - 1 9

Chapter - 7 Basic Design using a RTOS (7 -1) to (7 -12)

7.1 Principles..................................................................................................7 - 1
7.2 Encapsulating Semaphores and Queues ............................................. 7 - 2
7.3 Hard Real Time Considerations.............................................................. 7 - 3
7.4 Saving Memory Space.............................................................................7 - 4
7.5 Saving P o w e r.......................................................................................... 7 - 4
7.6 Micro C/OS-II............................................................................................7 - 5
7.7 Embedded Software Development Tools ............................................. 7 - 5
7.7.1 Host and Target Machines .................................................................................................. 7 -5
7.8 Getting Embedded Software into the Target System........................... 7 - 8
7.8.1 PROM Programmers............................................................................................................. 7 -9
7.8.2 ROM Em ulators..................................................................................................................... 7 -9
7.8.3 In-circuit Emulators................................................................................................................. 7 -9
7.8.4 Flash........................................................................................................................................ 7 -9
7.8.5 M onitors.................................................................................................................................. 7 -9
7.9 Debugging Techniques........................................................................ 7 -1 0
7.9.1 Testing on Host M achine.......................................................................................................7 - 1 0
7.9.2 Using Laboratory T o o ls .........................................................................................................7- 11
Review Questions...................................................................................... 7 - 1 2

(xii)
Chapter-8 Introduction to Advanced Architectures (8 -1 ) to (8-2 8)

8.1 Introduction...............................................................................................8 -1
8.2 ARM Processor (Advanced RISC Machine Processor)....................... 8 - 2
8.2.1 Processor and Memory Organization..................................................................................... 8 - 2
8.2.2 Programming Model................................................................................................................. 8 - 3
8.2.3 ARM Instruction S e t................................................................................................................. 8 - 4
8.2.4 Computing an Absolute Address using P C ...........................................................................8 - 8
8.3 SHARC Processor................................................................................. 8 - 1 0
8.3.1 Memory Organization.............................................................................................................8 - 1 0
8.3.2 Data Operations..................................................................................................................... 8- 11
8.3.3 Instruction Level Parallelism (IP L )........................................................................................8 - 1 6
8.4 Networked Embedded Systems............................................................ 8 - 1 6
8.4.1 Bus Protocols..........................................................................................................................8 - 1 7
8.4.2 l2C Bus (Inter Integrated Circuit Bus)................................................................................... 8 - 1 7
8.4.3 CAN Bus (Controller Area Network B u s).............................................................................8 - 1 8
8.5 Internet Enabled Systems.................................................................... 8 - 20
Review Questions........................................................................................ 8 - 2 7

(xiii)
(xiv)
Embedded Systems (A Conceptual Approach)

20%
OFF

Author : Atul P. Godse, Altaf O.


Publisher : Technical Publications ISBN : 9789350993170
Mulani

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

Get this eBook

You might also like