Microcontrollers and Embedded Systems

282

Click here to load reader

description

The main objectives of this book are to teach students the fundamental concepts of the 8051 microcontroller, and logical programming oriented approach, which will help students who want to firm grasp on microcontroller applications, assembly programming and interfacing to the memory and I/O devices.The I/O devices such as motors, sensors, ADC, DAC, keyboard, memory, buzzer, speaker, programmable chips, LCD, LED, seven segment display etc., are magnify microcontroller operations and applications.Assembly programming is an important aspect, without the knowledge of the internal architecture, it is not possible to make a good assembly program. Emphasis is given to the microcontrollers and entire peripherals architecture, pin configuration and mode of operations.This book contains twenty two chapters. The objectives of the course and the book are the same to describe the right way to design embedded systems. While no prior knowledge of microcontrollers or microprocessors is required, but the reader should be familiar with basics of electronics, logic, and computer organization.Learning to design and develop a microcontroller system without any practical hands-on experience is a bit like trying to learn to drive a car from reading book. Thus, another goal is to provide a practical example of a complete working module.Students are advised to work out all the review questions and then proceed to the next chapter. The review questions will refresh the contents of that chapter discussed. This way will help you a lot for embedded systems design.

Transcript of Microcontrollers and Embedded Systems

  • Microcontrollers and

    Embedded Systems

    Thorough 8051 Microcontroller

    Over 135 programming examples

    Includes 15 I/O devices interfacing examples

    Introduction to Advance Microcontrollers and RTOS

    MOHIT TYAGI

    ARVIND KUMAR GUPTA

    ESCS LABS-Gr. NOIDA

  • Microcontrollers and Embedded Systems (The 8051 Microcontroller Architectural detailed explanation, Assembly language programming, interfacing with peripheral devices,

    introduction to the 8096, MC68H11 and ARM processor, an overview on embedded systems design and RTOS)

    Mohit Tyagi B.Tech., M.Tech. (MANIT-Bhopal)

    (Training and R&D cell, ESCS Labs-Greater Noida)

    Edited by

    Er. Arvind Kumar Gupta (Project Manager in RMRC-Delhi and Technical advisor in ESCS Labs-Greater Noida)

  • PREFACE

    This text book is intended for a course entitled Microcontrollers and Embedded Systems written for engineering students (GBTU, MMTU, KU, RTU, PTU, IP, MDU, RGPV etc.).

    Now-a-days the microcontrollers have become the most powerful tools available to

    the engineers. A small microcontroller in the fan control provides programmable speed control and temperature level of the room. High end industrial products can

    contain over fifty embedded microcontrollers. A typical middle class household has over fifty embedded devices. For every PC, smart phone in the world there are over

    one hundred embedded devices. Millions of PCs are manufactured each year, but billions of microcontrollers manufactured annually. While a great deal of attention is given to personal computers, the vast majority of new designs are for embedded

    applications. For every PC designer, there are thousands of designers using microcontrollers in embedded applications. The number of embedded designs is

    growing quickly. Architecture of the Microcontroller, especially assembly programming seems quiet complex to understand. Therefore, this book is designed to provide the desirable

    balance among the basic concepts of architecture design, programs and interfacing. The main objectives of this book are to teach students the fundamental concepts of

    the 8051 microcontroller, and logical programming oriented approach, which will help students who want to firm grasp on microcontroller applications, assembly programming and interfacing to the memory and I/O devices.

    The I/O devices such as motors, sensors, ADC, DAC, keyboard, memory, buzzer, speaker, programmable chips, LCD, LED, seven segment display etc., are magnify

    microcontroller operations and applications.

    Assembly programming is an important aspect, without the knowledge of the

    internal architecture, it is not possible to make a good assembly program. Emphasis is given to the microcontrollers and entire peripherals architecture, pin configuration and mode of operations.

    This book contains twenty two chapters. The objectives of the course and the book are the same to describe the right way to design embedded systems. While no prior

    knowledge of microcontrollers or microprocessors is required, but the reader should be familiar with basics of electronics, logic, and computer organization.

    Learning to design and develop a microcontroller system without any practical hands-on experience is a bit like trying to learn to drive a car from reading book.

    Thus, another goal is to provide a practical example of a complete working module.

    Students are advised to work out all the review questions and then proceed to the next chapter. The review questions will refresh the contents of that chapter

    discussed. This way will help you a lot for embedded systems design.

    Authors

  • ABOUT THE AUTHORS Mohit Tyagi has over 6 year experience in industry, research and teaching. He holds graduate

    degree in department of Electronics and Instrumentation Engineering and Master Degree in VLSI

    and Embedded System Design from Maulana Azad National Institute of Technology (MANIT)-

    Bhopal. He has published several research papers in National/ international journals. His areas of

    working and current interest in computer architecture design (VLSI), embedded system, and

    analog signal processing. He is a co-founder and working in training and research cell of ESCS

    Labs-Greater Noida. The ESCS Labs is dedicated to spread knowledge in the field of VLSI design,

    digital design, embedded system design and consumer electronics products design.

    Arvind Kumar Gupta has a Bachelor of Technology degree in Electronics and communication.

    He is working as a research associate in RMRC-Delhi; also serve as technical advisor in ESCS

    Labs-Greater Noida. He has published several research papers in national/ international journals

    and conferences. His areas of interest SMPS design, microcontroller based product design,

    computer architecture and consumer electronics product design.

    ESCS LABS- Greater Noida Published in Bharat ESCS Labs 2014

    All rights reserved.

    For suggestions and queries you can mail at: [email protected], [email protected] , www.escslabs.com

  • i

    CONTENTS

    CHAPTER 1

    INTRODUCTION TO DIGITAL SYSTEM 1

    1.1 Number system 1

    1.2 Logic Gate 4

    1.3 Flip-Flop 6

    1.4 Mux and De-mux 6

    1.5 Basic input and output logic devices for interface 7

    1.6 Registers 8

    1.7 Arithmetic and Logical unit 9

    Review Questions 11

    CHAPTER 2

    INTRODUCTION TO THE COMPUTER SYSTEM 12 2.1 Explanation of terms related to the microprocessors 13

    2.2 Microprocessor 14

    2.3 Introduction to Microprocessor based system 15

    2.4 Microcontroller 16

    2.5 Computer Architectures 17

    CISC 17

    RISC 18

    2.6 Memory Architecture 18

    Von-Neumann or Princeton 18

    Harvard 19

    2.7 The 8, 16 and 32-bit Microcontrollers 19

    CHAPTER 3

    INTRODUCTION TO MICROCONTROLLER, EMBEDDED PROCESSOR AND SYSTEM

    3.1 Introduction to the microcontroller

    3.2 Embedded Processor and Application Awareness

    3.3 Selecting the right Microcontroller Unit

    3.4 Processor Technologies

    3.5 Selection Process

    3.6 Choosing the Right Processor Technology

    3.7 What does the MCU Need to do in the System?

    3.8 Finalizing the Selection

    CHAPTER 4 THE 8051 MICROCONTROLLER

    4.1 Introduction to the 8051 Microcontroller Family

    4.2 Development/Classification of Microcontrollers

    4.3 The 8051 Microcontroller Architecture

    4.4 The Functional Block Diagram for the 8051

    4.5 A Small 8051 Microcontroller (AT89C2051)

  • ii

    CHAPTER 5

    ASSEMBLY LANGUAGE PROGRAMMING 5.1 Structure of Assembly Language Program

    5.2 Assembler

    5.3 Assembling and Running an 8051 Program

    5.4 Programming Model for the 8051

    5.5 The 8051s Memory Organization

    5.5.1 Internal RAM Organization

    The PSW Register and the Flag Bits of the 8051

    5.5.2 Internal ROM

    5.6 Inside the 8051 Microcontroller

    5.7 Internal Working of the Microcontroller 5.8 The 8051 Microcontroller Instruction Set Summary

    CHAPTER 6

    DATA TRANSFER INSTRUCTIONS, I/O PORT PROGRAMMING 6.1 Data Transfer (Copy) Instructions and Programs 6.2 The 8051 I/O Parallel Port Programming

    CHAPTER 7

    ADDRESSING MODES 7.1 Immediate/constant addressing

    Register addressing

    Direct addressing

    Register indirect addressing

    Indexed addressing

    Implied addressing mode

    7.2 Timing Effect of Addressing Modes

    7.3 Flow Chart symbols and description

    CHAPTER 8

    BRANCHING INSTRUCTIONS, LOOPS AND PROGRAMS 8.1 Jump Instructions, Loop and Programs

    Unconditional Jump Instructions

    Conditional Jump Instructions

    Nested Loop (Loop within a Loop)

    Call Instructions and Programs

    Time Delay Calculation (Software Method)

    CHAPTER 9

    ARITHMETIC INSTRUCTIONS AND PROGRAMS

    9.1 Addition

    9.2 Subtraction

    9.3 BCD (Binary Code Decimal) Number System

    9.4 Multiplication and Division

    9.5 Increment/Decrement

  • iii

    CHAPTER 10

    LOGIC INSTRUCTIONS AND PROGRAMS

    10.1 Logical Instructions

    10.2 Rotate Accumulator

    10.3 Swap Nibbles within Accumulator

    10.4 ASCII and BCD Code for Decimal Digits

    CHAPTER 11

    SINGLE BIT HANDLING INSTRUCTIONS 11.1 Bit Handling Instructions 11.2 Interfacing of a LED With a Port Pin 11.3 The Code Conversion Techniques and Programming BCD to Binary/Hex Conversion Binary/Hex to BCD Conversion 11.4 BCD To Seven-Segment Code Conversion 11.5 BCD to Seven-Segment Code Conversion 11.6 Interfacing with Buzzer

    CHAPTER 12

    TIMER/COUNTER IN THE 8051 12.1 Timers Programming

    12.2 Time Delay Generation (Hardware Approach)

    12.3 Large Time Delay Generation (Mixed Approach)

    12.4 Using Timers as Counters (Counter Programming)

    CHAPTER 13

    8051 SERIAL COMMUNICATION, SPI, I2C AND USB INTERFACE

    13.1 Synchronous And Asynchronous Serial Communications

    13.2 Asynchronous Serial Data Bit Format

    13.3 The Rs-232 Standards

    13.4 DCE and DTE Devices

    13.5 Voltage Converters

    13.6 Universal Asynchronous Receiver Transmitter (Uart)

    13.7 Baud Rate Generation

    13.8 Serial Port Programming to Transmitting and Receiving Data

    13.9 Power Mode Control (Pcon) Register

    13.10 SPI Bus Interface

    13.11 I2C Bus Interface

    13.12 The Universal Serial Bus (USB)

  • iv

    CHAPTER 14

    THE 8051 INTERRUPTS 14.1 Polling and Interrupt Based Data Handling Input/Output Devices

    14.2 The 8051 Interrupts

    14.3 Enabling and Disabling of Interrupts

    14.4 Timer Interrupts

    14.5 External Interrupts

    14.6 Internal Interrupts

    14.7 Interrupts Structure for the 8051

    14.8 Interrupt Priority in the 8051

    14.9 Nested Interrupt (Interrupt with an Interrupt)

    14.10 Interrupt Latency

    CHAPTER 15

    DATA CONVERTERS AND INTERFACING

    15.1 Digital To Analog Convertor

    15.2 Interfacing an 8-Bit DAC (MC1408) With The 8051 Microcontroller

    15.3 Analog to Digital Converter (ADC 804)

    15.4 The ADC 804 Interfacing with the Microcontroller

    15.5 ADC0808/0809 Chip with 8 Analog Channels

    15.6 Serial ADC Chips

    15.7 Temperature Measurement

    15.8 Signal Conditioning

    15.9 Analog Output

    CHAPTER 16

    INTERFACING WITH THE KEYBOARD, SEVEN SEGMENT DISPLAY, LCD AND MOTORS 16.1 Simple Keyboard and Seven Segment Display Interface

    16.2 Matrix Keyboard Interfacing with the 8051

    16.3 Interfacing To LCD Display

    16.4 The 8051 Interfacing With THe Motors

    16.5 Pulse Width Modulation (PWM)

    CHAPTER 17

    INTERFACING TO EXTERNAL MEMORY

    17.1 Decoder as Address Decoder

    17.2 Flip-Flop or Latch as the Basic Output Interface

    17.3 Memory Expansion

    17.4 Introduction to Address Decoding

    17.5 External Memory Interfacing in 8051/8031

    17.6 External Program ROM Interfacing 17.7 External Data Memory RAM

  • v

    APPENDIX A 232-244

    MODEL QUESTION PAPER 252

    QUESTION BANK

    CHAPTER 18

    THE 8051/31 INTERFACING WITH 8255 (EXPENDING I/O PORTS)

    18.1 Interfacing of the 8051 Microcontroller with the 8255 PPI

    18.2 Simple Keyboard and Seven Segment Display Interface

    18.3 Matrix Keyboard Interfacing with the 8255

    CHAPTER 19

    INTRODUCTION TO ADVANCED MICROCONTROLLERS

    19.1 Introduction to Intel 8096

    19.2 Introduction to MC68HC11 Microcontroller

    19.3 Introduction to ARM Processor

    CHAPTER 20

    INTRODUCTION TO EMBEDDED SYSTEM DESIGN

    20.1 Inside An Embedded System

    20.2 Design Parameters

    20.3 Embedded Systems Design

    20.4 Development Lifecycle Model

    20.5 The Embedded Systems Model

    20.6 Present Trends in Embedded System

    20.7 Real-Time Embedded Systems

    20.8 Software Partitioning

    20.9 Hardware and Software Co-Design Model

    CHAPTER 21

    INTRODUCTION TO REAL-TIME OPERATING SYSTEM (RTOS)

    21.1 Real-Time Operating System

    21.2 The Scheduler

    21.3 Multitasking

    21.4 Scheduling Algorithms

    21.5 Task and Task States

    21.6 Priority Inversion

    21.7 Why Operating Systems for Real-Time Applications

    21.8 Task-Oriented Design

    21.9 How does an RTOS Work?

    21.10 CASE STUDIES of RTOS

  • vi

  • 1

    CHAPTER-1 INTRODUCTION TO DIGITAL SYSTEMS

    The basic concepts of digital are necessary to understand the software logic and hardware design of a

    microprocessor/microcontroller based system. In this chapter, we are focusing on logic gates, number

    systems, conversion and inside a CPU.

    1.1 NUMBER SYSTEMS The number of digits or basic symbols in a number system is known as its base. The decimal system has a base of 10 because it uses 10 digits. Binary has a base of 2; octal has a base of 8 and hexadecimal a base of 16. The number of digits in any base (also called radix) N is exactly the same number N. For example, in the binary (N = 2) number system there are only two digits: 0 and 1; in the Octal (N=8) there are eight of them: 0, 1, 2, 3, 4, 5, 6, and 7; in the decimal (N = 10) there are ten of them: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. What if N exceeds 10? If N > 10, the missing digits come from the alphabet (usually disregarding the case.) Thus A stands for the decimal 10 in any number system with base greater than 10. The B stands for the decimal 11 in any number system with base greater than 11, and so on. Here is the list of hexadecimal (base 16) digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. It is customary to prefix hexadecimal numbers with ()H or 16, octal with ()O or 8 , decimal with ()D or 10 and binary with ()B or 2. The table 1.1 show that the basics of conversion and the relation among the number systems.

    Table 1.1: Number systems

    Decimal (0-9)10

    Binary (0-1)2

    Ternary (0-2)3

    Quintal (0-4)5

    Octal (0-7)8

    Hexadecimal (0-F)16

    Base 36 number (0-Z)36

    0 0 0 0 0 0 0

    1 1 1 1 1 1 1

    2 10 2 2 2 2 2

    3 11 10 3 3 3 3

    4 100 11 4 4 4 4

    5 101 12 10 5 5 5

    6 110 20 11 6 6 6

    7 111 21 12 7 7 7

    8 1000 22 13 10 8 8

    9 1001 100 14 11 9 9

    10 1010 101 20 12 A A

    11 1011 102 21 13 B B

    12 1100 110 22 14 C C

    13 1101 111 23 15 D D

    14 1110 112 24 16 E E

    15 1111 120 30 17 F F

    16 10000 121 31 20 10 G

    17 10001 122 32 21 11 H

    18 10010 200 33 22 12 I

    19 10011 201 34 23 13 J

    . . . . . . .

    . . . . . . .

    98 1100010 10122 343 142 62 2Q

    99 1100011 10200 344 143 63 2R

    100 1100100 10201 400 144 64 2S

    101 1100101 10202 401 145 65 2T

    . . . . . . .

    . . . . . . .

    999 1111100111 1101000 12444 1747 3E7 RR

    1000 1111101000 1101001 13000 1750 3E8 RS

    1001 1111101001 1101010 13001 1751 3E9 RT

  • 2

    Decimal to Binary Conversion Double Dabble: This is a very popular way to convert decimal numbers to binary numbers. In this method, we progressively divide the decimal number by 2, writing down the remainder after each division. The remainder, arranged in reverse order is result the required binary number. Let us convert decimal number 1310 into equivalent binary number. Step 1 Divide 13 by 2, 2) 13 ( 6 ------ Quotient is 6 12 LSB 1 remainder = 1 Step 2 2) 6 ( 3 ------ Quotient is 3 6 0 remainder = 0 Step 3 2) 3 ( 1 ------ Quotient is 1 2 1 remainder = 1 Step 4 2) 1 ( 0 ------ Quotient is 0 0 1 remainder = 1 MSB In final division, 1 does not divide by 2, therefore, the quotient is 0 with a remainder of 1. Hence, the binary equivalent of 1310 is 11012.

    Example 1.1: Express the decimal number 5410 as a binary number. Solution:

    54/2 = 27 ; remainder 0 27/2 = 13 ; remainder 1 13/2 = 6 ; remainder 1 6/2 =3 ; remainder 0 3/2 =1 ; remainder 1 1/2 =0 ; remainder 1

    Thus 54 decimal = 110110B and in an 8-bit register the value would be 00110110B. It may be easier to use the weighted values of an 8-bit register to determine the binary equivalent of a decimal number i.e. to break the decimal number down to those weighted elements, which have logic 1 level as given in following lines:

    Binary to Decimal Conversion We can express any decimal integer (a whole number) in units, tens, hundreds, thousands and so on. For instance, the decimal number 3056D may be written as

    385610 = 3000 + 800 + 50 + 6

    In power of 10, this becomes

    385610 = 3(10)3 + 8(10)

    2 + 5(10)

    1 + 6(10)

    0

    Here each digit position has a weight or value. The sum of all the digits multiplied by their weights gives the total amount being represented. Binary Weight In a similar way we can rewrite any binary number in terms of weights. For example binary number 111B (7D) becomes 1112 = 100 + 010 + 001

  • 3

    In decimal it is 710 = 4 + 2 + 1 710 = 1(2)

    2 + 1(2)

    1 + 1(2)

    o

    = 1(4) + 1(2) +1 Procedure for Binary to decimal conversion

    i) Write the binary number ii) Directly under the binary number, write weights from right to left. iii) Multiply the weight with corresponding binary digit. iv) Add the remaining weights to obtain the decimal equivalent.

    Example 1.2: Convert a binary number 1012 into equivalent decimal number. Solution:

    Step i) Binary Number : 1 0 1 Step ii) Binary Weight : 4 2 1 Step iii) Equivalent weight : 4 0 1 Step iv) Weight Sum : 4 + 0 + 1 = 510

    Example 1.3: Convert binary number 101012 into equivalent decimal number. Solution:

    Step i) : 1 0 1 0 1 Step ii) : 16 8 4 2 1 Step iii) : 16 0 4 0 1 Step iv) : 16 + 0 + 4 + 0 + 1 = 2110

    Conversion of Binary Fractions into decimal Fraction How we calculate the decimal equivalent of 0.1012? In this case, the weight of digit positions to the right of the binary point is given by 1/2, 1/4, 1/8, 1/16, 1/32 and so on. In power of 2, the weights are given below:

    2-1

    , 2-2

    , 2-3

    , 2-4

    and so on or in decimal form 0.5, 0.25, 0.125, 0.0625 and so on Hence, the decimal equivalent for the binary fraction 0.1012 can be calculated as bellow:

    0.1 0 1 0.5 + 0 + 0.125 = 0.62510

    Example 1.4: What is the decimal equivalent of binary fraction 0.11012? Solution: Step i) Binary Number : 0. 1 1 0 1 Step ii) Binary Weight : 2-1 2-2 2-3 2-4 Step iii) Equivalent weight : 0. 5 0.25 0.125 0.0625 Step iv) Weight Sum : 0. 5 + 0.25 + 0 + 0.0625 =0.812510 Hence, for conversion of binary number into decimal number we should remember the following format:

    23 22 21 20 .

    2-1 2-2 2-3

    Binary point

    Table 1.2: Binary Addition Example 1.5: Add binary numbers 10102 to 10112. Solution: Binary Decimal 1 0 1 0 1 0 +1 0 1 1 + 1 1 1 0 1 0 1 2 1 Table 1.3: Binary multiplication

    A+B Carry Sum 0 + 0 0 0 0 + 1 0 1 1 + 0 0 1 1 + 1 1 0

  • 4

    Example 1.6: Multiply 1012 by 1102. Solution: Binary Decimal Hex 1 0 1 5 5 x1 1 0 x 6 x 6 0 0 0 3 0 1E 1 0 1 x 1 0 1 x x 1 1 1 1 0

    1.2 LOGIC GATES The logic gate is somewhat similar to normal gate/door. When a gate is opened something is allowed to pass and when it is closed nothing is allowed to pass through. But logical gate thinks logically and then acts. It works with certain conditions. When all the conditions are fulfilled input is allowed to pass as output. A logic gate is a digital circuit with one or more inputs, but only one output. The output is high only for certain combinations of the input signals. We have different types of gates such as AND gate, OR gate, NOT gate etc. These can be designed with the help of switches, diodes, transistors and ICs. Let us discuss these gates one by one.

    AND Gate The AND Gate has two or more inputs but only one output. When all the inputs are high (1), the output is high (1) otherwise it is low (0). This gate can be implemented with simple switches as shown in figure 1.2(a).

    Figure 1.2: (a) AND gate drawn with simple switches A and B (b) Symbol for AND gate

    In the figure 1.2 (a), the switches A and B are connected in series with the supply. When both the switches are ON (i.e. 1 or High), the bulb is ON (1 or High). If any of the switches is OFF (0 or Low), the bulb is OFF (0 or Low). Hence the combination of switches A and B is known as AND gate. The symbol of AND gate is shown in figure 1.2(b).

    Truth Table A truth table gives details of various combinations of inputs and corresponding outputs. The truth table of AND gate is given in table 1.4. Table 1.4: Truth Table of AND Gate

    Figure 1.3: The AND gate drawn with diodes Figure 1.4: Quad 2-input TTL/CMOS AND gates AND Gate can also be implemented with diodes as shown in figure 1.3. When either A or B input is low (0), D1 or D2 is forward biased and output Y is low (0). When both inputs A and B are high (1) together, the output Y is High (1). In the same way AND Gate can also be designed with the combinations of diodes and transistors or only transistors. The AND gate designed in IC form is shown in figure 1.4. This gate works on the logic of 'this and that' hence the name is AND gate.

    Inputs Output (0 for off/low and 1 for on/high)

    A B Y

    0 0 1 1

    0 1 0 1

    0 0 0 1

    AB Multiplication 0 0 0 0 1 0 1 0 0 1 1 1

  • 5

    OR Gate This gate has two or more inputs and one output. When any one or all the inputs are high (1), the output is high (1). Figure 1.5(a) and (b) show the OR gate designed with the help of switches and diodes, respectively. Table1.5: Truth table for OR gate

    Figure 1.5: (a) The OR gates drawn with switches (b) The OR gate drawn with diodes From figure 1.5 (a), the bulb is glowing when switch A or/and B is ON (1 or High). In figure 1.5 (b) output Y is High (1) when either input A or B is high (1) making D1 or D2 to conduct. The symbol of OR Gate is shown in figure 1.6(a). The OR gates in IC form shows in figure 1.6 (b). This gate works on the logic of 'This or that', hence the name is OR gate.

    Figure 1.6: (a) Symbol of OR gate (b) Quad 2-input TTL OR gates

    NOT Gate The NOT gate has one input and one output. When the input is High (1), the out is low (0) and vice versa. The figure 1.7 shows NOT gate designed with a switch and a transistor. Table 1.6: Truth table for NOT gate

    Figure 1.7: (a) The NOT gate drawn with a switch (b) The NOT gate drawn with a transistor

    In figure 1.7(a), When the switch is ON (1 or High) the bulb is shorted and hence it does not glow (OFF or 0 or LOW). When switch is OFF (open or 0) the bulb is ON (1 or High). In figure 1.7 (b), When the input A is high (1) the transistor is forward biased and so it conducts making Y low (0). When the input A is low (0), the transistor is cut off and hence the output Y is high (1). Since the NOT gate inverts the sense of the output with respect to input, it is also called as an inverter. Figure 1.7 (c) and (d) shows NOT gates symbol and IC form. This gate works on the logic of negative; hence the name is NOT gate.

    Figure 1.7: (c) Symbol for NOT gate (d) Quad TTL NOT gates

    NAND Gate A NAND gate has two or more inputs and a single output. It is a combination of an AND gate and a NOT gate. The output of a NAND gate assumes the 0 state if and only if all the inputs assume the 1 state. Figure 1.8 shows the NAND gate designed with the help of switches, symbol of NAND gate and NAND gates in IC form.

    A B Y

    0 0 0

    0 1 1

    1 0 1

    1 1 1

    A (I/O) Y(O/P)

    0 1

    1 0

  • 6

    Table 1.7: Truth table for NAND gate

    Figure 1.8: (a) NAND gate drawn with switches (b) NAND gate Symbol (c) Quad 2-input NAND gates

    NOR Gate

    A NOR gate has two or more inputs and a single output. It is a combination of an OR gate followed by a NOT gate. The output of a NOR gate assumes the 1 state if and only if all the inputs assume the 0 state. Figure 1.9 shows the NOR gate designed with the help of switches. NOR gate symbol and IC form in given in figure 1.9. Table 1.8: Truth table for NOR gate

    Figure 1.9: (a) NOR gate drawn with switches (b) Symbol of NOR gate (c) Quad 2-input NOR gates The NAND and NOR gates are known as 'Universal Gates' as any gate or logical circuit can be implemented with them.

    Exclusive OR Gate EX-OR gate (see figure 1.10) has two or more inputs and one output. The EX-OR gate produces a high output when either of the inputs is high, but not both. This is different from the traditional OR gate, which produces a 1 output when either one or both of the inputs are 1. The opposite of Ex-OR gate is Ex-NOR gate. Table 1.9: Truth Table for EX-OR gate

    Figure 1.10: (a) Symbol of EX-OR gate (b) Implementation of EX-OR gate with AND, OR and NOT gates

    1.3 FLIP-FLOP

    A flip-flop (FF) is a bi-stable electronic circuit that has two stable states. The flip-flop also has memory unlike gates described in previous Sections, since its output will remain as set until something is done to change it. FF has two outputs, defined as Q and Q.Q and Q are complementary. D Flip-Flop: The RS flip-flop has two data inputs R and S. To store a high bit, we need a high S; to store a low bit, we need a high R. Generation of two signals to drive has disadvantages in many applications. Furthermore, something forbidden condition of both R and S high may occur in advertently. These problems are avoided in D flip-flop, which only a single data needs as input. Logic diagram, symbol and truth table of D-FF are shown in figure 1.11.

    Figure 1.11: Logic diagram, symbol and truth table of D Flip-Flop

    1.4 MULTIPLEXER AND DEMULTIPXER Multiplexers, sometimes called selectors, are combinatorial elements that function as a multi-position logical switches to select one of many inputs. Figure 1.12 (a) shows a common schematic representation of a multiplexer, often shortened to

    Input Output

    A B Y 0 0 1

    0 1 1

    1 0 1

    1 1 0

    Input Output

    A B Y

    0 0 1

    0 1 0

    1 0 0

    1 1 0

    Input Output

    A B Y 0 0 0

    0 1 1

    1 0 1

    1 1 0

  • 7

    MUX. A MUX has an arbitrary number of data inputs, often an even power of two, and a smaller number of selector inputs. According to the binary state of the selector inputs, a specific data input is transferred to the output. A truth table for a 4-to-1 MUX is shown in Table 1.10. Each selector input value maps to one, and only one, data input. A de-multiplexer, also called a DEMUX, performs the opposite operation of a MUX by transferring a single input to the output that is selected by select inputs. A DEMUX is drawn similarly to a MUX, as shown in figure 1.12 (b). Table 1.10: Four-to-One Multiplexer Truth Table Table 1.11: One-to-Four Demultiplexer Truth Table

    Figure 1.12: (a) Four-to-one multiplexer. (b) One-to-four de-multiplexer.

    A popular use for a DEMUX is as a decoder. A decoder produces a unique output corresponding to each input pattern. If the input line in figure 1.12 (b) is set to logic 0 (i.e., Din = 0), the 1-to-4 de-multiplexer will act as a decoder. For example, A = 0, B = 0 will give an output of 0 on line Y0; lines Y1, Y2, and Y3 will be at logic 1. Similarly, A = 0, B = 1 will give an output of 0 on line Y1; A = 1, B = 0 will give an output of 0 on line Y2; and A = 1, B = 1 will give an output of 0 on line Y3. Thus the 1-to-4 de-multiplexer can function as a 2-to-4 decoder. This function has great utility in microprocessor address or op-code decoding, which involves selecting one of multiple devices (e.g., a memory chip) at a time for access. The truth table for a 2- to-4 decoder is shown in table 1.12 and in figure 1.12 (c). The decoders outputs are active-low, because most memory and microprocessor peripheral chips use active-low enable signals.

    Table 1.12: Two-to-Four Decoder Truth Table

    1.5 BASIC INPUT AND OUTPUT LOGIC DEVICES FOR INTERFACE The interfacing logic devices are used to make compatible of I/O device to the microprocessor system. Also interfacing logic devices increase the current driving capacity of data/address lines. There are three basic interfacing devices:-

    1. Tri-state buffers as bus drivers 2. Decoder 3. Latch

    Tri-state/three-state buffer logic as the basic input interface: Three Logic Levels are used and they are as High, Low, and High impedance (1, 0 and z) state. The high and low are normal logic levels but high impedance state is electrical open circuit conditions. Tri-state logic has a third line called enable line may be active Low or High. The various types of tri-state buffers are shown in figure 1.13.

    DECODER

    24

    A

    B

    Y0

    Y1

    Y2

    Y3

    Figure 1.12(c): a 2 to 4 decoder

  • 8

    The only difference between tri-state buffer and two-state buffer (simply buffer) is that buffer does have high impedance state. Therefore, there is no need of third line to enable buffer as shown in figure 1.14. Input B Output Q Input B Output Q Input B Output Q Low Enable E High Enable E High Enable E Figure 1.13: (a) Active low, inverted output tri-state buffer (b) Active high, inverted output tri-state buffer (c) Active high, non inverted output tri-state buffer input output

    Figure 1.14: A buffer

    Active low, inverted O/P tri-state buffer: When enable E is low the gate is enabled and the output Q can be 1 or 0 (if B is 0, Q is 1, otherwise Q is 0). However, when E is high the gate is disabled and the output Q enters into a high impedance state. Table 1.13 is described the function of each pin of Low enabled tri-state buffer with inverting output.

    Table 1.13: Functional table for active low, inverted output tri-state buffer

    E ( Low Enable) B (Input) Q (Output) State description

    1(High) 0 z High impedance (Open Circuit)

    1 1 z High impedance (Open circuit)

    0(Low) 0 1 High

    0 1 0 Low

    Active High, inverted O/P tri-state buffer: When enable E is high the gate is enabled and the output Q can be 1 or 0 (if B is 0, Q is 1, otherwise Q is 0). However, when E is low the gate is disabled and the output Q enters into a high impedance state.

    Active High, non-inverted O/P tri-state buffer: When enable E is high the gate is enabled and the output Q can be 1 or 0 (if B is 0, Q is 0, otherwise Q is 1). However, when E is low the gate is disabled and the output Q enters into a high impedance state. The advantages of using tri-state buffer and two-state (normal) buffer

    1- It can avoid undesirable change in input and control the read operation of the output of flip-flop.

    2- Tri-state buffer have three states as high, low, and high impedance (open circuit). If any flip-flop

    or register is not involved in any read or/and write operations, tri-state (high impedance

    state) buffer disconnect this flip-flop or register from memory circuit by making open

    circuit or high impedance so that there is no flow of any current in the circuit hence we

    can save power dissipation.

    3- Tri-state buffers or two state buffers are used to amplify current or power driving capacity of buses

    to avoid loading effect. Loading effect means that when the microprocessor draws high load current

    from input device is may cause overloading. Input device gives some fake or inaccurate output

    value to the microprocessor as the overloading change the characteristics of the input device.

    1.6 REGISTERS Registers are collections of multiple flip-flops arranged in a group with a common function. They are a

    common synchronous-logic building block and are commonly found in multiples of 8-bit widths, thereby

    representing a byte, which is the most common unit of information exchange in digital systems. An 8-bit

    register provides a common clock and clock enable for all eight internal flip-flops. The clock enable allows

    external control of when the flip-flops get reloaded with new D-input values and when they retain their

    current values. It is common to find registers that have a built-in tri-state buffer, allowing them to be

    placed directly onto a shared bus without the need for an additional tri-state buffer component.

    Whereas normal registers simply store values, synchronous elements called shift registers manipulate

    groups of bits. Shift registers exist in all permutations of serial and parallel inputs and outputs. The role of

    a shift register is to somehow change the sequence of bits in an array of bits. This includes creating arrays

    of bits from a single bit at a time (serial input) or distributing an array of bits one bit at a time (serial

    output). A serial-in, parallel-out shift register can be implemented by chaining several flops together as

    shown in figure 1.14.

  • 9

    Figure 1.14: Serial-in, parallel-out shift register.

    On each rising clock edge, a new serial input bit is clocked into the first flop, and each flop in succession

    loads its new value based on its predecessors value. At any given time, the parallel output of an N-bit shift register reflects the state of the last N bits shifted in up to that time. In this example (N = 4), a serial

    stream of bits collected in four clock cycles can be operated upon as a unit of four bits once every fourth

    cycle. As shown, data is shifted in MSB first, because Dout[3] is shown in the last bit position. Such a

    simple transformation is useful, because it is often more practical to communicate digital data in serial

    form where only one bit of information is sent per clock cycle, but impractical to operate on that data

    serially. An advantage of serial communication is that fewer wires are required as compared to parallel.

    A parallel-in, serial-out shift register is very similar, as shown in figure 1.15, with the signals connected

    for MSB first operation to match the previous example. Four flops are used here as well. However, instead

    of taking in one bit at a time, all flops are loaded when the load signal is asserted. The 2-to-1 muxes are

    controlled by the load signal and determine if the flops are loaded with new parallel data or shifted serial

    data. Over each of the next four clock cycles, the individual bits are shifted out one at a time. If these two

    shift register circuits were connected together, a crude serial data communications link could be created

    whereby parallel data is converted to serial and then back to parallel at each end.

    Figure 1.15: Parallel-in, serial-out shift register

    1.7 ARITHMETIC AND LOGICAL UNIT An arithmetic and logic unit (ALU) is a digital circuit that performs arithmetic and logical operations.

    The ALU is a fundamental building block of the CPU of a processor. Most of a processor's operations are

    performed by the ALU. An ALU loads data from input registers. Then an external control unit tells the ALU

    what operation to perform on that data, and then

    the ALU stores its result into an output register.

    The control unit is responsible for moving the

    processed data between these registers, ALU and

    memory. In order to know that how an ALU works?

    We are undergoing with its design in next sections.

    The ALU Design

    A basic ALU design involves a collection of "1-bit

    ALU ", which each can perform the specified

    operation on a single bit. Figure 1.16 shows a 1-bit

    ALU that can perform AND, OR, and ADD

    operations.

    Figure 1.16: A 1-bit ALU circuit

  • 10

    A typical ALU is given in figure consists of various digital circuits such as decoder, multiplexer, de-

    multiplexer, adder, subtractor, multiplication, division, logical AND, OR, NAND, NOR, EX-OR etc. The op-

    code 01112= 7H enables the register A, register B and full adder circuit. To generate enable signal for it, a

    decoder (control circuit) is used. An 8-bit ALU can be implemented (shown in figure 1.17) for the functions

    as given in table 1.14. Table 1.14: Operations for ALU

    Select (Op-code) Operation Instruction Function Unit 0000 Y=A MOV Y, A Transfer A

    Arithmetic

    0001 Y=A+1 INC A Increment A

    0010 Y=A-1 DEC A Decrement A

    0011 Y=B MOV Y, B Transfer B

    0100 Y=B+1 INC B Increment B

    0101 Y=B-1 DEC B Decrement B

    0110 Y=A+B ADD A, B Add A and B

    0111 Y=A+B+Cin ADDC A, B Add A and B with Carry

    1000 Y=A CPL A Complement A

    Logic Unit

    1001 Y=B CPL B Complement B

    1010 Y=A AND B AND A, B Logical AND with A and B

    1011 Y=A OR B OR A, B Logical OR with A and B

    1100 Y=A NAND B NAND A, B Logical NAND

    1101 Y= A NOR B NOR A, B Logical NOR with A and B

    1110 Y=A XOR B XOR A, B Ex-OR

    1111 Y= A XNOR B XNOR A, B EX-NOR

    The ALU has some stages, each stage consisting of three parts: a) input multiplexers b) full adder and c)

    output multiplexers. The ALU performs the following four arithmetic operations, MOVE, ADD, INCREMENT

    and DECREMENT. The four logical operations performed are NOT, Ex-OR, Ex-NOR, AND and OR. The input

    and output sections consist of 8 to 1 and 2 to 1 multiplexers. A set of four select signals has been

    incorporated in the design to determine the operation being performed and the inputs and outputs being

    selected. Figure 1.17 shows the 8-bit ALU with the Cin bit cascading all the way from first stage to fourth

    stage.

    Figure 1.17: A typical 8-bit ALU

    There are large numbers of digital circuits in a processor including ALU such as registers, counter,

    multiplexer, decoder, adder etc. and every operation have a unique code, called Op-code. For example:

    we want to move/copy the contents of a register (say B) to the output register (say Y). The instruction

    MOV Y, B performs this operation and machine-code for this operation is 03H. The instruction-code

    00112=03H enables the register Y, register B and parallel-in parallel-out register. To generate enable signal for it, a decoder (control circuit) is used. The internal operations of the processor circuit upon

    receiving instruction code shown in figure 1.18. First, the decoder is decoding the instruction code, and

    generate enable signal at the output. Shift register and register Y and B enable signal connected to the

    decoder enable output.

  • 11

    0011 (Input)

    (Output) Enable signal to shift register

    Register B (source)

    Enable

    Register Y (destination) Figure 1.18: The internal circuit operation of a processor to execute MOV Y, B instruction

    REVIEW QUESTIONS

    1. Express decimal 167 as a binary number.

    2. Represent decimal numbers 15 and 250 in binary format.

    3. Convert Hex ABCD to binary.

    4. Add 26H+AFH.

    5. What is ALU purpose?

    6. Express 101111000001 as a hexadecimal value.

    7. Express decimal 100 as a hex number and then as a binary number.

    8. Show that if an 8-bit register contains all logic 1s then the value stored is 255.

    9. Describe the function of Mux and Demux.

    10. Design a 4-bit ALU for two arithmetic and two logic operations.

    D Q

    CLK

    D Q

    CLK

    D Q

    CLK

    D Q

    CLK

    D Q

    CLK

    D Q

    CLK

    D Q

    CLK

    D Q

    CLK

    D7 D6 D5 D4 D3 D2 D1 D0

    D7 D6 D5 D4 D3 D2 D1 D0

    Decoder

    4 24

  • 12

    CHAPTER-2 INTRODUCTION TO THE COMPUTER SYSTEM

    A digital computer is a digital electronic system which is designed to store, process, and communicate

    information in digital form. The computer systems are constructed of digital electronics. It means that

    their electronic circuits can exist in only one of two states: On or Off. Most computer electronics use voltage levels to indicate their present state. For example, a transistor with +5 volts would be considered

    "on", while a transistor with 0 volt would be considered "off."

    They are found in a wide range of applications, like process control, communication systems, digital

    instruments, weather forecasting and consumer products such as PCs, handhold calculators, mobile

    phones etc.

    How many languages do we know? Most probably more than one, but digital computer knows only a

    binary. A binary number has only two discrete values: 0 and 1. Each discrete value is represented by the

    on (1) and off (0) status of an electronic switch called a transistor. These patterns of "on" and "off" stored inside the computer, which are used to encode binary data using the binary number system. The

    binary number system is a method of storing ordinary numbers as pattern of 1's and 0's i.e. the ordinary

    decimal number 810 is stored in computer as 01002 in binary. Because of their digital nature, the

    electronics of computer can easily manipulate numbers stored in binary by treating 1 as "on" and 0 as

    "off." The digital computer has various circuits, so that it can add, subtract, multiply, divide, and can do

    many other things with numbers stored in binary. All digital computers understand only binary number patterns or binary codes. Any decimal number (base 10, with ten digits from 0 to 9) can be represented

    by a binary number (base 2, with digits 0 and 1).Its Binary codes are the digital machine language. A

    computer manipulates information in digital or more precisely in binary form.

    Computer software consists of a collection of programs that contain instructions and data to perform a

    task. All programs are written using any programming language (i.e. Assembly, C, C++, Java etc), must

    be translated into binary prior to execution by a computer because the computer is a digital device.

    Therefore, a translator is necessary to convert such a program into binary and this is achieved using a

    translator program called a compiler.

    A computer is a programmable machine. The two principle characteristics of a computer are: it responds

    to a specific set of instructions in a well-defined manner and it can execute a prerecorded list of

    instructions (a program). Modern computers are electronic and digital. The actual machinery wires,

    transistors, and circuits are called hardware. The instructions and data are called software.

    All general-purpose computers require the following hardware components:

    Memory: Enables a computer to store data and programs permanent or/and temporarily. Mass storage device: Allows a computer to permanently retain large amounts of data. Common mass storage devices include disk drives and tape drives.

    Input device: Usually a keyboard and mouse is the input device through which data and instructions enter a computer.

    Output device: A display screen, printer, or other device that lets you see what the computer has accomplished.

    Microprocessor: The brain of the computer, this is the component that actually executes instructions (processes data according to instructions).

    In addition to these components, there are many other components which make it possible for the basic

    components to work together efficiently. For example, every computer requires a bus (signal lines/wires)

    that transmits data from one part of the computer to another.

    The basic blocks of a computer, are the central processing unit (CPU) or Microprocessor(s), the RAM and

    ROM memory, and the input/output (I/O) ports or devices. The CPU or microprocessor (ALU + Reg.) of a

    computer is basically the same as the brain of a human being; so computer memory is conceptually

    similar to human memory.

    A question asked to a human being is analogous to enter a program into a computer using an input device

    such as a keyboard, touch-screen, scanner and a person answering a question is similar in concept to

    outputting the program result to a computer output device such as a printer, monitor, alarm etc.

  • 13

    The main difference is that human beings can think independently, whereas computers can responds only

    for those questions, which they are programmed (instructions) and designed (electronic circuit). So, one

    can better understand who is more intelligent?

    The computer hardware includes such components as memory, CPU, transistors, plug, socket, nuts, bolts,

    and so on. These hardware components like CPU, memory are designed for software programs. The

    programs can perform a specific task, such as addition, subtraction etc., if the computer has an electronic

    circuit capable of adding two numbers. The programmers cannot change these electronic circuits but can

    perform tasks on them using instructions.

    All units (CPU, memory, and I/O devices ) of the computer work together in synchronization to perform a

    task similar to human being, all parts of human body (brain as CPU and memory, Input units as eyes,

    ears, nose etc. and output units as human voice, hands, lags etc) work together to perform a task.

    In next paragraphs, we define some basic terms associated with microprocessor based systems.

    2.1 EXPLANATION OF TERMS RELATED TO THE MICROPROCESSOR/COMPUTERS

    Before we go on, it is necessary to understand some basic terms.

    Signal A variable parameter by which information is conveyed through an electronic circuit or wire. Digital Signal Operating by the use of discrete signals to represent data in the form of numbers. A discrete-time signal having a set of discrete values is called a digital signal. Note that sampling an analog

    signal produces a discrete-time signal. Then quantization of its values produces a digital signal.

    An Address is a pattern of 0s and 1s that represents a specific location in memory or a particular I/O device. Typical 8-bit microprocessors have 16 address lines, and, these 16 lines can produce 216 unique

    16-bit patterns from 0000 0000 0000 00002 to 1111 1111 1111 11112 (0000H to FFFFH) representing

    65,536 different address combinations/memory locations.

    An Arithmetic-logic unit (ALU) is a digital circuit that performs arithmetic and logic operations on two or

    more n-bit digital words. The value of n can be 4, 8, 16, 32, or 64 Bits. Typical computing operations

    performed by an ALU are addition, subtraction, ANDing, ORing, and comparison of two n-bit digital words.

    The size of the ALU defines the size of the microprocessor. For example, a 32-bit microprocessor

    contains a 32-bit ALU.

    The Bit is an abbreviation for the term binary digit. A binary digit can have only two values, which are 0

    and 1, whereas a decimal digit can have 10 values, represented by the symbols 0 through 9.

    A number of bits taken as a group are called a word. For example, a 32-bit microprocessor can process a

    32-bit word or 8-bit microprocessor can process an 8-bit word.

    An 8-bit word is referred to as a byte, and a 4-bit word is known as a nibble. A byte contains two nibbles.

    A bit is a single binary digit of value logic 1 or logic 0. A nibble is a group of bits, e.g. 10102 is a nibble. A

    byte is a group of 8 bits e.g. 101001112 is a byte and the byte is made up of two nibbles 10102 and

    01112.

    The Microprocessor based system consist at least a microprocessor and input/output devices and Memory.

    This is the difference between the microprocessor and the microprocessor based system (microcomputer).

    A bus consists of a number of conductors (wires) organized to provide a means of communication or data

    transfer among different elements in a microprocessor system. The conductors in a bus can be grouped in

    terms of their functions. A microprocessor normally has an address bus, a data bus, and a control bus.

    Address bits are sent to memory or to an external device on the address bus. The Instructions from

    memory, and data to/from memory or external devices, normally travel on the data bus. The Control

    signals for the other buses and among system elements are transmitted on the control bus.

    Unidirectional Bus (generally used for Address Bus) Bidirectional Bus (generally used for Data bus) Unidirectional line (generally used for Address/control line) Bidirectional line (generally used for Data/control line)

  • 14

    The Clock is analogous to `human heart beats. The microprocessor requires synchronization among its

    components, and this is provided by a clock or timing circuits i.e. the microprocessor is a synchronous

    electronic integrated circuit.

    The instruction set of a microprocessor is a list of operations/commands that the microprocessor circuit

    is designed to execute. Typical instructions are ADD, SUBTRACT, and STORE individual instructions are

    coded as unique bit patterns which are recognized and executed by the microprocessor. If a

    microprocessor has 3 bits allocated to the representation of instructions, the microprocessor will recognize

    a maximum of 23, or eight different instructions. In other word, the microprocessor will have a maximum

    of eight instructions in its instruction set. It is obvious that some instructions will be more suitable than

    others to a particular application. For example, if a microprocessor is to be used in a calculating mode, the

    instructions/operations such as ADD, SUBTRACT, MULTIPLY, DIVIDE and LOGICAL OPERATIONS would be

    desirable. In a control application, the instructions inputting digitized signals to the processor and

    outputting digital control variables to external circuits are essential. The number of instructions necessary

    in an application will directly influence the amount of hardware in the chip set and the number and

    organization of the interconnecting bus lines.

    The Pipelining is a technique that overlaps instruction fetch (instruction read) and instruction execution.

    In other word, pipelining is the fetching of current instruction and execution of the previously fetched

    instruction simultaneously. This allows microprocessors processing operation to be broken down into several steps (dictated by the number of pipeline levels or stages) so that the individual step outputs can

    be handled by the microprocessor in parallel. The Pipelining is often used to fetch the microprocessors next instruction while executing the current instruction, which speeds up the overall operation of the

    microprocessor considerably.

    The Random-access memory (RAM) is storage medium for group of bits or words whose contents can

    be read as well as altered at specific addresses (that is why it called read/write memory). A RAM normally

    provides volatile storage, which means that its contents are lost in case power is turned off. RAMs are

    fabricated on chips and have typical densities of 4096 bits to 1 megabit per chip. These bits can be

    organized in many ways: for example, as 4096 x 1 bit words or as 2048 x 2 bit words. RAMs are normally

    used for the storage of temporary data and intermediate results as well as programs that can be reloaded

    from a backup nonvolatile source. RAMs are capable of providing large storage capacity, in the megabit

    range.

    The Read-only memory (ROM) is storage medium for the group of bits called words, and its contents

    can easily read but cannot normally be altered once programmed. A typical ROM Is fabricated on a chip

    and can store, for example, 2048 eight-bit words, which can be accessed individually by presenting to it

    one of 2048 addresses. This ROM is referred to as a 2K x 8-bit ROM. 1011 01112 is an example of an 8-bit

    word that might be stored in one location in this memory. A ROM is a nonvolatile storage device, which

    means that its contents are retained in case power is turned off. Because of this characteristic, ROMs are

    used to store programs (instructions and data) that must always be available to the microprocessor.

    A register can be considered as volatile storage (RAM) for a number of bits. These bits may be entered

    into the register simultaneously (in parallel) or sequentially (serially) from right to left or from left to right,

    1 bit at a time. An 8-bit register storing the bits or 8-bit word 111100002 are represented as follows:

    1 1 1 1 0 0 0 0

    The word micro is used in electronics and in science generally, to mean one-millionth or 1 x 106. It has also entered general language to mean something very small circuit components fabricated by LSI or VLSI

    technology for example, a very small processor or microprocessor. It has also become an abbreviation

    for microprocessor, microcomputer, microprocessor-based system or a microcontroller indeed almost anything that has micro in its name. In the scientific sense, the word micro is represented by the Greek letter (mue). It was only a small step for microprocessor to become abbreviated to P.

    2.2 MICROPROCESSOR (P) In general, it is a clock driven, multipurpose, programmable, semiconductor electronic device, fabricated

    with LSI (Large Scale Integration) or VLSI (Very LSI) technology, contains several general purpose

    registers (memory elements) including special purpose register such as program counter (PC) or

    Instruction pointer and stack pointer, an ALU (arithmetic and logical unit), and a control and timing unit

    on a single chip as shown in figure 2.1. In the world of personal computers, the terms microprocessor and

    CPU are used interchangeably. One or more microprocessor typically serves as a central processing unit

  • 15

    (CPU) in a computer system or handheld device. Microprocessors made possible the advent of the

    microcomputer. At the heart of all personal computers and most working stations sits a microprocessor.

    The Microprocessors also control the logic of almost all digital devices, from handheld calculator to fuel-

    injection systems for automobiles.

    Notice that a microprocessor cannot work alone and must be interfaced with peripheral support chips

    (memory, input-output devices etc.) in order to perform a function. The Microprocessor receives

    instruction (binary code) from memory and accepts binary data input according to the command from

    memory or input device and provide the result to the output device. Actually we do not work with only

    microprocessor but a microprocessor based system (described in next topic). However, we study the

    microprocessor to work with microprocessor based system. Three basic characteristics that differentiate

    one microprocessor to other:

    Bandwidth is the number of bits processed in a single instruction. Clock speed is given in megahertz

    (MHz); the clock speed determines that how many instructions per second the processor can execute.

    In above both cases, the higher the value of BW and clock speed, the more powerful will be the CPU. For

    example, a 16-bit microprocessor that runs at 8MHz is more powerful than an 8-bit microprocessor that

    runs at 3MHz. In addition to bandwidth and clock speed, the microprocessors are classified as being either

    RISC (reduced instruction set computer) or CISC (complex instruction set computer) will discuss RISC and

    CISC later in this Chapter.

    Figure 2.1: Typical Microprocessor Block diagram

    The microprocessor system can be divided into two categories: the microprocessor based computer for

    general purpose and microprocessor based system for dedicated purpose as defined in sections 2.3 and

    2.4, respectively.

    2.3 INTRODUCTION TO MICROPROCESSOR BASED SYSTEM

    To perform a function or useful task we have to form a system by using microprocessor as a CPU and

    interfacing memory, input and output devices to it. A system designed using a microprocessor as its CPU

    is called a microcomputer.

    The Microprocessor based system (single board microcomputer) consists of a microprocessor as CPU,

    semiconductor memories like the ROM/EPROM and the RAM, input device, output device and interfacing

    devices. The memories, input device, output device and interfacing devices are called peripherals. The

    popular input devices are keyboard and compact disk (CD) and the output devices are printer, LED/LCD

    displays, CRT monitor, etc. Address bus Data bus Data bus Control bus

    Figure 2.2: A typical Architecture of the Microprocessor based Computer system

    The above block diagram (figure 2.2) shows the organization of a microprocessor based system. In this

    system, the microprocessor is the master and all other peripherals are slaves. The master controls all the

    peripherals and initiates all operations.

    The work done by the processor can be classified into the following three groups.

    Microprocessor or CPU

    PC

    Control and Timing unit

    ALU

    Registers

    Instruction

    Decoder

    Input/output Port/Device (Peripherals)

    ADC/DAC

    A0-An-1

    Microprocessor

    (CPU)

    D0-Dn-1 I/OW I/OR MW MR

    ROM RAM Outside Real World (Analog) To/From

  • 16

    1. Work done internal to the processor

    2. Work done external to the processor

    3. Operations initiated by the slaves or peripherals.

    The work done internal to the processor is addition, subtraction, logical operations, data transfer

    operations, etc. The work done external to the processor are reading/writing the memory and

    reading/writing the I/O devices or the peripherals. If the peripheral requires the attention of the master

    then it can interrupt the master and initiate an operation. The microprocessor is the master, which

    controls all the activities of the system.

    To perform a specific job or task, the microprocessor has to execute a program stored in memory. The

    program consists of a set of instructions. It issues address and control signals and fetches the instruction

    and data from memory. The instruction is executed one by one internally to the microprocessor and based

    on the result it takes appropriate action.

    Buses

    The buses are group of lines that carries data, address or control signals.

    The CPU or system bus has multiplexed lines, i.e., same lines are used to carry data and address signals.

    The CPU and memory interface is provided by de-multiplexing of the multiplexed address/data lines;

    generation of the memory chip select signal and additional control signals.

    The system bus has separate lines for each signal.

    All the slave peripherals in the system are connected to the same system bus. At any time instant

    communication takes place between the master and one of the slaves, all other slaves have tri-state logic

    and hence normally remain in high impedance state when not in use. Only when the slave is selected it

    comes to the normal logic.

    Peripheral Devices

    1. The EPROM memory is used to store permanent programs and data.

    2. The RAM memory is used to store temporary programs and data.

    3. The input device is used to enter the program, data and to operate the system.

    4. The output device is used for examining the results.

    Since, speed of the I/O devices does not match with the speed of processor, an interface device is

    provided between the system bus and the I/O devices. Generally I/O devices are slow devices.

    Advantages of Microprocessor based system

    1. Computational/processing speed is high.

    2. Intelligence has been brought to systems, automation in the industrial processes and office

    administration.

    3. Since the devices are programmable, there is flexibility to alter the system by changing the

    software program alone.

    4. Less number of components, compact in size, more reliable and low cost.

    5. Operation and maintenance are easier.

    Disadvantages of Microprocessor based System

    1. It has limitations on the size of data.

    2. The applications are limited due to the limited physical memory address space.

    3. The analog signals cannot be processed directly and digitizing the analog signals introduces errors.

    4. The speed of execution is slow (when external access is used) and hence real time applications are

    not well performed.

    5. Most of the microprocessors do not support floating point operations.

    2.4 MICROCONTROLLER (C) The microcontroller is a complete microcomputer system on a single-chip that contains all the components

    comprising a controller. Typical microcontrollers include a microcomputer (microprocessor, memory and

    I/O port), timers, A/D (analog-to- digital) and D/A (digital to analog) converters, all on a single chip, as

    shown in figure 2.3. Unlike a general-purpose computer which is also includes all of these components, a

    microcontroller is designed for a very specific task - to control a particular system. A microcontroller is

    meant to be more self-contained and independent, and functions as a tiny, dedicated computer. The great

    advantage of microcontrollers, as opposed to using larger microprocessors, is that the parts-count and

    design costs of the item being controlled, can be kept to a minimum. Now, they are designed using CMOS

    (complementary metal oxide semiconductor) technology. The microcontrollers are sometimes called

  • 17

    embedded microcontrollers, which just mean that they are part of an embedded system. Microcontrollers

    are typically used for dedicated applications or smart machines such as automotive systems, home

    appliances, and home entertainment systems. Examples of typical microcontrollers are the Intels 8051, Motorolas 6811, Zilogs Z8 and PIC (peripheral interface controller) 16xx from Microchip Technology.

    Figure 2.3: A typical block diagram of a microcontroller with its internal components

    Microcontrollers Vs Microprocessors 1. Microprocessors

    Targeted for high end of market where performance matters.

    High power dissipation.

    Almost all instructions are byte handling; only one or two instructions are bit handling in a

    microprocessor.

    High cost.

    Need peripheral devices to work.

    Mostly used in microcomputers or General Purpose.

    A microprocessor requires an external memory for program/data storage. Instruction execution requires

    movement of data from the external memory to the microprocessor or vice versa. Usually,

    microprocessors have good computing power and they have higher clock speed to facilitate faster

    computation.

    2. Microcontrollers

    Targeted for low end of market where performance does not matter

    Low power dissipation.

    Low cost.

    Bit handling instructions are in vicinity in microcontroller i.e. Microcontrollers have many bit-

    handling instructions, while microprocessor has one or two.

    Microprocessor, memory and serial/ parallel ports, all integrated into single chip, that is why its a

    complete computer on a chip.

    A microcontroller does not require much additional interfacing ICs for operation and it functions as a

    standalone system. Mostly used in embedded systems or real time, dedicated systems. The operation of a

    microcontroller is multipurpose and application specific. A microcontroller has required on-chip memory

    with associated peripherals.

    2.5 COMPUTER ARCHITECTURES Some important computer/microprocessor architectures are defined in the following paragraphs:

    Complex-instruction-set computer (CISC) was popular in 1970s, since the program memory was

    slow, designers tried to improve performance by constructing complex and large instruction set. Each

    Instruction

    Decoder

    RTC

    Microcontroller

    (Single IC)

    Timer and counter A/D and D/A converter

    Microcomputer

    Microprocessor (CPU)

    Control and Timing unit

    ALU

    Registers

    I/O Ports Memory (ROM and RAM)

  • 18

    complex instruction took several clock cycles, while data flow path control words for each clock cycle were

    stored in a much faster micro program memory as shown in figure 2.4. The concept of micro programming

    allowed for emulation of arbitrary instruction sets and creation of specialized instructions, while speeding

    up the execution. It is difficult to pipeline compared to RISC. Large instruction set helps assembly

    language programmers by providing flexibility to write effective and short program. CISC processor

    support many addressing modes for the memory access and data transfer instructions. The Intel

    8085/80X86, Motorolas 68000 microprocessor are based on CISC.

    Figure 2.4: The CISC architecture

    Reduced-instruction-set computer (RISC) became popular in late 1980s by eliminating complex

    instructions and the micro program memory. The RISC architecture maximizes speed by reducing clock

    cycles per instruction and makes it easier to implement pipelining. All instructions in a RISC are simple

    and execute in one clock cycle allowing Data flow path to be efficiently pipelined in few pipelined stages.

    The micro program memory was replaced with micro instruction decoding stage that followed the

    instruction fetch from Program Memory as shown in figure 2.5. Since instructions are simpler, a RISC

    needs approximately two instructions for each complex instruction and, therefore, the size of the Program

    Memory is approximately doubled. However, the Fetch- Decode-Execute-Store pipeline of the whole

    processor improved the execution speed several times. Power PC and PIC microcontroller are the example

    of RISC architecture. Intels 80X86 Pentium microprocessors families are CISC based, although RISC type functionality has been incorporated into Pentium CPUs. Sun Microsystemss SPARC microprocessor, MIPS R 2000, R 3000 and R 4000 families dominate the RISC end of the market. However, Digital signal

    processors are in wide used in Motorolas Power PC, G4, Intels i860, and analog devices INCs. In the PC/workstation market, Apple computers and Sun employs RISC microprocessors as their choice of CPU.

    Figure2.5: The RISC architecture

    Table 2.1: CISC versus RISC architecture

    CISC (Complex Instruction Set Computer) RISC (Reduced Instruction Set Computer ) Large Instruction set Compact Instruction set

    Complex, powerful instruction Simple hard wired machine code and control Unit

    Instructions sub-commands micro-coded in on board ROM Pipelining of instructions

    Compact and versatile register set Numerous registers

    Numerous memory addressing operations for operands Compiler and IC developed simultaneously

    2.6 MEMORY ARCHITECTURE

    Von - Neumann or Princeton Memory Architecture

    Instruction pointer

    PROGRAM

    MEMORY

    (Instructions)

    Instruction register

    DATA

    MEMORY

    Timing and

    control for data

    flow path

    Instruction

    decoder

    Instruction

    Pointer (PC)

    PROGRAM

    MEMORY

    (Instructions)

    Microinstruction generator (1 instruction = m micro instruction)

    Micro-program

    memory

    (Micro-instruction)

    DATA

    MEMORY

    Timing and

    control for data

    flow path

    Micro-

    instruction

    decoder

  • 19

    The Von Neumann Architecture is named after the mathematician and early computer scientist John

    Von Neumann. The Von Neumann machines have shared signals and memory for code and data. Thus, the

    program can be easily modified by itself since it is stored in read-write memory. There are no separate

    instructions to provide separate control signals for data transfer from/to program and data memory as

    shown in figure 2.6. For example, the 8085/86 microprocessors.

    Both memories share same address and data lines

    Figure 2.6: The von-Neumann memory architecture

    In Harvard Memory Architecture (shown in figure 2.7), there are separate memories for program and

    data with their distinct address and data bus. Both memory organizations have separate control signal as

    separate instructions are used for data transfer from/to program and data memory. It is possible to access

    program memory and data memory simultaneously. Microcontrollers are characterized by having small

    amounts of program (flash memory) and data (SRAM) memory, with no cache, and take advantage of the

    Harvard architecture to speed processing by concurrent instruction and data access. The separate storage

    means the program and data memories can have different bit depths, for example using 16-bit wide

    instructions (in program memory) and 8-bit wide data (in data memory). They also mean that instruction

    pre-fetch can be performed in parallel with other activities. Examples include, the AVR by Atmel Corp,

    the PIC by Microchip Technology, Inc. , Intel 8051 microcontroller series and the ARM Cortex-M3

    processor (not all ARM chips have Harvard architecture).

    Both memories use different address and data lines

    Figure 2.7: Harvard memory architecture

    Princeton versus Harvard memory Architecture Many years ago, in the late 1940's, the US Government asked Harvard and Princeton universities to come

    up with a computer architecture to be used in computing distances of Naval artillery shell for defense

    applications. Princeton suggested computer architecture with a single memory interface. It is also known

    as Von Neumann architecture after the name of the chief scientist of the project in Princeton University

    John Von Neumann (1903 1957 Born in Budapest, Hungary). Harvard suggested a computer with two different memory interfaces, one for the data / variables and the

    other for program / instructions. Although Princeton architecture was accepted for simplicity and ease of

    implementation, Harvard architecture became popular later, due to the parallelism of instruction

    execution.

    The Von Neumann architectures CPU can be either reading an instruction Op-code from program memory or reading/writing a data from/to the data memory. Both reading and writing operation cannot occur at

    the same time since the instructions and data use the same bus system. On the other hand, the CPU with

    Harvard architecture can both read an instruction op-code from program memory and perform a data

    memory access at the same time, even without a cache. A Harvard architecture computer can thus be

    faster for a given circuit complexity because instruction fetches and data access do not contend for a

    single memory path way. Also, a Harvard architecture machine has distinct code for instruction and data

    address spaces: instruction address zero is not the same as data address zero. Instruction address zero

    might identify a 16- bit value, while data address zero might indicate an 8- bit byte that is not part of that

    twenty-four bit value.

    2.7 THE 8, 16 AND 32-BIT MICROCONTROLLERS

    The 8-Bit Microcontroller

    Program and Data Memory

    CPU

    Program Memory

    CPU

    Data Memory

  • 20

    When the ALU performs arithmetic and logical operations on a byte (8-bits) at an instruction, the

    microcontroller is an 8-bit microcontroller. The internal bus width of 8-bit microcontroller is of 8-bit.

    Examples of 8-bit microcontrollers are Intel 8051 family and Motorola MC68HC11 family.

    The 16-Bit Microcontroller

    When the ALU performs arithmetic and logical operations on a word (16-bits) at an instruction, the

    microcontroller is an 16-bit microcontroller. The internal bus width of 16-bit microcontroller is of 16-bit.

    Examples of 16-bit microcontrollers are Intel 8096 family and Motorola MC68HC12 and MC68332 families.

    The performance and computing capability of 16 bit microcontrollers are enhanced with greater precision

    as compared to the 8-bit microcontrollers.

    The 32-Bit Microcontroller

    When the ALU performs arithmetic and logical operations on a double word (32- bits) at an instruction, the

    microcontroller is an 32-bit microcontroller. The internal bus width of 32-bit microcontroller is of 32-bit.

    Examples of 32-bit microcontrollers are Intel 80960 family and Motorola M683xx and Intel/Atmel 251

    family. The performance and computing capability of 32 bit microcontrollers are enhanced with greater

    precision as compared to the 16-bit microcontrollers.

    REVIEW QUESTIONS 1. Why do computers use the binary number system instead of the decimal number system? 2. Differentiate Hardware and Software? 3. What are the RAM and ROM? 4. Why is RAM called volatile memory? 5. Why synchronous digital circuit needs a clock signal? 6. What is the function of Bus? 7. What do you mean by instruction and instruction set? 8. What is a Microprocessor? 9. What is the difference between a Microprocessor and a Microcomputer? 10. Differentiate between microprocessors and microcontroller in one line. 11. Define bit, byte, nibble and word. 12. Which type of memory architecture of the 8051 has? 13. What does it mean by embedded system? 14. What is the difference between microprocessor and CPU? 15. Compare RISC and CISC. 16. Differentiate Von-neumann and Harvard memory architecture. 17. Draw the typical block diagram of a microprocessor, Microcomputer and microcontroller. 18. What do you mean by the power of a Microprocessor? Mention the Architectural Parameters to distinguish

    between Microprocessors. 19. Explain the organization of microprocessor based system with its block diagram. 20. Give at least three examples for embedded system. 21. What is the advantage of separate data and program memory (Harvard memory architecture)?

  • 21

    CHAPTER-3 INTRODUCTION TO MICROCONTROLLER, EMBEDDED PROCESSOR AND SYSTEM

    Even though often nearly invisible, embedded systems are everywhere. Embedded systems are present in

    many industries, including industrial automation, defense, transportation, our home and aerospace. For

    example, NASAs Mars Path Finder, ISROs Mars Orbiter mission, missile guidance system, electronic appliances, and the automobile all contain numerous embedded systems. Every day, people throughout

    the world use embedded systems without even knowing it. In fact, the embedded systems invisibility is its

    very beauty: users reap the advantages without having to understand the intricacies of the technology.

    Remarkably adaptable and versatile, embedded systems can be found at home, at work, and even in

    recreational devices. Indeed, it is difficult to find a segment of daily life that does not involve embedded

    systems in some way.

    INTRODUCTION TO MICROCONTROLLER

    Microcontroller is a programmable digital processor with necessary peripherals. In other words, we can

    say that a microcontroller is an entire computer manufactured on a single chip. Both microcontrollers and

    microprocessors are complex sequential digital circuits meant to carry out job according to the program /

    instructions.

    Microcontrollers are usually dedicated devices embedded within an application. For example,

    microcontrollers are used as engine controllers in automobiles and as exposure and focus controllers in

    cameras. In order to serve these applications, they have a high concentration of on-chip facilities such as

    serial ports, parallel input-output ports, timers, counters, interrupt control, analog-to-digital converters,

    random access memory, read only memory, etc. The I/O, memory, and on-chip peripherals of a

    microcontroller are selected depending on the specifics of the target application. Since microcontrollers are

    powerful digital processors, the degree of control and programmability they provide significantly enhances

    the effectiveness of the application.

    Embedded control applications also distinguish the microcontroller from its relative, the general-purpose

    microprocessor. Embedded systems often require real-time operation and multitasking capabilities. Real-

    time operation refers to the fact that the embedded controller must be able to receive and process the

    signals from its environment as they are received. That is, the environment (temperature of a furnace)

    must not wait for the controller to become available. Similarly, the controller must perform fast enough to

    output control signals to its environment when they are needed. Again, the environment must not wait for

    the controller.

    EMBEDDED PROCESSOR AND APPLICATION AWARENESS

    The processors found in common personal computers (PC) are general-purpose or universal processors

    such as Intels x86, Power PC microprocessor, AMD processor etc. They are complex in design because these processors provide a full scale of features and a wide spectrum of functionalities.

    They are designed to be suitable for a variety of applications. The systems using these universal

    processors are programmed with a multitude of applications. For example, modern processors have a

    built-in memory management unit (MMU) to provide memory protection and virtual memory for

    multitasking-capable, general-purpose operating systems. These universal processors have advanced

    cache logic. Many of these processors have a built-in math co-processor capable of performing fast

    floating-point operations. These processors provide interfaces to support a variety of external peripheral

    devices. These processors result in large power consumption, heat production, and size. The complexity

    means these processors are also expensive to fabricate. In the early days, embedded systems were

    commonly built using general-purpose processors.

    Because of the great improvement in advancements made in microprocessor technology in recent years,

    embedded systems are increasingly being built using embedded processors instead of general-purpose

    processors. These embedded processors are special-purpose processors designed for a specific class of

    applications. The key is application awareness, i.e., knowing the nature of the applications and meeting

    the requirement for those applications that it is designed to run.

    One class of embedded processors focuses on size, power consumption, and price. Therefore, some

    embedded processors are limited in functionality, i.e., a processor is good enough for the class of

    applications for which it was designed but is likely inadequate for other classes of applications. This is one

    reason why many embedded processors do not have fast CPU speeds. For example, the processor chosen

    for a personal digital assistant (PDA) device does not have a floating-point co-processor because floating-

    point operations are either not needed or software emulation is sufficient. The processor might have a 16-

    bit addressing architecture instead of 32-bit, due to its limited memory storage capacity. It might have a

  • 22

    200MHz CPU speed because the majority of the applications are interactive and display-intensive, rather

    than computation-intensive. This class of embedded processors is small because the overall PDA device is

    slim and fits in the palm of our hand. The limited functionality means reduced power consumption and

    long-lasting battery life. The smaller size reduces the overall cost of processor fabrication.

    On the other hand, another class of embedded processors focuses on performance. These embedded

    processors are powerful and packed with advanced chip-design technologies, such as advanced pipeline

    and parallel processing architecture. These processors are designed to satisfy those applications with

    intensive computing requirements not achievable with general-purpose processors. An emerging class of

    highly specialized and high-performance embedded processors includes network processors developed for

    the network equipment and telecommunications industry. Overall, system and application speeds are the

    main concerns.

    Yet another class of embedded processors focuses on all four requirements performance, size, power

    consumption, and price. Take, for example, the embedded digital signal processor (DSP) used in cell

    phones. Real-time voice communication involves digital signal processing and cannot tolerate delays. A

    DSP has specialized arithmetic units, optimized design in the memory, and addressing and bus

    architectures with multiprocessing capability that allow the DSP to perform complex calculations extremely

    fast in real time. A DSP outperforms a general-purpose processor running at the same clock speed many

    times over comes to digital signal processing. These reasons are why DSPs, instead of general-purpose

    processors, are chosen for cell phone designs. Even though DSPs are incredibly fast and powerful

    embedded processors, they are reasonably priced, which keeps the overall prices of cell phones

    competitive. The battery from which the DSP draws power lasts for hours and hours.

    System-on-a-chip (SoC) processors are especially attractive for embedded systems. The SoC processor is

    comprised of a CPU core with built-in peripheral modules, such as a programmable general-purpose timer,

    programmable interrupt controller, DMA controller, and possibly Ethernet interfaces. Such a self-contained

    design allows these embedded processors to be used to build a variety of embedded applications without

    needing additional external peripheral devices, again reducing the overall cost and size of the final

    product. Sometimes a gray area exists when using processor type to differentiate between embedded and

    non-embedded systems. It is worth noting that, in large-scale, high-performance embedded systems; the

    choice between embedded processors and universal microprocessors is a difficult one.

    SELECTING THE RIGHT MICROCONTROLLER UNIT

    What criteria