PG - M.sc. - Physics - 34533 Microprocessor and Electronic Instrumentation
PG - M.sc. - Physics - 34533 Microprocessor and Electronic Instrumentation
M.Sc. PHYSICS
III -SEMESTER
34533
MICROPROCESSOR AND
ELECTRONIC INSTRUMENTATION
Author
Dr. M. Ramesh Prabhu, M.Sc, Ph.D.,
Assistant Professor
Department of Physics
Alagappa University
Karaikudi– 630003.
(Units: 8-14)
All rights reserved. No part of this publication which is material protected by this copyright notice
may be reproduced or transmitted or utilized or stored in any form or by any means now known or
hereinafter invented, electronic, digital or mechanical, including photocopying, scanning, recording
or by any information storage or retrieval system, without prior written permission from the
Alagappa University, Karaikudi, Tamil Nadu.
SYLLABI-BOOK MAPPING TABLE
MICROPROCESSOR AND ELECTRONIC INSTRUMENTATION
1.1 Introduction
1.2 Intel 8085
1.3 Architecture of Intel 8085
1.4 Timing Diagram
1.4.1 Timing Diagram for opcode fetch cycle of 8085
1.4.2 Timing Diagram for memory read cycle
1.4.3 Timing diagram for memory write cycle
1.5 I/O read and I/O write
1.6 Instruction set
1.6.1 Instruction and data formats
1.7 Addressing modes of 8085
1.8 Status flags
1.9 Instruction set classification
1.9.1 Data transfer
1.9.2 Arithmetic operations
1.9.3 Logical operations
1.9.4 Branching operations
1.9.5 Interrupts
2.1 Introduction
2.2 Architecture of 8086
2.3 8086 pin diagram
2.3.1 Pin description and functions
2.4 Register organization
2.5 Maximum mode function of 8086
2.6 Minimum mode system
7.1 Introduction
7.2 Address space partitioning
7.2.1 Memory mapped I/O scheme
7.2.2 I/O mapped I/O scheme
7.3 Interfacing devices
7.3.1 Memory interfacing
7.3.2 I/O interfacing
7.4 Data transfer schemes
7.4.1 Serial I/O mode transfer
7.4.2 Parallel data transfer scheme
7.4.2.1 Programmed data transfers
7.4.2.2 DMA data transfer scheme
7.5 Interrupts
7.6 I/O ports
UNIT VIII – INTERFACING DEVICES (8255 AND 8259) 74-83
12.1 Introduction
12.2 Classification of transducers
Structure
1.1 Introduction
1.2 Intel 8085
1.3 Architecture of Intel 8085
1.4 Timing Diagram
1.4.1 Timing Diagram for opcode fetch cycle of 8085
1.4.2 Timing Diagram for memory read cycle
1.4.3 Timing diagram for memory write cycle
1.5 I/O read and I/O write
1.6 Instruction set
1.6.1 Instruction and data formats
1.7 Addressing modes of 8085
1.8 Status flags
1.9 Instruction set classification
1.9.1 Data transfer
1.9.2 Arithmetic operations
1.9.3 Logical operations
1.9.4 Branching operations
1.9.5 Interrupts
1.1 INTRODUCTION
Microprocessor is a controlling unit of a micro-computer, fabricated on
a small chip capable of performing ALU (Arithmetic Logical Unit) operations
and communicating with the other devices connected to it. Microprocessor
consists of an ALU, register array, and a control unit. ALU performs
arithmetical and logical operations on the data received from the memory or an
input device. Register array consists of registers identified by letters like B, C,
D, E, H, L and accumulator (A). The control unit controls the flow of data and
instructions within the microprocessor.8085 is pronounced as "eighty-eighty-
five" microprocessor. It is an 8-bit microprocessor designed by Intel in 1977
using NMOS technology. It has the following configuration:
Registers:
Registers:- It is basically a collection of flip flops used to store a binary word.
They are used by themicroprocessor or by the users for the temporary storage
of data, manipulation of data and instructions.8085 has the following registers:
1-8 bit accumulator i.e. register A.
2
8085 Architecture
Address-Data bus
NOTES
AD7-AD0, it carries the least significant 8-bit address and data in Multiplexed
mode.
WR: This signal indicates that the data on the bus is written into a selected
memory or IO device.
IO/M
This signal is used to differentiate between IO and Memory operations, i.e.
when it is high; it indicates IO operation and when it is low then it indicates
memory operation.
Self- Instructional Material
3
8085 Architecture
S1 & S0
NOTES
These signals are used to identify the type of current operation. For example, if
both S1 and S0 are 1, then it implies ― FETCH‖ operation and if both S1 and
S0 are 0, then it meant for ―HALT‖.
Power supply
There are 2 power supply signals: VCC & VSS.
VCC indicates +5v power supply and VSS indicates ground signal.
Clock signals
There are 3 clock signals, i.e. X1, X2, CLK OUT.
X1, X2: A crystal (RC, LC N/W) is connected at these two pins and is
used to set frequency of the internal clock generator. This frequency is
internally divided by 2.
CLK OUT: This signal is used as the system clock for devices
connected with the microprocessor.
RESET IN: This signal is used to reset the microprocessor by setting the
program counter to zero.
RESET OUT: This indicates that the CPU is being reset and this signal is
also used to reset all the connected devices when the microprocessor is reset.
READY: This signal indicates that the device is ready to send or receive
data. If READY is low, then the CPU has to wait for READY to go high.
HOLD: This signal indicates that another device is requesting the use of the
address and data buses.
HLDA (HOLD Acknowledge): It indicates that the CPU has received the
HOLD request and it will relinquish the bus in the next clock cycle. HLDA is
set to low after the HOLD signal is removed.
Self- Instructional Material There are 2 serial signals, i.e. SID and SOD.These signals are used for serial
communication between the microprocessor and the peripherals.
4
SOD (Serial output data line): The output SOD is set/reset as specified by the
8085 Architecture
SID (Serial input data line): The data on this line is loaded into the
accumulator whenever a RIM instruction is executed.
Stack pointer-SP
Stack is a sequence of memory locations defined by the programmer in LIFO
(Last In First Out) logic.That is last data to be placed in the stack is the first
one to be removed.The stack pointer –SP register contains the address of the
stack top. It indicates the address of the data filled-up location. The address of
the next available location is SP+1.
Program counter-PC
It is the address of the next instruction to be executed.
Instruction register
It holds a copy of the current instruction until it is decoded. It is not accessed
by the user.
7
8085 Architecture If the length of the instruction is three bytes, it needs three machine cycles
NOTES (M1, M2 and M3). For example, LXI D, 2500H instruction needs three machine
cycles, to fetch the opcode, to read 8LSB of the data and to read 8MSB of the data. In
the case of LDA 2500H, 4 machine cycles are needed to fetch the opcode, to read
8LSB of the address, to read 8MSB of the address and to transfer the content of the
address to the Accumulator
Machine Period/ Signal Functions
Cycle Clock
M2 T1 IO/M = 0 – Address in the A15-A8 (MSB) and AD7-
AD0 (LSB) Bars meant for Memory Address.
A15- Carries 8 MSB bits
A8
AD7- Carries 8 LSB bits, it works in multiplexed
AD0 mode.
ALE = 1 – Address Latch Enable helps to latch
AD7-AD0 (8 – LSB) either in the memory or in
an external latch in order to make AD7-AD0
available to transfer data in the next clock.
S1 and S1=1 and S0=0 meant for Read Operation
S0
RD = 1 means no read operation.
T2 IO/M = 0 – Address/Data in the A15-A8 (MSB) and
AD7-AD0 (LSB) Bars meant for Memory
Address
A15- Carries 8 MSB Address bits
A8
AD7- Carries 8 bits data, here data. Memory gets
AD0 opcode from the register and places it on this
bus.
ALE =0
S1 and S1=1 and S0=0 meant for Read Operation
S0
RD = 0. It enables the memory for read operation
and data is placed in the data bus.
T3 IO/M = 0 – Address in the A15-A8 (MSB)
A15- Carries 8 MSB Address bits
A8
AD7- Carries 8 bits data, it is placed in the CPU.
AD0
ALE =0
S1 and S1=1 and S0=0 meant for Read Operation
S0
RD = 1 means memory is disabled. The read
Self- Instructional Material operation is completed and the data is placed in
the CPU.
8
8085 Architecture
1.4.3 TIMING DIAGRAM FOR MEMORY WRITE CYCLE
NOTES
In a memory write cycle the CPU sends data from the accumulator or
any other register to memory.
The status signal S0 and S1 are 1 and 0 respectively for write
operation.
The WR signal goes low in T2 indicating that the write operation is to
be performed.
During T2 the address/data bus is not disabledas in fetch or read
operation but the data to be sent out to memory is placed on the
address/data bus which works under multiplexed mode.
In T3, the WR signal goes high indicating that the write operation is
completed.
Example: - 1. MOV M, A and 2. STA 2400H
or IO port.
9
8085 Architecture
1.6 INSTRUCTION SET
NOTES
8085 instruction set generally consists of the following types:
• Data transfer instructions.
Intel 8085 is an 8-bit microprocessor and canhandles 8-bit data. All the
memory locationsare designed to store 8-bit data. For, 16-bit data, consecutive
memory locations are used. The address of memory location is of 16-bit i.e. 2
bytes.
10
8085 Architecture
Two-Byte instruction
NOTES
In case of two byte instruction the 1st byte of the instruction is opcode
and 2nd byte is either data or address. Both bytes should be stored in two
consecutive memory locations.
Ex-MVI C, 05; Move the data 05 to register C
MVI C,05 in the code form is 0E 05. The 1st byte i.e. 0E is the opcode for
MVI C and 2nd byte i.e. 05 is the data which is to be moved to register C.
Three-Byte instruction
The three byte instruction has the 1st byte as opcode and 2nd and 3rd
bytesare either 16-bit data or 16-bit address. They should be stored in three
consecutive memory locations.
Ex- LDA 2500H, Load the accumulator with the content of the memory
location, 2500H
In code form is 3A, 00, 25
The 1st byte, 3A is the opcode for LDA. The 2nd byte, 00 is 8 LSBs of
addressand the 3rd byte, 25 is 8 MSBs ofaddress.
a) Direct addressing
b) Register addressing
c) Register indirect addressing
d) Immediate addressing
e) Implicit addressing
11
8085 Architecture
source of the data and the destination for the data are explicitly given in these
NOTES
instructions.
Ex: 1. MOV B, A and 2. ADD C. In the example 1, the content of the register
A will be moved to the register B. The opcode for this operation is 47H. It
specifies the operation as well as the operands. In the example 2, the content of
the register C will be added to the content of the register A and the result will
be stored in the register A. The opcode for this operation is 81H. Again, this
opcode specifies the operands and the operation.
For example: LXI H, 2100H - Load the H-L register pair with the content of
2100H
MOV A,M – Move the content of 2100H to the accumulator
ADD C – Add the content of the register C with A, Now
A=A+C
HLT – Halt
In the above example, the instruction MOV A, M lists under register
indirect addressing mode.
12
8085 Architecture
Example: 1. MVI A,05H - Move immediate data 05H to Accumulator.
NOTES
2. ORI 05H – Perform logical OR with data 05H and the
content of the register A
Carry Flag
It holds carry out of the MSB resulting from the execution of an
arithmetic operation.If there is a carry from addition ora borrow from
subtraction or comparison, the carry flag is set to 1 otherwise 0.
Sign Flag
It is set to 1 if the MSB of the result of arithmetic or logical operation
is 1 otherwise 0.
Zero Flag
It is set to 1 if the result of an arithmetic or logical operation is 0
otherwise 0 for non-zero result.
Parity Flag
The result of the operation contains even number of 1sset this flag to 1
otherwise 0 for odd number of 1s.
13
8085 Architecture
Auxiliary Carry Flag
NOTES
It holds carry from bit 3 to 4 resulting from the execution of an
arithmetic operation otherwise 0.
Types Examples
1. Between Registers. 1. Copy the content of the register B
into
register D. MOV D, B
2. Specific data byte to a register or a 2. Load register B with the data byte
memory location. 32H.
MVI B, 32H
3. Between a memory location and a 3. From a memory location 2000H to
register. register
B.MOV B, M
4. Between an I/O device and the 4.From an input port to the
accumulator. accumulator.
IN 02
14
8085 Architecture
Addition - Any 8-bit number, or the content of a register or the content of a
memory location can be added to the content of the accumulator and the sum NOTES
is stored in the accumulator. No two other 8-bit registers can be added directly
(e.g., the content of register B cannot be added directly to the content of the
register C). The instruction DAD is an exception; it adds 16-bit data directly in
register pairs.
Subtraction - Any 8-bit number, or the content of a register, or the content of
a memory location can be subtracted from the content of the accumulator and
the result is stored in the accumulator. The subtraction is performed in 2's
compliment, and the results if negative, are expressed in 2's complement. No
two other registers can be subtracted directly.
Increment/Decrement - The 8-bit content of a register or a memory location
can be incremented or decremented by 1. Similarly, the 16-bit content of a
register pair (such as BC) can be incremented or decremented by 1. These
increment and decrement operations differ from addition and subtraction in an
important way; i.e., they can be performed in any one of the registers or in a
memory locations.
16
8086 Architecture
UNIT – II 8086 ARCHITECTURE NOTES
Structure
2.1 Introduction
2.2 Architecture of 8086
2.3 8086 pin diagram
2.3.1 Pin description and functions
2.4 Register organization
2.5 Maximum mode function of 8086
2.6 Minimum mode system
2.1 INTRODUCTION
A microprocessor is an Integrated Circuit with all the functions of a
CPU however; it cannot be used stand-alone since unlike a
microcontroller it has no memory or peripherals.8086 does not have a
RAM or ROM inside it. It is a 16-bit Microprocessor (μp).
It‘s ALU, internal registers works with 16bit binary word. 8086 has a
20 bit address bus and can access up to 220= 1 MB memory locations.
8086 has a 16bit data bus. It can read or write data to a memory/port
either 16bit or 8 bit at a time. It can support up to 64K I/O ports. It
provides 14 numbers of 16 -bit registers.
Clock frequency range of 8086 is 6-10 MHz. It has multiplexed
address and data bus AD0- AD15 and an address bus A16 – A19. It
requires single phase clock with 33% duty cycle to provide internal
timing.
It can prefetch up to 6 instruction bytes from memory and queues them
in order to speed up the instruction execution. It requires +5V power
supply and built in a 40 pin dual in line package.
8086 is designed to operate in two modes, Minimum mode and
Maximum mode. The minimum mode is selected by applying logic 1
to the MN / input pin.
This is a single microprocessor configuration. The maximum mode is
selected by applying logic 0 to the MN / input pin. This is capable
of cascading with multi microprocessors configuration.
17
8086 Architecture
NOTES
18
8086 Architecture
Clock signal
NOTES
Clock signal is provided through pin19. It provides timing to the
processor for operations. Its clock frequency is different for different
versions, i.e. 5MHz, 8MHz and 10MHz.
Address/data bus and Address/status bus
Pins AD0-AD15are 16 bit address/data bus. AD0-AD7 carries low
order byte data and AD8-AD15 carries higher order byte data. During the
first clock cycle, it carries 16-bit address and after that it carries 16-bit data
once low order byte is latched in the memory.
Pins A16-A19/S3-S6arethe 4 bit address/status bus. During the first
clock cycle, it carries 4-bit address and later it carries status signals.
S7/ and
BHE stands for Bus High Enable. It is available at pin 34 and used to
indicate the transfer of data using data bus D8-D15. This signal is low during
the first clock cycle, thereafter it is active. The status signal S7 is available
during T2, T3 and T4.
It is available at pin 32 and its value is 0 during Read operation.
READY and RESET
It is available at pin 22. It is an acknowledgement signal from I/O
devices to the microprocessor for data transfer. It is an active high signal.
When it is high, it indicates that the device is ready to transfer data. When it
is low, it indicates wait state.
It is available at pin 21 and is used to restart the execution. It causes
the processor to immediately terminate its present activity. This signal is
active high for the first 4 clock cycles to RESET the microprocessor.
INTR and INTA
It is available at pin 18. It is an interrupt request signal from the I/O
devices, which is sampled during the last clock cycle of each instruction to
determine if there is any interrupt request or not.
It is an interrupt acknowledgement signal and is available at pin 24.
When the microprocessor receives this signal, it acknowledges the interrupt
by raising this signal to 1.
NMI
It stands for non-maskable interrupt and is available at pin 17. It is an
edge triggered input, which causes an interrupt request to the microprocessor.
19
8086 Architecture This signal is like wait state and is available at pin 23. When this
NOTES
signal is high, then the processor has to wait in IDLE state, else the execution
continues.
MN/
It stands for Data Enable and is available at pin 26. It is used to enable
Trans-receiver 8286. The trans-receiver is a device used to separate data from
the address/data bus.
It stands for Data Transmit/Receive signal and is available at pin 27. It
decides the direction of data flow through the trans-receiver. When it is high,
data is transmitted out and vice-a-versa.
M/
0 0 No operation
20
8086 Architecture
NOTES
It stands for write signal and is available at pin 29. It is used to write
the data into the memory or to the output device depending on the status of
M/ signal.
LOCK
S2 S 1 S0 Status
0 0 0 Interrupt acknowledgement
0 0 1 I/O Read
0 1 0 I/O Write
0 1 1 Halt
1 0 0 Opcode fetch
Self- Instructional Material
1 0 1 Memory read
21
8086 Architecture
1 1 0 Memory write
NOTES
1 1 1 Passive
22
8086 Architecture
Segment Registers
NOTES
Intel 8086 is byte organized. Here 1 MB of memory is divided into 16
logical segments. Each segment contains 64 kilobytes of memory.
There are four segment register in 8086; Code segment register (CS),
Data segment register (DS), Extra segment register (ES) and Stack
segment register (SS). Code segment register (CS) points out the
starting address of the code segment memory, where the executable
program is stored.
Data segment register (DS): points the starting address of the data
segment of the memory where the data is stored. Extra Segment
Register (ES) also points the starting address of the extra segment
memory locations. These registers act as base registers.
Stack Segment Register (SS)
By default, the processor assumes that all data referenced by the stack
pointer (SP) and base pointer (BP) registers is located in the stack segment.
SS register can be changed directly using POP instruction. It is used for
addressing stack segment of memory and is used to store stack data. The
starting address of the each segment can be obtained from CS, DS, SS and ES
registers.
Pointers and Index Registers
The pointers IP, BP, SP usually contain offsets within the code, data
and stack segments respectively.
• Stack Pointer (SP) is a 16-bit register pointing to program stack in
stack segment.
•Base Pointer (BP) is a 16-bit register pointing to data in stack
segment. BP register is usually used for based indexed or register indirect
addressing. The index registers are particularly useful for string manipulation.
SI is used to store the offset of source data in data segment. DI is used to store
the offset of destination in data or extra segment.
Status Register
It determines the current state of the processor. They are modified
automatically by CPU after mathematical operations. This allows to
determine the type of the result and to determine the conditions to transfer the
flow of execution to other parts of the program.
Carry flag (CY)
It is set whenever there is a carry or borrow out of the MSB of a result.
CY=1, Carry is generated CY=0, Carry is not generated.
Parity flag (PF):It is set if the result has even parity of 1s. If parity is odd, PF
is reset.
Self- Instructional Material
Auxiliary carry flag (AC): Holds a carry after addition or a borrow after
subtraction between bit 3 and 4 of the result.
23
8086 Architecture Zero flag (ZF): Indicates the result of an arithmetic or logic operation. It is
NOTES
set if the result is zero
Sign flag (SF): Indicates the arithmetic sign of the result after an addition or
subtraction. If S = 1, the result is negative. If S = 0, the result is positive.
Overflow flag (OF): An overflow condition indicates that a result has
exceeded the capacity of the machine when a condition that can occur when
signed numbers are added or subtracted.
ControlFlags
Trap flag (TF): Debugging feature of the microprocessor by setting single
step mode of execution in the microprocessor. In single step mode the 8086
executes a software interrupt. The interrupt vector table contains certain
locations reserved for single step mode.
Interrupt flag (IF) : interrupt controls operation. If I = 1, the INTR pin is
enabled. If I = 0, the INTR pin is disabled.
Direction flag (DF) Controls the selection of increment and decrement for
the DI and SI registers during string instructions. If DF=1, the string bytes are
accessed from low memory address to high memory address. The contents of
SI and DI are decremented. If DF=0, the string bytes are accessed from high
memory address to low memory address. The contents of SI and DI are
incremented.
ground.
In this mode, the processor derives the status signal S2, S1, S0.
Another chip called bus controller derives the control signal using this
status information. In the maximum mode, there may be more than
one microprocessor in the system configuration. The components in
the system are same as in the minimum mode system.
The basic function of the bus controller chip IC8288 is to derive
control signals like and (for memory and I/O devices), ,
DT/ , ALE etc. using the information by the processor on the status
lines.
The bus controller chip has input lines S2, S1, S0 and CLK. These
inputs to 8288 are driven by CPU. It derives the outputs ALE, ,
DT/ , , , , , and .
Self- Instructional Material
24
Maximum mode of operation AEN and IOB are generally grounded. 8086 Architecture
25
8086 Architecture
NOTES
NOTES
The and AD0 signals are used to select the proper byte or bytes of
memory orI/O word to be read or write.The M/ , and signals indicate
the type of data transfer.
27
Instructions (8085)
UNIT –III INSTRUCTIONS (8085)
NOTES
Structure
3.1 Introduction to instructions for 8085
3.2 Instruction set
3.3 Software development tools
3.4 Sample programs
3.4.1 Assembly language program for addition of two 8-bit
numbers and store the sum
3.4.2 Assembly language program for 8-bit decimal subtraction
and store the result
3.4.3 Assembly language program to shift an 8-bit number left by
one bit
3.4.4 Assembly language program to find larger of two numbers
NOTES
• Logical operations - AND, OR, XOR and rotate.
• Control transfer - conditional, unconditional, call subroutine, return
from subroutine and restarts.
• Input/Output instructions. Examples, IN and OUT
• Other - setting/clearing flag bits, enabling/disabling interrupts, stack
operations, etc.
29
Instructions (8085) 3.4 SAMPLE PROGRAMS
NOTES 3.4.1 ASSEMBLY LANGUAGE PROGRAM FOR ADDITION OF
TWO 8-BIT NUMBERS AND STORE THE SUM
DATA
2500- 03 H
2501- 05 H
DATA
2501- 96 H.
2502- 38 H.
The result is stored in memory location 2503 H.
RESULT
2503- 58 H.
Self- Instructional Material
30
Instructions (8085)
Shift the data 65H left by one bit which is stored in memory 2501H.
The binary representation of 65H is given below:
65=0110 0101
Result of shifting65H left by one bit =1100 1010=CA
PROGRAM
DATA
2501-65 H
Result
2502-CA H
The first number 98H is placed in the memory location 2501H. Self- Instructional Material
The 2nd number 87H is placed in the memory location 2502H
31
Instructions (8085) The result is to be stored in the memory location 2503H.
NOTES
PROGRAM
DATA:
2501-98H
2502-87H
Result is 98H and it is stored in memory location 2503H
RESULT:
2503-98H
32
Interrupts and Stack Operations of 8085
UNIT –IV INTERRUPTS AND STACK NOTES
OPERATIONS OF 8085
Structure
34
Interrupts and Stack Operations of 8085
4.2 INTERRUPT SERVICE SUBROUTINE (ISS)
NOTES
A small program or a subroutine that is to be executed by the
microprocessor or by an external device at the time of receiving the interrupt
signal is called an ISS.
TRAP
It is a non-maskable interrupt, having the highest priority among all
interrupts. Bydefault, it is enabled until it gets acknowledged. In case of
power failure, it executes an ISS and sends the data to the backup memory.
This interruptsignal transfers the program control to the location 0024H.
RST7.5
It is a maskable interrupt, having the second highest priority among all
interrupts. When this interrupt is executed, the processor saves the content of
the PC register into the stack and branches the control to 003CH address.
RST 6.5
It is amaskable interrupt, having the third highest priority among all
interrupts. When this interrupt is executed, the processor saves the content of
the PC register into the stack and branches the control to 0034H address.
RST 5.5
It is amaskable interrupthaving the fourth highest priority among all
interrupts. When this interrupt is executed, the processor saves the content of
the PC register into the stack and branches the control to 002CH address.
INTR
It is a maskable interrupt, having the lowest priority among all the
above mentioned interrupts. There are 8 numbers of CALL-locations for
INTR interrupts. RST n instruction is used to transfer the program control to a
specific location. It can be disabled by resetting the microprocessor.
When INTR signal goes high, the following events can occur −
The microprocessor checks the status of INTR signal during the
execution of each instruction.
When the INTR signal is high, then the microprocessor completes its
current instruction and sends active low interrupt acknowledge signal.
When instructions are received, then the microprocessor saves the
address of the next instruction on stack and executes the received
instruction.
4.3 SUBROUTINE
In a microprocessor, a subroutine is a sequence of program
instructions that may perform a specific task, written as a unit. This unit can
then be used in the main program wherever that particular task is to be
performed. A subroutine is often called several times from several places Self- Instructional Material
during the execution of the main programand then return back after
35
Interrupts and Stack Operations of 8085 completing the task to the next instruction after the call instruction in the main
NOTES
program. It is implemented by using Call and Return instructions. The
program control can also be transferred from one subroutine to another by
using the same was as described in the case of main program to subroutine.
The different types of subroutine instructions are
Unconditional CALL instruction
CALL address is the format for unconditional call instruction. After
execution of this instruction,the program control is transferred to a subroutine
whose starting address is specified in the instruction.Before transferring the
program control, value of PC (Program Counter) is transferred to the memory
stack and value of SP (Stack Pointer) is decremented by 2.
Conditional CALL instruction
In these instructions program control is transferred to a subroutine if
the condition stated in the instruction is satisfied else the program control will
follow as usual i.e to the next instruction followed to the conditional CALL
instruction.Before transferring the program control, value of PC (Program
Counter) is transferred to the memory stack and value of SP (Stack Pointer) is
decremented by 2.
36
Interrupts and Stack Operations of 8085
4.4 FLOWCHARTING
NOTES
Flowcharting is a pictorial tool to represent a program. It allows to
break down a program into blocks and to show the logical relationships
between them pictorially. Constructing flowcharts promotes better
understanding of the program for debugging and for improvement.A
flowchart is a visual representation of the sequence of steps and decisions
needed to execute a program. Different diagrammatic shapes are used to
represent a step and these shapes are connected by lines with directional
arrows to represent the flow of execution or program control. This allows
anyone to logically follow the program from beginning to end.
A flowchart is a powerful tool. With proper design and construction, it
communicates the steps in a program very effectively and efficiently.
Flow Chart Symbols
The flowchart has different shapes as described in the diagram.
4.5 LOOPS
The programming technique used to instruct the microprocessor to repeat a
taskis called looping.This task is generally accomplished by using branching
instructions. For example: JMP
Classification of loops
1. Continuous loop
2.Unconditional loop
Continuous loop:
Repeats a task continuously.
A continuous loop is set up by using the unconditional branch control
instruction
A program with a continuous loop does not stop repeating the tasks
until the system is reset.
Conditional loop:
A conditional loop is set up by a conditional branch control
instruction.
These instructions check values of status flags (Z,CY,P,S) and repeat
the tasks if the conditions are satisfied.
These loops include counting and indexing.
Application of Conditional loop as counter:
A counter is a typical application of the conditional loop.
A microprocessor needs a counter,flag to accomplish the looping task.
Counter is set up by loading an appropriate count in a register.
Counting is performed by either increment or decrement the counter.
Loop is set up by a conditional branch control instruction.
End of counting is indicated by a flag.
4.6 PSEUDO-INSTRUCTIONS
Pseudo-instructions are special commands or directives to the
assembler to assemble the program. These instructions have mnemonics but
do not have a direct machine language equivalent. They are not part of
instructions, no operation code and not executable statements.
Duringassembly, the assembler translates each pseudoinstruction into one or
more machine. The following are the examples for pseudo instructions;ORG
indicates the starting memory location for loading the instructions and END
indicates the end of the program, no instructions to be translated into machine
code.
Self- Instructional Material
38
Interrupts and Stack Operations of 8085
4.7 STACK OPERATIONS
NOTES
A stack is a reserved area for temporary storage of data in the RAM.
The stack is defined usually at the highest address of the available RAM
location using LXI SP, XX99 H instruction. It means the location is available
for storing. An 8-bit stack pointer is used to hold the address of the top of the
stack.The stack works on the principle of LIFO(Last in first out). The SP is
decremented by one when data is stored and incremented by one when data is
retrieved. The data which is stored at last will be retrieved at first. The
contents are stored and retrieved on stack by using PUSH and POP
instructions respectively.
39
Interrupts and Stack Operations of 8085
4.8 PROGRAMMING AND APPLICATIONS: TRAFFIC
NOTES CONTROL SYSTEM
The 8085 is a popular microprocessor used for various applications
such as traffic light control, temperature control, stepper motor control, etc.
The following text describes a microprocessor based traffic control system
and a model assembly language program to activates the traffic lights at a
desired direction and at a desired time. The normal function of traffic light
system ensures that traffic moves as smoothly and safely as possible and that
pedestrians are protected when they cross the roads.It minimizes the accidents
and helps to streamline the flow of vehicles.
In this scheme, the traffic lights are interfaced to a microprocessor
through a programmable peripheral Interface 8255 to automatically switch
ON/OFF the traffic lights through its ports in desired sequence. Once the
address of the particular traffic light is indentified, then it can be switched
ON/OFF by sending a valid data from the microprocessor to that location
through the ports by using the OUT instruction.A delay program sequence
will be used to design the desired time for keeping the lights in ON or OFF
condition. Looping can also be used to continue the task of switching the
lights in sequence continuously. The one such assembly language program for
the application of traffic light control scheme is written below;
Program
MVI A, 80H: Initialize 8255, Port A and Port B
MVI A, 24H
MVI A, 12H
40
Interrupts and Stack Operations of 8085
CALL: DELAY: Call delay subroutine
NOTES
MVI A, 24H
MVI A, 09H
MVI A, 12H
JMP START
Delay Subroutine:
DELAY: LXI D, Count: Load count to give 0.5 sec delay
MOV A, D
41
UNIT – V MICROCONTROLLER 8051
Microcontroller 8051
NOTES
Structure
5.1 Introduction to 8 bit microcontrollers
5.2 8051 microcontroller architecture
5.3 Features of 8051 microcontroller
5.3.1 Pin diagram of 8051 microcontroller
5.4 8051 Memory organization
5.5 General purpose registers
5.5.1Special function register
5.6 Oscillator and clock circuit
5.7 8051 Addressing modes
5.8 8051 Interrupts of 8051
43
Microcontroller 8051 Interrupts:
NOTES
Interrupts are special signals that effect the CPU to suspend its current
activity and perform some other task for the hardware device that require
urgent attention. A microcontroller may need to support or monitor several
hardware subsystems each of which will occasionally require urgent attention.
CPU's are commonly designed to handle interrupts from various sources. Each
interrupt signal is associated with a particular memory location which contains
the address of the subroutine (a set of instructions) that should be executed on
demand. When subroutine task is finished then the implementation of core
program initiates automatically as usual. There are 5 interrupt signals in 8051
Microcontroller, two out of five are peripheral interrupts, two are timer
interrupts and one is serial port interrupt. Interrupts facilitate the users to
postpone or delay the current process, carry out a sub-routine task and then all
over again restart the standard program implementation.An Interrupt vector is
a memory location which contains the address of an interrupt service routine.
Interrupt service subroutine is aset of codes that is to be executed on receipt of
an interrupt signal. Interrupt vector table is a collection of interrupt vectors.
Oscillator:
45
Microcontroller 8051
NOTES
ALE: Address Latch Enable – an output pin which is active High and
is used for demultiplexing the address and data.
P0: Pins 32 to 39. It can be used as input or output port. To use the
pins of P0 as both input or output, each pin must be connected externally to
a pull-up register. Data 0 for output and 1 for input.
P1: Pins 1 to 8. It can be used as input or output. In contrast to P0, this
port doesn‘t need any pull-up register. Since it already has pull-up register
externally. P1 can be configured as an output upon reset. To make the P1
as input, it must be programmed as such by writing 1 to all of its bits.
P2: Pins 21 to 28. It can also be used as input or output like P1. P2
doesn‘t need any pull-up register since it already has registers internally. P2
can be configured as an output upon reset. To make it input, it must be
programmed as such by writing 1 to all its bit.
P3: Pins 10 to 17.It can also be used as input or output. P3 doesn‘t
need any pull-up register as same as P1 and P2. P3 has the additional
function of providing some extremely important functions and signals such
as interrupts. P3.0 and P3.1 are used for RXD and TXD serial
communication signal. P3.2 and P3.3 are set aside for external interrupts.
P3.4 and P3.5 are used for timer 0 and 1. Finally, P3.6 and P3.7 are used to
provide the write and read signal for external memory connected to the
8051 microcontroller system.
46
Microcontroller 8051
5.4 8051 MEMORY ORGANIZATION
NOTES
The 8051 microcontroller's memory is divided into Program Memory
and Data Memory. Program Memory (ROM) is used to store the program
being executed, while Data Memory (RAM) is used for temporarily storing
and keeping intermediate results and variables. This architecture has the
advantage that a program cannot accidently overwrite itself and is being used
in embedded systems. In addition, it uses the same address, in different
memories, for program and data. The microprocessor accesses the correct
memory based on the nature of the operation in progress.
Stack Pointer
The stack is a portion of the RAM used by CPU for storing the
information (data or an address) temporarily. The CPU uses this storage area
when there is shortage of registers. The Stack Pointer (SP) register is used to
locate the stack memory for read and write. The 8 bit stack can take values of
00H to FFH. On power on, the SP register in the microprocessor contains the
value 07H, implying that 08H is available for storing by PUSH instruction.
POP instruction is used to get the data from the stack.
47
Microcontroller 8051
5.5GENERAL PURPOSE REGISTERS
NOTES
This flag reflects the number of 1s in the register A. If register A contains even
number of 1s, then P=0 else P=1 for odd number of 1s.
49
Microcontroller 8051
5.6 OSCILLATOR AND CLOCK CIRCUIT
NOTES
System Clock
50
Microcontroller 8051
1. Immediate Addressing
2. Register Addressing NOTES
3. Direct Addressing
4. Register Indirect Addressing
5. Indexed Addressing
The instruction involves the use of registers (R0-R7) to hold the data to
be manipulated. The four register banks consisting of eight registers (R0-R7).
One of these four banks is selected by a 2 bit field in PSW register
For example-
MOV R6, A : save the content of register A in register A6. Data can be
moved between A and Rn( n= 0 to7) or vice-versa, but data movement
between Rn registers is forbidden. For instance, MOV R3,R2 is not allowed
and invalid.
3. DirectAddressing
The direct addressing mode, the content of the memory location whose
address is specified in the instruction will be processed. It is used to access the
RAM locations 30H to 7FH since other locations are designated for register
banks and stack (00H to 1FH) and bit addressable space (20H to 2FH). In
direct addressing mode the absence of the sign # indicates that the data
followed the instruction is address.
For example -
51
Microcontroller 8051 MOV R3, #55H; Load the data 55H in to R3.
NOTES
4. Register Indirect Addressing
For example -
5. Indexed Addressing
For example –
52
Microcontroller 8051
Vector Address: This is the address where the controller transfers its flow of
execution after receiving the interrupt in order to execute the ISR (interrupt NOTES
service routine).
Interrupt Flag Interrupt vector address
Reset - 0000H
INT0 (External interrupt 0) IE0 0003H
Timer 0 TF0 000BH
INT1 (External interrupt 1) IE1 0013H
Timer 1 TF1 001BH
Serial TI/RI 0023H
53
Microcontroller 8051 Bit 1 – ET0: Enable Timer0 Interrupt Bit
NOTES 1 = Enable Timer0 interrupt
0 = Disable Timer0 interrupt
Bit 0 – EX0: Enable External0 Interrupt Bit
1 = Enable External0 interrupt
0 = Disable External0 interrupt
Interrupt priority
Priority to the interrupt can be assigned by using interrupt priority
register (IP)
Interrupt priority after Reset:
Priority Interrupt source Intr. bit / flag
1 External Interrupt 0 INT0
2 Timer Interrupt 0 TF0
3 External Interrupt 1 INT1
4 Timer Interrupt 1 TF1
5 Serial interrupt (TI/RI)
In the table, interrupts priorities upon reset are shown. As per 8051
interrupt priorities, lowest priority interrupts are not served until
microcontroller is finished with higher priority ones. In a case when two or
more interrupts arrives microcontroller queues them according to priority.
IP Register: Interrupt priority register
8051 has interrupt priority register to assign priority to interrupts.
NOTES
1 = Assign high priority to External1 interrupt.
0 = Assign low priority to External1 interrupt.
Bit 1 – PT0: Timer0 Interrupt Priority Bit
1 = Assign high priority to Timer0 interrupt.
0 = Assign low priority to Timer0 interrupt.
Bit 0 – PX0: External0 Interrupt Priority Bit
1 = Assign high priority to External0 interrupt.
0 = Assign low priority to External0 interrupt.
Reset
Reset is the highest priority interrupt. Upon reset pin is enabled, 8051
microcontroller starts executing code from 0000H address.
Internal interrupt (Timer Interrupt)
8051 has two internal interrupts namely timer0 and timer1. Whenever
timer overflows, timer overflow flags (TF0/TF1) are set. Then the
microcontroller jumps to their vector address to serve the interrupt. For this,
EA and timer interrupt should be enabled.
Serial interrupt
8051 has serial communication port and have related serial interrupt
flags (TI/RI). When the last bit (stop bit) of a byte is transmitted, TI serial
interrupt flag is set and when last bit (stop bit) of receiving data byte is
received, RI flag get set.
Timers/Counters
In 8051, two 16 bit timers/counters are provided to count the event or
to estimate the elapsed time by means of counting the internal/external
periodic pulses. Each can be programmed independently either to count
internal closk or to count external input pulses. A timer with ―n‖ stages divides
the input clock frequency by 2 n. A 16 bit timer would counts from 0000H to
FFFFH. The counting will be monitored by overflow flag, which is set on the
FFFFH to 0000H overflow of the count. TMOD (Timer Mode Register) and
TCON (Timer Control Register) are the special SFRs to set the mode of
operation and configure of the timerand timer status respectively.
Timer Mode Control (TMOD)
TMOD is an 8-bit register used for selecting timer or counter and mode
of timers. Lower 4-bits are used for control operation of timer 0 or counter 0,
and remaining 4-bits are used for control operation of timer1 or counter1.This
register is present in SFR register, the address for SFR register is 89th. The Self- Instructional Material
two timers of 8051 can be set as timers or event counters by the status of the
55
Microcontroller 8051 C/T bit in the TMOD register. Mode 1 is the commonly used mode and the
NOTES
timers are 16 bits in size. It is common to configure the timer to cause an
interrupt when it overflows. The interrupt service routine then initializes the
timer.
Timer Control Register (TCON)
TCON is an 8 bit register and TR0 and TR1 flags in the TCON register
enable a timer to run, when set. The address of the TCON is 88H.
56
8051 Instruction Set and Programming
UNIT – VI 8051 INSTRUCTION SET AND NOTES
PROGRMMING
Structure
The arithmetic instruction has no knowledge about the data format i.e.
signed, unsigned, ASCII, BCD, etc. Also, the operations performed by the
arithmetic instructions affect flags like carry, auxiliary carry, overflow, zero,
etc. in the PSW Register.
60
8051 Instruction Set and Programming
NOTES
6.2.5 PROGRAM BRANCHING INSTRUCTIONS
All these instructions, except the NOP (No Operation) affect the
Program Counter (PC) in one way or other. Some of these instructions have
decision making capability before transferring control to other part of the
program.
1. Write a program to add the contents of locations 50H and 51H and
store the result in locations in 52H and 53H.
Self- Instructional Material
5. Find the value of the register A after the following instructions are
executed
63
Introduction to Interfacing Devices
UNIT –VII INTRODUCTION TO
NOTES
INTERFACING DEVICES
Structure
7.1 Introduction
7.2 Address space partitioning
7.2.1 Memory mapped I/O scheme
7.2.2 I/O mapped I/O scheme
7.3 Interfacing devices
7.3.1 Memory interfacing
7.3.2 I/O interfacing
7.4 Data transfer schemes
7.4.1 Serial I/O mode transfer
7.4.2 Parallel data transfer scheme
7.4.2.1 Programmed data transfers
7.4.2.2 DMA data transfer scheme
7.5 Interrupts
7.6 I/O ports
7.1 INTRODUCTION
64
Introduction to Interfacing Devices
NOTES
7.2 ADDRESS SPACE PARTITIONING
Intel 8085 uses a 16-bit wide address bus or addressing memory and
I/O devices. It can access 216=64k bytes of memory and I/O devices. There are
two schemes for the allocation of address to memories or I/O devices.
This scheme has only one address space which covers all possible
addresses that a microprocessor can generate. A distinct portion of the space is
assigned to memories and I/O devices. One unique address is assigned to
either memory location or I/O device. The main advantage of this scheme is
that all the data transfer instructions of the microprocessor can be used for
both memory as well as I/O devices since each entity has distinct address. For
example, MOV A, M will be valid for data transfer from the memory location
or I/O device whose address is in H-L pair. This scheme is suitable for small
system which involves limited number of memories and I/O devices.
This scheme has common address space for both memory and I/O
devices. Identification of memory and I/O device is done using a special signal
IO/M in addition to the address bus. When the signal is high the address
carried by the address bus is for I/O device and the low state of the signal
refers for a memory location. This scheme is suitable for large system since
the entire address space can be utilized to handle large number of memory and
I/O devices. Additionally, instructions IN and OUT are used to address the I/O
device for readingand writing the data.
The following table list outs the differences between Memory mapped
I/O and I/O mapped I/O
65
Introduction to Interfacing Devices Memory mapped I/O I/O mapped I/O
Each address of the I/O port and
NOTES
memory I/O and memorylocations share
location is unique same address space
Considerable memory location
are allotted No such problem.
for I/O ports where instruction
and data
cannot be stored
The I/O ports have 16 bit address. The port address will be only 8
Therefore bit. Therefore
64k is shared between I/O system 256 separate I/O devices can be
and connected.
The I/O map is independent of
memory system memory map.
Data transfer between any CPU
register and Data transfer is possible only
I/O ports are possible. through A register to I/O ports.
Instructions like LDA,STA,
MOV M, R, MOV R,M Only IN, OUT instructions are
instructions can be used to used to transfer data. I/Ooperations
transfer data to any I/O device. are very explicit.
I/O devices are not explicit in the
program.
Main memory space is limited. Separate memory is used for I/O
Program debugging is not easy. ports
Instructions. Program debugging
is easy.
66
Introduction to Interfacing Devices
NOTES
67
Introduction to Interfacing Devices
In the above truth table, the first three rows are invalid and the remaining
addresses can be used to decode any one of the output by properly connecting
NOTES this outputs to memories.
68
Introduction to Interfacing Devices
However in many situations, the parallel I/O mode needs special devices to
NOTES
implement.
Figure 7.4 Data transfer scheme
7.4.1 SERIAL I/O MODE TRANSFER
In serial I/O mode transfer, a single bit of data on a single line at a time
is transferred. For serial I/O data transmission mode, 8-bit parallel word is
converted to a stream of eight serial bit using parallel-to-serial converter.
Similarly, in serial reception of data, the microprocessor receives a stream of
8-bit one by one which are then converted to 8- bit parallel word using serial-
to-parallel converter. Here the microprocessor is able to process the data in
parallel mode.
7.4.2 PARALLEL DATA TRANSFER SCHEME
In DMA data transfer scheme CPU does not participate. Data are
directly transferred from an I/O device to the memory device or vice versa.
The data transfer is controlled by the I/O device or a DMA controller. When a
large block of data is to be transferred, DMA is used. If bulk of data are
transferred through CPU, it takes appreciable time and the process becomes
slow. An I/O device which wants to send data using DMA technique, sends a
HOLD signal to the microprocessor, then the CPU frees the control of buses as
soon as the current machine cycle is completed. The CPU sends HOLD
acknowledgement signal to that I/O device to indicate that it has received the
HOLD request and it will give up the buses in the next machine cycle. The I/O
device takes over the control of buses and initiates data transfer directly to the
memory or reads data from the memory. DMA transfer scheme is a faster
scheme as compared to programmed data transfer scheme. It is used to transfer
data from mass storage devices such as hand disks, floppy disks etc, It also
used for high-speed printers.
71
Introduction to Interfacing Devices
Cycle stealing techniques DMA transfer
In this technique, DMA data transfer happens at different intervals
NOTES
based on the availability of the bus without much interference in CPU‘s
process. After transferring one byte or several bytes, the I/O device withdraws
the DMA request and steals the bus cycle through an interfacing circuitry
when the CPU is not using the system bus. Data is transferred by a sequence of
DMA cycles.
Demand transfer mode DMA
The bulk of data transfer takes place whenever there is a demand
created by the I/O device or memory device. The following figure shows some
various types of data transfer schemes.
7.5 INTERRUPTS
An interrupt is a condition that causes the microprocessor to
temporarily work on a different task, and then later return to its previous task.
Interrupts can be internal or external. Internal interrupts, or "software
interrupts," are triggered by a software instruction and operate similarly to a
jump or branch instruction. An external interrupt, or a "hardware interrupt," is
caused by an external hardware module. As an example, many computer
systems use interrupt driven I/O, a process where pressing a key on the
keyboard or clicking a button on the mouse triggers an interrupt. The
processor stops what it is doing, it reads the input from the keyboard or mouse,
and then it returns to the current program.
72
Introduction to Interfacing Devices
7.6 I/O PORTS
NOTES
I/O stands for Input and Output. The information given into the
microprocessor is known as input. The most common device for input is the
keyboard or a signal from sensor. The information generated by the computer
is called output. The most common device for output is either a display or a
printer. The buffer where the information are shared from or to the
microprocessor is called I/O port. An input port is a place for unloading data
by the peripheral and read by the microprocessor. An output is a place for
unloading the data by the microprocessor and read by the peripherals. If
different data formats are being exchanged, the interface must be able to
convert serial data to parallel form and vice-versa. The following figure shows
a schematic connection of the CPU, I/O ports and I/O devices.
73
UNIT – VIII INTERFACING DEVICES
Interface Devices (8255 and 8259)
NOTES
(8255 AND 8259)
Structure
8.1 Programmable peripheral interface (PPI)
8.2 Intel 8255
8.3 Control word
8.4 Internal architecture of Intel 8255
8.4.1 Pin configuration of 8255
8.5 Programmable interrupt controller (PIC)
8.6 Internal architecture of 8259
The two operating modes in which 8255 can be programmed are as follows:
ii.I/O mode
The bits of port C gets set or reset in the BSR mode. The other mode of 8255
i.e., I/O mode is further classified into:
Self- Instructional Material
74
Interface Devices (8255 and 8259)
Mode 0: Simple input/output
NOTES
Mode 1: Input output with handshaking
Mode 0 and Mode 1 both are same but the only difference is mode 1 does not
support bidirectional handshaking.This means if 8255 is programmed to mode
1 input, then it will particularly be connected to an input device and performs
the input handshaking with the processor.
But if it is programmed to mode 2 then due to bidirectional nature, the PPI will
perform both input and output operation with the processor according to the
command received.
8.3 CONTROL WORD
According to the requirement, a port can be programmed to act either
as an input port or an output port. For programming the ports of 8255 a
control word is formed. The bits of control word are shown in the following
figure.
Control word is written into the control word register which is within
8255 by using the instruction OUT followed by the address of the port.
Bit No 0:
It is for port clower. To make port Clower an input port, the bit is set to
Self- Instructional Material
1.To make port Clower an output port, the bit is set to 0.
75
Interface Devices (8255 and 8259) Bit No 1:
NOTES
It is for port B. To make port B and input port, the bit is set to 1.
To make port b an output port, the bit is set to 0.
Bit No 2:
It is for the selection of the mode for the port B. If the port B has to
operate in mode 0, the bit is set to 0. For mode 1 operation of the port B, it
is set to 1.
Bit No 3:
It is for the port Cupper. To make port Cupper an input port, the bit set
to 1.
Bit No 4:
It is for the port A. To make portA, an input port, the bit set to 1.
To make port A, an output port, the bit is set to 0.
Bit No 5 and 6:
These bits are to define the operating mode of the port A. For the
various modesof port A these bits can defined as follows:
Examples:
The following example illustrates how to make a control word
Make control word when the ports of Intel/8255 are defined as follows;
Port A as an input port. Mode of the port A – mode 0, Port B as an output port,
76
Interface Devices (8255 and 8259)
Mode of the port B – mode 0, Mode of the port B – mode 0, Port Cupper as an
NOTES
Solution:
The control word bits for the above definition of the ports are as
follows:
77
Interface Devices (8255 and 8259)
8.4 INTERNAL ARCHITECTURE OF INTEL 8255
NOTES
Data bus buffer: It is used to connect the internal bus of 8255 with the
system bus so as to establish proper interfacing between the two. The data bus
buffer allows the read/write operation to be performed from/to the CPU.The
buffer allows the passing of data from ports or control register to CPU in case
of write operation and from CPU to ports or status register in case of read
operation.
Read/ Write control logic: This unit manages the internal operations of
the system. This unit holds the ability to control the transfer of data and
control or status words both internally and externally.Whenever there exists a
need for data fetch then it accepts the address provided by the processor
through the bus and immediately generates command to the control groups (A
and B) for the particular operation.
Group A and Group B control: These two groups are handled by the
CPU and functions according to the command generated by the CPU. The
CPU sends control words to the group A and group B control and they in turn
sends the appropriate command to their respective port. Group A has the
access of the port A and higher order bits of port C while group B controls port
B and the lower order bits of port C.
Self- Instructional Material
78
Interface Devices (8255 and 8259)
: It is for chip select. A low signal at this pin enabling the communication
between the 8255 and the processor so that the data transfer operation gets NOTES
enabled.
– It is for read operation. A low signal at this pin shows that CPU is
performing read operation at the ports or status word or 8255 is providing data
or information to the CPU through data buffer.
– It is for write operation. A low signal at this pin allows the CPU to
perform write operation over the ports or control register of 8255 using the
data bus buffer.
A0 and A1: Used to select the desired port among all the ports of the 8255 by
forming conjunction with RD and WR signals.
The table below shows the operation of the control signals for the selection of
ports.
Port A 00
Port B 01
Port c 02
The instruction IN00 means that it is for the port A of 8255. When this
instruction is executed data are transferred from the port A to the accumulator.
The instruction OUT 03 will transfer the content of the accumulator to the
control word register of 8255.
Reset: It is an active high signal and a high signal at this pin clears the control
registers and the ports which are set in the input mode.
During the reset, initializing the ports to input mode alone is done to
prevent the accidental circuit breakdown at the output mode since there exist
chances of electrical destruction of 8255 along with the processor due to the
physical interface between the output ports with the microprocessor.
79
Interface Devices (8255 and 8259) PC3 of Port Clower and PC4-PC7 of Port Cupper. Vcc is input power and GND is
NOTES circuit ground.
80
Interface Devices (8255 and 8259)
8.6 INTERNAL ARCHITECTURE OF 8259
NOTES
Read/Write logic
This block works only when the value of pin CS is low (as this pin is Self- Instructional Material
active low). This block is responsible for the flow of data depending upon the
81
Interface Devices (8255 and 8259) inputs of RD and WR. These two pins are active low pins used for read and
NOTES
write operations.
Control logic
It controls the functioning of every block. It input pin INTR receives
interrupt request from microprocessor and enable pin INT for output to the
microprocessor. If 8259 is enabled, and the connected microprocessor‘s
interrupt is high then this causes the value of the 8259‘s output INT pin high
and in this way 8259 responds to the request made by
microprocessorinterfaced with it.
Priority resolver
It examines all the three registers and set the priority of
interrupts.According to the priority of the interrupts, interrupt with highest
priority is set in ISR register. Also, it reset the interrupt level which is already
been serviced in IRR.
Cascade buffer
It is used to increase the Interrupt handling capability by employing
CSA lines to control multiple interrupt structure.
SP/EN (Slave program/Enable buffer) pin is set to high to work in
master mode else in slave mode. In case of non-buffered mode SP/EN pin is
used to specify whether 8259 work as master or slave and in buffered mode,
SP/EN pin is used as an output to enable data bus.
82
Interface Devices (8255 and 8259)
The priority can be assigned to the I/O devices which are connected to
PIC. 8 I/O devices can be connected to 8259 through IR0 − IR7 lines. In this NOTES
interrupt driven system, the interrupt controller accepts request from an I/O
device and determines which of the incoming request is of the highest priority.
After checking the priority of the interrupt request, the 8259 sends an interrupt
signal to the microprocessor through the INT line. Thenthe microprocessor
sends the acknowledgesignal through INTA line and all the interrupt of lower
priority are inhibited.The 8259 sends a unique CALL instruction to the
microprocessor so that it can take up the ISS attached to the I/O device which
has requested for data transfer. 8259 chips can be cascaded to receive upto 64
vectored priority interrupts without additional circuitry. The following
schematic diagram represents a scheme for interfacing 8259 with 8085 or
8086.
83
Interface Devices (8257 and 8251)
NOTES
UNIT – IX INTERFACING DEVICES
(8257 AND 8251)
Structure
The more description about the features of 8259 are given as follows.
Four I/o devices can be interfaced to the microprocessor through this device. It
is capable of performing three operation namely read, write and verify.
Transfer of data from the memory to the I/O device is read and transfer of data
from the I/O device to the memory is write operation. On receiving a request
from the I/O device, the 8257 generats a sequential memory address which
allows the I/O device, to read or write directly to or from the memory. Each
channel incorporates two 16- bit resisters namely,DMA address register and
Byte count register.
These register are initialized with the address of the first memory
location is to be accessed before a channel is enable. During DMA operation it
stores the next memory locations is to be accessed in the next DMA cycle. 14-
LSBs of the byte count registers store the number of bytes to be transferred.
14
So, 2 (16384) bytes of data can directly be transferred to the memory from
the I/O device or from the memory to the I/O device. The 2 MSBs of the byte
count register indicate the operation which is to be performed by the controller
on that channel. Besides these registers the 8257 also includes mode set
register and starter register.
85
Interface Devices (8257 and 8251)
NOTES
−
These are the active-low DMA acknowledge lines by 8257 against the
request made by the peripherals. These lines can also act as strobe lines for
the requesting devices.
Do − D7
These are bidirectional, data lines which are used to interface the
system bus with the internal data bus of DMA controller. In the Slave mode,
it carries command words to 8257 and status word from 8257. In the master
mode, these lines are used to send higher byte of the generated address to the
latch. This address is further latched using ADSTB signal.
87
Interface Devices (8257 and 8251)
NOTES
It is an active-low chip select line. In the Slave mode, it enables the
read/write operations to/from 8257. In the master mode, it disables the
read/write operations to/from 8257.
A4 - A7
These are the higher nibble of the lower byte address generated by
DMA controller in the master mode.
READY
It is an active-high asynchronous input signal, which makes DMA
controller ready by inserting wait states.
HRQ
This signal is used to receive the hold request signal from the output
device. In the slave mode, it is connected with a DRQ input line 8257. In
Master mode, it is connected with HOLD input of the CPU.
HLDA
It is the hold acknowledgement signal which indicates the DMA
controller that the bus has been granted to the requesting peripheral by the
CPU when its status is 1.
It is the low memory read signal, which is used to read the data from
the addressed memory locations during DMA read cycles.
It is the active-low tristate signal which is used to write the data to the
addressed memory location during DMA write operation.
ADST
This signal is used to convert the higher byte of the memory address
generated by the DMA controller into the latches.
AEN
This signal is used to disable the address bus/data bus.
TC
It stands for byte count (‗Terminal Count‘) of the data transfer. If
TC=1, then the current DMA is complete.
MARK
The mark will be activated after each 128 cycles or integral multiples
of it from the beginning. It indicates the current DMA cycle is the 128th cycle
since the previous MARK output to the selected peripheral device.
Self- Instructional Material
88
Interface Devices (8257 and 8251)
Vcc
It is the input power required for the operation of the circuit. NOTES
89
Interface Devices (8257 and 8251)
9.2.2 ARCHITECTURE OF INTEL 8051A
NOTES
The schematic diagram of the internal architecture of 8051A is given
below. The function of the each block is described in the following section.
Read/Write control logic
• The Read/Write Control logic interfaces the 8251A with CPU and
determines the functions of the 8251A according to the control word
written into its control register.
• It monitors the data flow.This section has three registers and they are
control register, status register and data buffer.
• The active low signals RD, WR, CS and C/D(Low) are used for
read/write operations with these three registers.
• When C/D is high, the control register is selected for writing control word
or reading status word.When C/D is low, the data buffer is selected for
read/write operation.
• When the reset is high, it forces 8251A into the idle mode.The clock input
is necessary for 8251A for communication with CPU and this clock does
not control either the serial transmission or the reception rate.
• The transmitter section accepts parallel data from CPU and converts them
into serial data.
• When output register is empty, the data is transferred from buffer to output
register. Now the processor can again load another data in buffer register.
If buffer register is empty, then TxRDY goes to high.If output register
is empty then TxEMPTY goes to high.
• The clock signal, TxC (low) controls the rate at which the bits are
transmitted by the USART.The clock frequency can be 1,16 or 64 times the
baud rate.
Receiver Section
• The receiver section accepts serial data and convert them into parallel data.
The receiver section is double buffered, i.e., it has an input register to
receive serial data and convert to parallel, and a buffer register to hold the
parallel data.
• When the RxD line goes low, the control logic assumes it as a START bit,
waits for half a bit time and samples the line again.If the line is still low,
then the input register accepts the following bits, forms a character and
loads it into the buffer register.
• The CPU reads the parallel data from the buffer register.When the input
register loads a parallel data to buffer register, the RxRDY line goes high.
• The clock signal RxC (low) controls the rate at which bits are received by
the USART.
MODEM Control
91
Interface Devices (8257 and 8251) • The 8251A can be either memory mapped or I/O mapped in the
NOTES system.Using a 3-to-8 decoder generates the chip select signals for I/O
mapped devices.
• The address lines A4, A5 and A6 are decoded to generate eight chip select
signals (IOCS-0 to IOCS-7) and in this, the chip select signal IOCS-2 is
used to select 8251A.
• The address line A7 and the control signal IO / M(low) are used as enable
for decoder.
• The RESET and clock signals are supplied by the processor. The
processor clock is directly connected to 8251A. This clock controls the
parallel data transfer between the processor and 8251A.
• The output clock signal of 8085 is divided by suitable clock dividers like
programmable timer 8254 and then used as clock for serial transmission
and reception.
• The TTL logic levels of the serial data lines and the control signals
necessary for serial transmission and reception are converted to RS232
logic levels using MAX232 and then terminated on a standard 9-pin D-
.type connector.
92
Microprocessor Applications
APPLICATIONS
Structure
ADC 0808
ADC0808 is a monolithic CMOS device, offers high speed, high Self- Instructional Material
Figure
10.1 Pin diagram of ADC0808
Main Features:
94
Microprocessor Applications
No zero or full-scale adjust required
NOTES
8-channel multiplexer with address logic
0V to 5V input range with single 5V power supply
In the first step the unknown voltage Vin is compared with ½Vr. If
Vin>=1/2 Vr, the MSB of the digital output is set to 1. If Vin<1/2Vr, MSB is
set to 0.
Specifications:
Resolution: 8 Bits
Low Power: 15 mW
this the interrupt follows the low to high operation. When the start pin is held
95
Microprocessor Applications high no conversion begins, but when the start pin is low the conversion will
NOTES start within 8 clock periods. The point when the conversion is completed the
EOC pin goes low to indicate the finish of conversion and data ready to be
picked up. The output enable (OE) is then raised high. This enables the TRI-
STATE outputs, allowing the data to be read.
Application of ADC0808:
The analog to digital converter chips 0808 and 0809 are 8- bit CMOS,
successive approximation converters. This technique is one of the fast
techniques for analog to digital conversion. The conversion delay is 100µs at a
clock frequency of 640 KHz, which is quite low as compared to other
converters.
Analog input voltage must be constant at the input of the ADC right
from the start of conversion till the end of the conversion to get correct
results.This may be ensured by a sample and hold circuit which samples the
analog signal and holds it constant for specific time duration. The
microprocessor may issue a hold signal to the sample and hold circuit. If the
applied input changes before the complete conversion process is over, the
digital equivalent of the analog input calculated by the ADC may not be
correct.
96
Microprocessor Applications
10.2 MICROPROCESSOR BASED TEMPERATURE
NOTES
MONITORING CONTROLLER
Microprocessor based temperature monitoring and controlling is one of
the very important applications in industry. Temperature control is a process in
which change of temperature of an object is measured or detected, and the
supply of heat energy into or out of the object is adjusted in order to achieve a
desired temperature. An Automatic Temperature Control Unit mainly divided
into three parts-Temperature input unit, Processing unit and Control output
unit.
The 8085 based scheme forms the basic processing unit, the Analog-to-
Digital converter unit, and temperature input unit with temperature sensor. The
switching ON/OFF of the heater controls the heat supplied to the object. Basic
operation of the temperature control unit,requires two set points, Upper set
point and Lower set point. Whenever the temperature of the object exceeds the
upper limit the power is turned-off. If the temperature drops below the lower
limit, then the power is turned on. In this way, the temperature is maintained
around the set limit.
97
Microprocessor Applications
NOTES
X=
After the rotation of the shaft through angle X, the rotor locks itself
with the next tooth in the sequence on the internal surface of stator.This design
allows for very precise control of the motor by proper pulsing.These are used
in printers, disk drives, and other devices where precise positioning of the
motor is necessary and be controlled with digital circuits.
The internal schematic of a typical stepper motor with four windings
Self- Instructional Material with an angle of rotation 90° and its rotor are shown in the following figures.
98
Microprocessor Applications
NOTES
Figure 10.4
Schematic diagram of stepper motor with four windings
A typical pulse scheme to realize the rotation in both clockwise and
anticlockwise is given in the following table.This scheme is called a wave
scheme. The four windings, say Wa, Wb, Wc and Wd are applied with the
required voltages pulses (as per the motor specification), in a cyclic fashion.
By reversing the sequence of excitation, the direction of rotation of the stepper
motor shaft may be reversed.
By selecting a proper input circuit along with the required output in
digital form will help to interface the stepper motor with 8085 or 8086. A
simple scheme represented in the below figure will explain a method of
interfacing stepper motor with 8085.
99
Microprocessor Applications
NOTES
Motion step A B C D
1 1 0 0 0
2 0 1 0 0
Clock 3 0 0 1 0
Wise
Direction 4 0 0 0 1
1(2nd
round) 1 0 0 0
1 1 0 0 0
2 0 0 0 1
Anti-clock
wise 3 0 0 1 0
Direction 4 0 1 0 0
1(2nd
round) 1 0 0 0
100
Amplifiers and Comparators
UNIT – XI AMPLIFIERS AND NOTES
COMPARATORS
Structure
11.1 Introduction to instrumentation amplifier
11.2 Operation of instrumentation amplifier
11.3 Sample and hold circuit
11.4 Comparators
11.5 Digital to analog converter
11.6 D/A converter architectures
11.6.1 Weighted Resistor method
11.6.2 Resistor Ladder Network Method
Having the feedback resistors on both pins being equal makes this a unity-
gain differential op-amp. In order to get the output in terms of the inputs,
the relationship between V4 – V3 and V1 – V2 must be found.
Between point 3 and 4, there are three resistors with no
connection to ground. This causes the current through all three resistors,
I, to be equal. Therefore
I=
Self- Instructional Material
Also, the voltages at point 1 and 2 are known, yielding the equation
102
Amplifiers and Comparators
I= NOTES
When the two equations are combined and rearranged, the equations yield
V3-V4 = (V1-V2)
This relationship can be plugged into the equation for V out to yield a final
equation of
V3-V4 = (V2-V1)
103
Amplifiers and Comparators Control input open and closes (solid-state switch) at sampling rate fs.
NOTES The modes of operation of the control switch - tracking ( switchclosed) and
hold (switch open). The sample and hold parameters are defined as follows;
acquisition time - time for instant switch closes until Vi within defined
% (~ ≥99.3%) of input.
aperture time - time taken by the switch to open.
decay rate - rate of discharge of C when circuit is in hold mode.
11.4 COMPARATORS
Analog-to-Digital (A/D or ADC) and Digital-to-Analog (D/A or DAC)
circuits are in wideuse today because of the need to translate analog signal to
digital format for processing by microprocessors and translate the output of
microprocessors (digital signal) to analog signal to drive the loads. The heart
of most ADC circuit is the ―comparator‖ whose schematic diagram is given in
the below figure. A comparator compares the value of input signal to a
reference voltage. If the input signal voltage is larger than the reference
voltage, comparator outputwill be in a set voltage (for example, V +, for a
―HIGH‖ or ―ON‖ state). If the input signal voltage is smaller than the
reference voltage, comparator output will be in a different, yet another set
voltage (for example, V −, for a ―LOW‖ or ―OFF‖ state).
That means it takes two input voltages, then compares them and gives
a differential output voltage either high or low-level signal. The comparator is
used to sense when an arbitrary varying input signal reaches reference level or
a defined threshold level. The comparator can be designed by using various
components like diodes, transistors, op-amps. The comparators find in many
electronic applications that may be used to drive logic circuit.
104
Amplifiers and Comparators
Figure 11.3 Block diagram of Comparator
NOTES
105
Amplifiers and Comparators
NOTES
In the voltage domain, that is if the input signals are voltages, the
addition of the binary bits can be achieved using the inverting summing
amplifier shown in the above figure.
The input resistors of the op-amp have their resistance values weighted
in a binary format. When the receiving binary 1 the switch connects the
resistor to the reference voltage. When the logic circuit receives binary 0, the
switch connects the resistor to ground. All the digital input bits are
simultaneously applied to the DAC.
The DAC generates analog output voltage corresponding to the given
digital data signal. For the DAC the given digital voltage is b3 b2 b1 b0 where
each bit is a binary value (0 or 1). The output voltage produced at output side
is
V0=R0/R (b3+b2/2+b1/4+b0/8) Vref
106
Amplifiers and Comparators
The above figure shows the 4-bit R-2R ladder DAC. In order to
achieve high-level accuracy, we have chosen the resistor values as R and 2R. NOTES
Let the binary value B3 B2 B1 B0, if b3=1, b2=b1=b0=0, then the circuit is
shown in the figure below it is a simplified form of the above DAC circuit.
The output voltage is V0=3R(i3/2)= Vref/2
If b1=1 and b2=b3=b0=0, then the circuit shown in the figure below it
is a simplified form of the above DAC circuit. The output voltage is
V0=3R(i1/8)= Vref/8
107
Amplifiers and Comparators
NOTES
In this way, we can find that when the input data is b3b2b1b0 (where
individual bits are either 0 or 1), then the output voltage is
108
Temperature Transducers
UNIT – XII TEMPERATURE NOTES
TRANSDUCERS
Structure
12.1 Introduction
12.2 Classification of transducers
12.1 INTRODUCTION
A device which converts a physical quantity into the proportional
electrical signal is called a transducer. The electrical signal produced may
be a voltage, current or frequency. A transducer uses many effects to
produce such conversion. The process of transforming signal from one form
to other is called transduction. A transducer is also called pick up. The
transduction element transforms the output of the sensor to an electrical
output, as shown in theFig.
1. SensingElement
The physical quantity or its rate of change is sensed and responded to
by this part of the transistor.
2. TransductionElement
The output of the sensing element is passed on to the transduction
element. This element is responsible for converting the non-electrical signal
into its proportional electricalsignal.
3. Thermocouple
110
Temperature Transducers
However, they operate across the widest temperature range, from -200 °C to
1750 °C. NOTES
4. Semiconductor-based sensors
111
UNIT – XIII DISPLACEMENT
Displacement Transducers
NOTES
TRANSDUCERS
Structure
13.1 INTRODUCTION-POTENTIOMETER
A potentiometer is a resistive sensor used to measure linear
displacements as well as rotary motion. In a potentiometer an electrically
conductive wiper slides across a fixed resistive element. A voltage is
applied across the resistive element. Thus a voltage divider circuit is
formed. The output voltage(Vout) is measured as shown in the figure below.
The output voltage is proportional to the distance travelled.
112
Displacement Transducers
Figure 13.1 Block diagram of a potentiometer
There are two types of potentiometer, linear and rotary potentiometer. NOTES
The linear potentiometer has a slide or wiper. The rotary potentiometer can be
a single turn or multi turn.
• Higher resolution.
• Lower noise.
• Longer life (exceed 10 millioncycles)
Self- Instructional Material
• Resistance of 50 to 100 Ω/mm can be obtained with conductive plasticfilm.
113
Displacement Transducers • Commercially available resolution is 0.001mm.
NOTES
Where,
A = Overlapping area of plates; m2,
d = Distance between two plates;m,
Z = 1/2πfC
Where: Z =Impedance
f = frequency, 50 Hz.
Self- Instructional Material
C =capacitance
115
Displacement Transducers The capacitive transducers work on the principle of change in
NOTES
capacitance of the capacitor. This change in capacitance could be caused by
change in overlapping area A of the plates, change in the distance d between
the plates and change in dielectric constant of the medium.
In most of the cases the above changes are caused by the physical
variables, such as, displacement, force or pressure. The capacitive
transducers are commonly used for measurement of linear displacement.
The major advantages of capacitive transducers are that they require
extremely small forces to operate them and hence are very useful for use in
small systems. They are extremely sensitive and require small power to
operate them. Owing to their good frequency response they are very useful
for dynamicstudies.
The disadvantages of capacitive transducers include their non-linear
behavior on account of edge effects and the effects of stray capacitances
especially when the transducers have a low value of capacitance.Capacitive
transducers can be used for measurement of both linear and angular
displacements.
118
Photoelectric Transducers
NOTES
UNIT – XIV PHOTOELECTRIC
TRANSDUCERS
Structure
14.1 Photoelectric transducer
14.2 Photo-voltaic cell
14.3 Types of photovoltaic cell
14.4 Photoconductive cell
14.5 Piezo-electric transducer
14.5.1 Piezoelectric effect
14.5.2 Working principle of piezoelectric transducer
119
Photoelectric Transducers
14.2 PHOTO-VOLTAIC CELL
NOTES
A p-type silicon and p-type silicon are diffused to form a photovoltaic
cell (p-n junction). When this cell is exposed to light, photons are absorbed by
the semiconductor crystal which causes significance number of free electrons
in the crystal, this phenomenon is called photovoltaic effect.
The photovoltaic effect is the basis of generation of current across the
semiconductor junction.Large sets of PV cells can be connected together to
form solar modules, arrays, or panels. The use of PV cells and batteries for the
generation of usable electrical energy from solar light is known as
photovoltaic. One of the major advantages of photovoltaic is non-polluting
electrical energy generation from unlimited solar energy. It can provide energy
at cost effective over years and with minimal maintenance.
The current or voltage across the junction is proportional to the amount
of light incident on that cell. Hence, it can be used as a transducer.
120
Photoelectric Transducers
14.4 PHOTOCONDUCTIVE CELL
NOTES
The photoconductive cell converts the light energy into an electric
current. It uses the semiconductor material like cadmium selenide, Ge, Si, as a
photo sensing element.When the beam of light falls on the semiconductor
material, their conductivity increases and the material works like a closed
switch.In this effect, the electrical resistance of the material varies with the
amount of incident light.
122
Photoelectric Transducers
3. It is used in microphones and speakers for converting the electric
signal into sound. NOTES
4. The piezoelectric material is used in electric lighter.
REFERENCES
123
MODEL QUESTION PAPER
MICROPROCESSOR AND ELECTRONIC INSTRUMENTATION
Time: 3hrs PART - A Max marks:75
I. Answer all the questions not exceeding 50 words each. (10 x 2 = 20)
1. Write the addressing modes of 8085 microprocessor.
2. Give any two examples for logical instructions.
3. Define synchronous data transfer?
4. State the principle of DMA controller.
5. What is a microcontroller?
6. Write the advantages of microcontrollers?
7. How many instructions group are available in 8051?Name them.
8. Give the function of the following instruction.
MOVX, A, @DPTR.
9. Give the principle of a stepper motor.
10. What is meant by interfacing of 8051?
PART – B
II. Write any 5 questions of the following not exceeding 650 words each. (5 x 5 = 25)
11. Explain in detail the data transfer instructions.
12. Write aprogram using 8085 to multiply two 8 bitnumbers.
13. Discuss about asynchronous data transfer.
14. Describe a programmable peripheral interface(8255 A).
15.Short note on microcontroller hardware.
16. Explain the function of timers in a microcontroller.
17. Elaborate about bit manipulations.
18. Briefly explain about the pulse measurement.
PART – C
III. Answer any ONE from each section of the following not exceeding1500 words each (2 x 15 =
30)
19. (a) With suitable diagrams, describe the pins of 8085 andexplain its architecture.
(OR)
19. (b) Explain about :8253 A (PIT) and 8259 (PIC)
20. (a) Elaborately explain the memory structure of 8051.
(OR)
20. (b) Write an 8051 program to find the biggest and smallestnumbers from a given list of numbers.
124