7 BSC CS Microprocessor - Indd
7 BSC CS Microprocessor - Indd
, COMPUTER SCIENCE
MICROPROCESSOR AND ITS APPLICATIONS
SECOND YEAR NON – SEMESTER
Dr.A.SHAIK ABDUL KHADIR
HOD & Associate Professor
Dept of Computer Science,
Khadir Mohideen College,
Adirampattinam, Thanjavur - 614 701.
150
MICROPROCESSOR AND ITS APPLICATIONS
Unit I
1
9 After 1978, the 3rd generation microprocessors were introduced.
Typical microprocessors were Intel 8086/ 80186/ 80286 and Motorola 68000/
68010. These microprocessors were designed using HMOS technology.
Transportation Industry
2
9 A cell phone or mobile device executes game instructions by way of
the microprocessor.
9 VCRs, televisions and gaming platforms also contain microprocessors
for executing complex instructions and tasks.
Instrumentation
Entertainment
1.5. Programming
9 To perform a particular task the programmer prepares a set of instructions known
as a program. A program written in the form of zeros and ones is called a machine
language program. The writing of a program in the machine language is difficult.
The simplest symbolic language used for microprocessor is assembly language.
9 Translators are used for the conversion of an assembly language or high level
language into Machine language for the operation of the computer. A program
which converts an assembly language program into a machine language program
is called an assembler. Similarly, a program, which translates a program written in
a high level language into a machine language program is called a compiler.
3
1.1. Schematic Diagram of a Digital Computer
1.6.1 CPU
The Central Processing Unit fetches instructions from the memory and performs specified
tasks. It stores results in the memory or sends results to the output devices. The CPU of a large
computer is implemented on one or more circuit boards. ICs are used as its components. The
major sections of a CPU are:
i. ALU (Arithmetic and Logic Unit). The function of an ALU is to perform arithmetic
operations such as addition and subtraction.
4
ii. Timing and Control Unit. This unit controls the entire operations of a computer.
iii. Accumulator and General Purpose Registers. The accumulator is a register which
contains one of the operands and stores results of most arithmetic and logical operations.
General purpose registers are used for temporary storage of data.
1.6.2. Microprocessor
A CPU built into a single chip LSI or VLSI chip is called a microprocessor. A digital
computer using microprocessor as its CPU is called a microcomputer.
1.6.3. Memory
5
1.6.5. Output Device
The computer sends results to output devices. An output device may store, print, display or
send electrical signal to control certain equipment. The example of simple output devices are
printers, CRT, LEDs, controllers etc.
1.7. Memory
9 A memory is just like a human brain. It is used to store data and instructions.
Computer memory is the storage space in the computer, where data is to be
processed and instructions required for processing are stored.
9 The memory is divided into large number of small parts called cells. Each
location or cell has a unique address, which varies from zero to memory size
minus one. For example, if the computer has 64k words, then this memory unit
has 64 * 1024 = 65536 memory locations. The address of these locations varies
from 0 to 65535. There are two kinds of memories:
i. Semiconductor memories
ii. Magnetic memories
1.7.1.1. RAM
9 RAM is a form of short term or volatile memory. Information stored in short
term storage is lost when the computer is switched of (or when power fails).
9 This means that any location in memory may be accessed in the same amount
of time as any other location. Memory access means one of two things, either
the CPU is reading from a memory location or the CPU is writing to a
memory location.
9 When the CPU reads from a memory location, the contents of the memory
location are copied to a CPU register. When the CPU writes to a memory
location, the CPU copies the contents of a CPU register to the memory
location, overwriting the previous contents of the location. RAM is of two
types:
i. Static RAM
ii. Dynamic RAM
Static RAM(SRAM). The word static indicates that the memory retains its contents as
long as power is being supplied. However, data is lost when the power gets down due to volatile
6
nature. SRAM need not have to be refreshed on a regular basis in order to maintain the data
.SRAM is used as cache memory and has very fast access.
• Faster
• Used as RAM
1.7.1.2 ROM READ ONLY MEMORY (ROM) ROM stands for Read Only Memory. The
memory from which we can only read but cannot write on it. This type of memory is non-
volatile. The information is stored permanently in such memories during manufacture. A ROM,
stores such instructions that are required to start a computer.
PROM . (Programmable Read only Memory) PROM is read-only memory that can be
modified only once by a user. It can be programmed only once and is not erasable.
EPROM. (Erasable and Programmable Read Only Memory) The EPROM can be erased
by exposing it to ultra-violet light for a duration of up to 40 minutes.
EEPROM. (Electrically Erasable and Programmable Read Only Memory) The EEPROM is
programmed and erased electrically. It can be erased and reprogrammed about ten thousand
times.
7
1.7.2. Magnetic memories
9 Magnetic memories are non-volatile. They are slower than semiconductor
memories. They are used in computer system for bulk storage. The important
types of magnetic memories are: magnetic tape, floppy disk, hard disk and
magnetic bubble type memories.
9 It was used as a main memory in earlier computers. Today semiconductor
memories have replaced core memories. Magnetic tapes, floppy disks are used as
mass storage devices.
Magnetic Tape Storage. Magnetic tape is a medium for magnetic recording, made of a
thin, magnetizable coating on a long, narrow strip of plastic film. A device that stores computer
data on magnetic tape is known as a tape drive. Magnetic tape revolutionized sound recording
and reproduction and broadcasting.
Magnetic tape recording works by converting electrical audio signals into magnetic
energy, which imprints a record of the signal onto a moving tape covered in magnetic particles.
As the tape passes by, these pulses align the tiny magnetic particles into patterns, leaving a
record of the sound.
Floppy Disk. A floppy disk is a magnetic storage medium for computer systems. The
floppy disk is composed of a thin, flexible magnetic disk sealed in a square plastic carrier. In
order to read and write data from a floppy disk, a computer system must have a floppy disk drive
(FDD). A floppy disk is also referred to simply as a floppy. Since the early days of personal
computing, floppy disks were widely used to distribute software, transfer files, and create back-
up copies of data. When hard drives were still very expensive, floppy disks were also used to
store the operating system of a computer.
Optical Disk. An optical disc is an electronic data storage medium that can be written to
and read from using a low-powered laser beam. Originally developed in the late 1960s, the first
optical disc, created by James T. Russell, stored data as micron-wide dots of light and dark.
Optical storage, electronic storage medium that uses low-power laser beams to record and
retrieve digital (binary) data. In optical-storage technology, a laser beam encodes digital data
onto an optical, or laser, disk in the form of tiny pits arranged in concentric tracks on the disk's
surface.
1.8. BUSES
Various input/output devices and memories are connected to the CPU by a group of
lines called a bus. There are three types of buses: address bus, data bus and control bus.
9 The data bus allows data to travel back and forth between the microprocessor
(CPU) and memory (RAM).
9 The address bus carries information about the location of data in memory.
8
9 The control bus carries the control signals that make sure everything is flowing
smoothly from place to place.
1.10. Microcomputers
Low-cost small digital computers are known as microcomputers. The word length of a
microcomputer may be 8-bit, 16-bit or 32-bit. Microcomputers are widely used in industrial
control, instrumentation, general purpose computation, home appliances, commercial appliances,
office automation, automobiles, and so on and so forth.
9
1.5. Architecture of 8085 Microprocessor
Arithmetic and Logic Unit . The ALU performs the actual numerical and logical
operations such as Addition (ADD), Subtraction (SUB), AND, OR etc. It uses data from
memory and from Accumulator to perform operations. The results of the arithmetic and
logical operations are stored in the accumulator.
Registers. The 8085 includes six registers, one accumulator and one flag register, as
shown in Fig. 3. In addition, it has two 16-bit registers: stack pointer and program
counter. They are briefly described as follows.
10
The 8085 has six general-purpose registers to store 8-bit data; these are identified as B, C,
D, E, H and L. they can be combined as register pairs - BC, DE and HL to perform some
16-bit operations. The programmer can use these registers to store or copy data into the
register by using data copy instructions.
Accumulator. The accumulator is an 8-bit register that is a part of ALU. This register is
used to store 8-bit data and to perform arithmetic and logical operations. The result of an
operation is stored in the accumulator. The accumulator is also identified as register A.
Flag register. The ALU includes five flip-flops, which are set or reset after an operation
according to data condition of the result in the accumulator and other registers. They are
called Zero (Z), Carry (CY), Sign (S), Parity (P) and Auxiliary Carry (AC) flags.
For example, after an addition of two numbers, if the result in the accumulator is larger
than 8-bit, the flip-flop uses to indicate a carry by setting CY flag to 1. When an
arithmetic operation results in zero, Z flag is set to 1. The S flag is just a copy of the bit
D7 of the accumulator. A negative number has a 1 in bit D7 and a positive number has a
0 in 2’s
Complement representation. The AC flag is set to 1, when a carry result from bit D3 and
passes to bit D4. The P flag is set to 1, when the result in accumulator contains even
number of 1s.
Program Counter (PC). This 16-bit register deals with sequencing the execution of
instructions. This register is a memory pointer. The microprocessor uses this register to
sequence the execution of the instructions. The function of the program counter is to
point to the memory address from which the next byte is to be fetched. When a byte is
being fetched, the program counter is automatically incremented by one to point to the
next memory location.
Stack Pointer (SP). The stack pointer is also a 16-bit register, used as a memory pointer.
It points to a memory location in R/W memory, called stack. The beginning of the stack
is defined by loading 16-bit address in the stack pointer.
Control Unit. Generates signals on data bus, address bus and control bus within
microprocessor to carry out the instruction, which has been decoded. Typical buses and
their timing are described as follows:
11
9 Data bus carries data in binary form between icroprocessor and other
external units such as memory. It is used to transmit data i.e.
information, results of arithmetic etc. between memory and the
microprocessor. Data bus is bidirectional in nature. The data bus width
of 8085 microprocessor is 8-bit i.e. 28 combination of binary digits and
are typically identified as D0 – D7. Thus size of the data bus determines
what arithmetic can be done. If only 8-bit wide then largest number is
11111111 (255 in decimal). Therefore, larger numbers have to be
broken down into chunks of 255. This slows microprocessor.
9 Address Bus: The address bus carries addresses and is one way bus
from microprocessor to the memory or other devices. 8085
microprocessor contain 16-bit address bus and are generally identified
as A0 - A15. The higher order address lines (A8 – A15) are
unidirectional and the lower order lines (A0 – A7) are multiplexed
(time-shared) with the eight data bits (D0 – D7) and hence, they are
bidirectional.
I. Control Bus: Control bus are various lines which have specific functions for
coordinating and controlling microprocessor operations. The control bus carries control
signals partly unidirectional and partly bidirectional. The following control and status
signals are used by 8085 processor:
II. ALE (output): Address Latch Enable is a pulse that is provided when an address appears
on the AD0 – AD7 lines, after which it becomes 0.
III. RD (active low output): The Read signal indicates that data are being read from the
selected I/O or memory device and that they are available on the data bus.
IV. WR (active low output): The Write signal indicates that data on the data bus are to be
written into a selected memory or I/O location.
V. IO/M(output): It is a signal that distinguished between a memory operation and an I/O
operation. When IO/M= 0 it is a memory operation and IO/M=1 it is an I/O operation.
VI. S1 and S0 (output): These are status signals used to specify the type of operation being
performed.
12
The 8085 processor performs these functions using address bus, data bus and control bus shown
as below.
Properties:
x It is a 8-bit microprocessor
x Manufactured with N-MOS technology
x 40 pin IC package
x It has 16-bit address bus and thus has 216 = 64 KB addressing capability.
x Operate with 3 MHz single-phase clock
x +5 V single power supply
The logic pin layout and signal groups of the 8085 microprocessor are shown in the
following figure.
13
1.7. Pin configuration of 8085
The address bus is a group of sixteen lines i.e A0-A15. The address bus is unidirectional, i.e.,
bits flow in one direction from the microprocessor unit to the peripheral devices and uses the
high order address bus.
ALE – It is an Address Latch Enable signal. It goes high during first T state of a machine cycle
and enables the lower 8-bits of the address, if its value is 1 otherwise data bus is activated.
IO/M’ – It is a status signal which determines whether the address is for input-output or
memory. When it is high(1) the address on the address bus is for input-output devices. When it is
low(0) the address on the address bus is for the memory.
SO, S1 – These are status signals. They distinguish the various types of operations such as halt,
reading, instruction fetching or writing.
14
RD’ – It is a signal to control READ operation. When it is low the selected memory or input-
output device is read.
WR’ – It is a signal to control WRITE operation. When it goes low the data on the data bus is
written into the selected memory or I/O location.
READY – It senses whether a peripheral is ready to transfer data or not. If READY is high(1)
the peripheral is ready. If it is low(0) the microprocessor waits till it goes high. It is useful for
interfacing low speed devices.
XI, X2 – A crystal is connected at these two pins. The frequency is internally divided by two,
therefore, to operate a system at 3MHZ the crystal should have frequency of 6MHZ.
CLK (OUT) – This signal can be used as the system clock for other devices.
The 8085 has five interrupt signals that can be used to interrupt a program execution.
(i) INTR
(v) TRAP
Reset Signals:
RESET IN’ – When the signal on this pin is low(0), the program-counter is set to zero, the buses
are tristated and the microprocessor unit is reset.
15
RESET OUT – This signal indicates that the MPU is being reset. The signal can be used to reset
other devices.
DMA Signals:
HOLD – It indicates that another device is requesting the use of the address and data bus.
Having received HOLD request the microprocessor relinquishes the use of the buses as soon as
the current machine cycle is completed. Internal processing may continue. After the removal of
the HOLD signal the processor regains the bus.
HLDA – It is a signal which indicates that the hold request has been received after the removal
of a HOLD request, the HLDA goes low.
SID and SOD – SID is a data line for serial input where as SOD is a data line for serial output.
Timing Diagram is a graphical representation. It represents the execution time taken by each
instruction in a graphical format. The 8085 microprocessor has 5 basic machine cycles. They are
16
1.8. Timing Diagram for opcode fetch Cycle
x The memory read machine cycle is executed by the processor to read a data byte from
memory.
x The processor takes 3T states to execute this cycle.
x The instructions which have more than one byte word size will use the machine cycle
after the opcode fetch machine cycle.
17
1.9. Timing Diagram for Memory Read
x In a memory write cycle the CPU sends data from the accumulator or any other
register to the memory. The timing diagram for a memory for a memory write
cycle is shown in the following figure.
x The status signals S0 and S1 are 1 and 0 respectively for write operation. WR
goes low in T2 indicating that the write operation is to be performed.
x During T2 the AD bus is not disabled as it is done in case of memory or I/O
operation.
18
1.10. Timing Diagram for Memory Write
Review Questions
1. What is microprocessor?
2. What are the functions of an accumulator?
3. List the 16 – bit registers of 8085 microprocessor.
4. What is the purpose of READY and TRAP pins in 8085 Microprocessor?
5. List the operations performed by IO/M in 8085.
6. What are the basic units of a microprocessor?
7. What is a bus?
8. List few applications of microprocessor-based system.
9. Give the power supply & clock frequency of 8085.
10. Define ALU.
11. What do you mean by input port & output port?
12. What is the difference between a Microprocessor & CPU?
13. Why is the data bus bidirectional?
14. Specify the four control signals commonly used by the 8085 MPU.
19
15. What determines that Microprocessor is an 8, 16 or 32 bit?
16. Explain about evolution of microprocessor in detail.
17. Discuss about the real time applications of microprocessor.
18. Write a short note about Digital computers.
19. What are the various types of semiconductor memory? Describe them briefly.
20. Define Microprocessor. Illustrate the architecture of microprocessor and explain its
components.
21. Draw the pin diagram of 8085 Microprocessor and explain the function of various
signals.
20
UNIT II: Instruction Set Of Intel 8085
2.1. Introduction
Data transfer instructions are used to transfer data from one register to another
register, from memory to register or register to memory. In this group data transferred from
source to destination without any modification of data. Examples are: MOV, MVI, LXI, LDA,
STA etc.
Arithmetic Group:
Logical Group:
Logic group instructions perform logic operations such as AND, OR and XOR,
compare data between registers or between register and memory, rotate and complement data in
registers. Examples are: ANA, XRA, ORA, CMP, RAL etc.
The branch group instructions allow the microprocessor to change the sequence of a
program, either unconditionally or under certain test conditions. This group includes:
x Jump instructions
x Call and Return instructions
x Restart instructions
21
Examples are: JMP, JC, JNC, CALL, RST etc.
This group includes the instructions for input/output ports, stack and machine control.
Examples are: IN, UT, PUSH, POP, HLT etc.
Each instruction has two parts: one is task to be performed, called the operation code
(opcode), and the second is the data to be operated on, called the operand. The operand (or data)
can be specified in various ways. It may include 8-bit (or 16-bit) data, an internal register, a
memory location, or 8-bit (or 16-bit) address. In some instructions, the operand is implicit. The
8085 instruction set is classified into the following three groups according to word size:
In the 8085, "byte" and "word" are synonymous because it is an 8-bit microprocessor. However,
instructions are commonly referred to in terms of bytes rather than words.
The way by which the microprocessor identifies the operands for a particular
instruction is known as Addressing mode. Intel 8085 uses the following addressing modes:
In this type of addressing mode the operand is specified within the instruction
itself. Consider the following instruction: ADI 34H – This instruction adds the immediate data,
34H to the accumulator.
34H is the data here. H represents Hexadecimal value and the immediate value is
added to the accumulator. In this case 34H is added to the accumulator. Suppose if accumulator
has a value 8H and when this instruction is executed, 34H is added to the 8H and the result is
stored in accumulator.
22
2.3.2 Register Addressing
In this type of addressing mode the instruction specifies the name of the register
in which the data is available and Opcode specifies the name (or) address of the register on
which the operation would be performed.
Examples are:
(1)MOV A, B
Here the Opcode is MOV. If the above instruction is executed, the contents of Register
B are moved to the Register A, which is nothing but the accumulator.
(2) SUB H
If we execute the above instruction the contents of Register H will be subtracted from
the contents of the accumulator.
In this mode of addressing, the address of the data (operand) is specified within the
instruction.
There is a subtle difference between the direct addressing modes and immediate addressing
modes. In immediate addressing mode the data itself is specified within instruction, but in direct
addressing mode the address of the data is specified in the instruction.
Examples are:
Consider the instruction STA 2000H. When this instruction is executed, the contents of
the accumulator are stored in the memory location specified. In the above example the contents
of accumulator are stored in memory location 2000H.
This is indirect way of addressing. In this mode the instruction specifies the name of the
register in which the address of the data is available.
Consider MOV A, M. This instruction will move the contents of memory location, whose
address is in H-L register pair to the accumulator. M represents the address present in the H-L
register pair. So when MOV A, M is executed, the contents of the address specified in H-L
register pair are moved to accumulator.
23
2.4. Status Flags
The Flag register is a Special Purpose Register. Depending upon the value of result after
any arithmetic and logical operation the flag bits become set (1) or reset (0). In 8085
microprocessor, flag register consists of 8 bits and only 5 of them are useful. The five flags are
The respective position of these flag bits in flag register has been show the below figure. The
positions marked by “x” are to be considered as don't care bits in the flags register. The user is
not required to memorize the positions of these flags in the flags register.
Sign Flag (S) – After any operation if the MSB (B(7)) of the result is 1, it indicates the
number is negative and the sign flag becomes set, i.e. 1. If the MSB is 0, it indicates the number
is positive and the sign flag becomes reset i.e. 0, from 00H to 7F, sign flag is 0,from 80H to FF,
sign flag is 1,1- MSB is 1 (negative),0- MSB is 0 (positive)
Example:
SUB B (A = A – B)
These set of instructions will set the sign flag to 1 as 30 – 40 is a negative number.
After any arithmetical or logical operation if the result is 0 (00)H, the zero flag
becomes set i.e. 1, otherwise it becomes reset i.e. 0. Example:
24
SUB A (A = A – A)
These set of instructions will set the zero flag to 1 as 10H – 10H is 00H
Carry is generated when performing n bit operations and the result is more than n bits,
then this flag becomes set i.e. 1, otherwise it becomes reset i.e. 0. During subtraction (A-B), if
A>B it becomes reset and if (A<B) it becomes set. Carry flag is also called borrow flag.
Example:
SUB B (A = A – B)
These set of instructions will set the carry flag to 1 as 30 – 40 generates a carry/borrow.
This flag is used in BCD number system(0-9). If after any arithmetic or logical
operation D(3) generates any carry and passes on to B(4) this flag becomes set i.e. 1, otherwise it
becomes reset i.e. 0. This is the only flag register which is not accessible by the programmer.
Example:
ADD B (A = A + B)
These set of instructions will set the auxiliary carry flag to 1, as on adding 2B and 39, addition of
lower order nibbles B and 9 will generate a carry.
If after any arithmetic or logical operation the result has even parity, an even number
of 1 bits, the parity register becomes set i.e. 1, otherwise it becomes reset i.e. 0. Example:
This instruction will set the parity flag to 1 as the BCD code of 05H is 00000101, which contains
even number of ones i.e. 2.
25
2.5. Intel 8085 instructions
Instructions which are used to transfer the data from a register to another register from
memory to register or register to memory come under this group.
(1) MOV r1,r2: Move the content of the one register to another. For example, the
instruction MOV A,B moves the content of register B to register A.
(2) MOV r,M: Move the content of memory to register. For example the instruction
MOV B,M will move the content of memory location to register B.
(3) MOV M,r: Move the content of register to memory. For example the instruction
MOV M,C will move the content of register C to memory.
(4) MVI r,data: Move immediate data to register. For example the instruction MVI A,05
moves 05 to register A.
(5) MVI M,data: Move immediate data to memory. For example the instruction MVI
M,08 will move 08 to memory.
The instructions of this group perform arithmetic operations such as addition, subtraction,
increment or decrement of the content of a register or a memory. Examples are:
(1) ADD r : Add register to accumulator. The content of register r is added to the content
of accumulator, and the sum is placed in the accumulator.
(2) ADD M: Add memory to accumulator. The content of memory location addressed by
H-L pair is added to the content of the accumulator. The sum is placed in the
accumulator.
(3) ADC r: Add register with carry to accumulator. The content of register r and carry
status are added to the content of the accumulator. The sum is placed in the
accumulator.
(4) ADC M: ADD memory with carry to accumulator. The content of the memory
location addressed by H-L pair and carry status are added to the accumulator. The sum
is placed in the accumulator.
(5) ADI data: Add immediate data to accumulator. The immediate data is added to the
content of the accumulator. The 1st byte of the instruction is opcode. The 2nd byte of
the instruction is data, and it is added to the content of the accumulator, The sum is
placed in the accumulator.
26
2.5.3. Logical Group
The instructions in this group perform logical operation such as AND, OR, compare,
rotate, etc. Examples are:
(1) ANA r: AND register with accumulator. The content of register r is ANDed with the
content of the accumulator, and the result is placed in the accumulator. All status
flags are affected. The flag CS is cleared, i.e. it is set to 0. Auxiliary carry flag AC is
set to 1.
(2) ANA M: AND memory with accumulator. The content of the memory location
addressed by H-L pair is ANDed with the accumulator. the result is placed in the
accumulator. All flags are affected. The CS is set to 0 and AC to 1.
(3) ANI data: AND immediate data with accumulator. The second byte of the instruction
is data and it is ANDed with the accumulator. The CS flag is set to 0 and AC to 1.
(4) ORA r: OR-register with accumulator. The content of register r is ORed with the
content of the accumulator. The CS flag is set to 0 and AC to 1.
(5) ORA M: OR-memory with accumulator. The content of the memory location
addressed by H-L pair is ORed with the accumulator. The CS nd AC flags are set to
0.
This group contains the instructions for conditional and unconditional jump, subroutine
call and return, and restart. Examples are:
27
(3) CALL addr(label). Call the subroutine identifies by the operand. CALL
instruction is used to call a subroutine. Before the control is transferred to the
subroutine the address of the next instruction of the main program is saved in the
stack. The content of the stack pointer is decremented by two to indicate the new stack
top. Then the program jumps to subroutine starting at address specified by the label.
(4) RET. Return from subroutine. RET instruction is used at the end of the
subroutine. Before the execution of the subroutine the address of the next instruction
of the main program is saved on the stack. The execution of the RET instruction brings
back the saved address from the stack of the program counter. The content of the stack
pointer is incremented by 2 to indicate the new stack top. Then the program jumps to
the instruction of the main program next to CALL instruction which called the
subroutine.
Examples are: RST n, PCHL.
This group contains the instructions for input/output ports, stack and machine control.
Examples are:
(1) IN port – address: Input to accumulator from I/O port. The data available on the port
is moved to the accumulator. After the instruction IN, the address of the port is
specified. The second byte of the instruction contains the address of the port.
(2) OUT port-address: Output from accumulator to I/O port. The content of the
accumulator is moved to the port specified by its address. After the OUT instruction,
the port address is specified. The second byte of the instruction contains the address
of the port.
(3) PUSH rp: Push the content of register pair to stack . The content of the register pair
rp is pushed into the stack.
(4) PUSH PSW: Push processor word. The content of the accumulator is pushed into the
stack. The content of status flags are also pushed into the stack. The content of the
register SP is decremented by 2 to indicate new stack top.
(5) SPHL: Moves the contents of H-L pair to stack pointer. The contents of H-L pair are
transferred to the SP register.
2.6.1. Introduction
28
x A program written in the form of zeros and ones called a machine language
program. In the machine language there is a specific binary code for each
instruction. For example for Intel 8085 to add the contents of register A and
register B the binary code is 10000000.
A programmer can easily write a program in alphanumeric symbols instead of zeros and
ones. Meaningful and remember able symbols are chosen for the purpose. Examples are: ADD
for addition, SUB for subtraction etc. Such symbols are called mnemonics. A program written in
mnemonics is known as assembly language program. The writing of a program in assembly
language is much easier and faster as compared to the writing of a program in machine language.
When a program is written in a language other than machine language, a computer cannot
understand it. Consequently, a program written in other languages has to be translated into
machine language before it is executed. A program which translates an assembly language
program into machine language is called an assembler.
An assembler which goes through an assembly language program only once is known as
one-pass assembler. Such an assembler must have some technique to take the forward
references into account.
One-pass assembler is faster as it goes through a program only once. Its disadvantage is
that it does not provide as many features as a two-pass assembler can.
Example: An assembly language program for the addition of two numbers placed in two
consecutive memory locations 2501H and 2502H is given below. The sum is stored in the
memory location 2503H.
Mnemonics, operands, data of the program and starting address for the program are
fed to the computer. The assembler converts the program into a machine language program
before the execution of the program. The codes are written in hexadecimal system.
Mnemonics operands
LXI H,2501H
MOV A, M
INX H
29
ADD M
STA 2503H
HLT
DATA
2501- 49H
2502- 56H
Result:
2503- 9F
The advantages over to high level language such as FORTRAN, COBOL etc. is that the
computation time is less. An assembly language program is faster to produce result. The
disadvantages of assembly language are:
2.7. Stacks
The stack is a group of memory location in the R/W memory that is used for temporary
storage of binary information during the execution of a program. The stack is a LIFO structure
Last In First Out. The starting location of the stack is defined by loading a 16 bit address into the
stack pointer that spaced is reserved, usually at the top of the memory.
The stack normally grows backwards into memory. The stack can be initialized
anywhere in the user memory map, but stack is initialized at the highest memory location so that
there will not be any interface with the program.
In 8085 microprocessor system the beginning of the stack is defined in the program by
using the instruction LXI SP,16 bit. The LXI SP,a 16 bit state that load the 16 bit address into the
stack pointer register.
The 8085 provide two instructions PUSH & POP for storing information on the stack
and retrieving it back. Information in the register pairs stored on the stack in reverse order by
30
using the instruction PUSH. Information retrieved from the stack by using the instruction POP.
PUSH & POP both instruction works with register pairs only. The storage and retrieval of the
content of registers on the stack fallows the LIFO(Last-In-First-Out) sequence. Information in
the stack location may not be destroyed until new information is stored in that memory location.
2.8. Subroutines
The 8085 has two instructions for dealing with subroutines. The CALL instruction is
used to redirect program execution to the subroutine. The RET instruction is used to return to the
main program at the end of the subroutine.
The RET instruction: Return unconditionally from the subroutine. This instruction
locates the return address on the top of the stack and transfers the program execution back to the
calling program.
2.9. MACRO
Example.
LXI H, ADDRESS
MOV A,M
CMA
ENDM
31
In the above example COMPLE is the name of the macro. MACRO is written in the
beginning of the definition. ADDRESS is a parameter. ENDM is used to end the macro.
2.10. Microprogramming
1. The CPU places the content of the program counter on the address bus to fetch the
opcode of the instruction from the memory.
2. The CPU reads the opcode from the memory and places it in the instruction register.
3. The CPU decodes the instruction.
4. The CPU takes other data, if necessary, from the memory or other register to execute the
instruction.
5. The CPU executes the instruction.
Review Questions
1. What is an instruction?
2. List the types of instructions.
3. What are three types of instructions based on length?
4. Define addressing modes.
5. What are the types of addressing modes?
6. What is status flag?
7. What is assembly language?
8. Define assembler.
9. What do you mean by assembly language program?
10. What is Stack?
11. What is meant by subroutines?
12. Classify 8085 instruction in various groups. Give examples of instructions for each
group.
13. What are the various types of data formats for Intel 8085 instructions? Give examples for
each type of data format.
14. Discuss various types of addressing modes of Intel 8085 with suitable examples.
15. Write short notes on assembly language program.
16. What is stack? What is the function of stack pointer? Discuss PUSH and POP operation.
17. Explain subroutine. What instruction is used to call a subroutine?
18. Explain macro. What is the difference between a macro and subroutine?
32
UNIT III- ASSEMBLY LANGUAGE PROGRAMMING
3.1. Introduction
To learn assembly language programming the beginner should write simple programs and
try to execute them n Intel 8085 microprocessor kit. The memory addresses given in the
programs are for a particular microprocessor kit. Before writing assembly language program, one
should learn some important Intel 8085 instructions such as MOV, MVI, ADD, SUB, LXI, LDA,
INX, INR, HLT etc.
PROGRAM
The instruction MVI A,05 will move 05 to register A. In the code from it is written as
3E, 05. The first byte of the instruction is 3E. This code is for MVI A. The second byte 05 is the
33
data which is to be placed in A. The instruction MOV B,A transfers the content of register A to
register B. After the execution of the program register B will contain 05.
Problem:
2009 76 HLT
34
DATA
2501- 49H
2502- 56H
Result
2503- 9F H.
9 2501 H is the address of memory location for the first number. 2501 is placed in H-L pair
by the instruction LXI H, 2501 H. The next instruction is MOV A,M which moves the
content of the memory location addressed by H-L pair to the accumulator.
9 In this case H-L pair contains 2501 H and, therefore, the content of the memory location
2501H is moved to the accumulator. Thus the first number 49H has been moved to the
accumulator.
9 The instruction INX H increases the content of H-L pair by one. Previously the content of
H-L pair was 2501H. After the execution of INX H it becomes 2502H. ADD M adds the
content of the accumulator and the content of the memory location addressed by H-L
pair.
9 The content of 2502 H is the second number 56H. So 56H is added to 49H. Sum resides
in the accumulator. The instruction STA 2503H stores the sum in the memory location
2503H. The instruction HLT ends the program.
Problem:
35
2004 23 INX H Content of H-L pair
increases from 2501H to
2502H.
2005 96 SUB M First number – Second
number.
DATA
2501- 49H
2502- 32H
2503- 17H.
9 The first number is in the memory location 2501H. 2501 is placed in H-L pair by the
execution of the instruction LXI H, 2501 H. The instruction MOV A,M moves the
content of the memory location addressed by H-L pair to the accumulator.
9 Thus the first number 49H has been moved to the accumulator. The instruction INX H
increases the content of H-L pair by one. Previously the content of H-L pair was 2501H.
After the execution of INX H it becomes 2502H.
9 SUB B subtracts the content of the accumulator from the content of the memory location
addressed by H-L pair. The content of 2502 H is the second number 32H. So 32H is
subtracted from 49H. The result resides in the accumulator. The instruction STA 2503H
stores the result in the memory location 2503H. The instruction HLT ends the program.
Problem:
Sum=159=01, 59 D
36
01 is the MSDs of the sum.
DATA
2501- 84D
2502- 75D
Result
37
2010 79 MOV A,C MSDs of sum in accumulator.
2014 76 HLT
The program for “Decimal addition of two 8-bit number” is same as that for “addition of two
8-bit numbers” except that DAA instruction has been used for decimal adjustment after the
instruction ADD M. After the execution of the ADD M the sum is in hexadecimal. The DAA
instruction makes correction and the final result is obtained in decimal system.
Problem:
DAA instruction cannot be used after SUB or SBB instruction for decimal subtraction. It is
used only after DD, ADC. Therefore, for decimal subtraction the number which is to be
subtracted is converted into 10’s complement. In this example 38D is to be subtracted. 10’s
complement of 38 is first obtained and then it is added to 96D.
DATA
2501- 96
2502- 38
Result
2503- 58
38
2003 3E,99 MVI A,99 Place 99 in accumulator.
3.4. Complements
Example: Find one’s complement of 96 H. The number in the binary form is represented as
follows:
96 H = 1001 0110
(9) (6)
(6) (9)
To obtain one’s complement of a number its 0 bits are replaced by 1 and 1 by 0. The number is
placed in the memory location 2501 H. The result is stored in the memory location 2502 H.
39
2003 2F CMA Take its
complement.
2004 2,02,25 STA 2502 H Store result in 2502
H.
2007 76 HLT Halt
DATA
2501- 96 H
Result
2502- 69 H
The instruction LDA 2501 H transfers the number from memory location 2501 H to the
accumulator. CMA takes complement of the number. STA 2502 H stores the result in the
memory location 2502 H. HLT ends the program.
The number is in the memory location 2501 and 2502 H. The result is to be stored in the memory
locations 2503 H and 2504 H.
40
2004 2F CMA Complement of 8 LSBs of
the number.
2005 32,03,25 STA 2503 H Store 8 LSBs of result.
2008 23 INX H Address of 8 MSBs of the
number.
2009 7E MOV A,M 8 MSBs of the number in
accumulator.
200A 2F CMA Complement of 8 MSBs of
the number.
200B 32,04,25 STA 2504 Store 8 MSBs of the result.
DATA
Result
The 8 LSBs of the number re in the memory location 2501 H. The address 2501 is placed in
H-L pair. The 8 LSBs of the number are transferred from 2501 H to the accumulator. The
instruction CMA takes one’s complement of 8 LSBs. The 8 LSBs of the result are stored in the
memory location 2503 H. The address of 8 MSBs of the number is 2502 H, and it is placed in H-
L pair. The 8 MSBs of the number are transferred from 2502 H to the accumulator. The
instruction CMA takes one’s complement 0f 8 MSBs. The 8 MSBs of the result are stored in
memory location 2504.
3.5. Shift
41
65= 0110 0101
(6) (5)
Result of shifting
To shift a number left by one bit the number is added to itself or it is doubled. If 65 is added
to 65, the result is CA as shown below.
1100 1010= CA
DATA
2501- 65 h
Result
2502- CA H
The instruction LDA 2501 H transfers the number from memory location 2501 H to the
accumulator. ADD A adds the contents of the accumulator to itself. The result is twice the
number and thus the number is shifted left by one bit. This program does not take carry into
42
account after ADD instruction. If numbers to be handled are likely to produce carry the program
may be notified to store it.
(1) (5)
(2) (A)
The shifting of number left by two bits can be achieved by adding the number to itself and
again adding the sum to itself. This is obtained by using the instruction ADD A twice.
PROGRAM
DATA
2501- 15 H
Result
2502- 54H
43
3.5.3. Shift a 16-bit number Left by One Bit
Result of shifting left by one bit = 1110 1011 0010 1100= EB2C
DATA
Result
44
Result of shifting left by one bit =0010 1011 0010 1100= 2B2C
DATA
Result
3.5. Mask
Example:
Number = A6
= 1010 0110
(A) (6)
45
Result = A0 = 1010 0000
(A) (0)
The LSD of the given number A6 is 6. The MSD of the number A6 is A. In the binary form it
is 1010. If this number is multiplied by 1111 i.e. F, it will not be affected. Similarly the LSD of
the number is 6. In the binary form is represented by 0110. If it is multiplied by 0000, it becomes
0000 i.e. it is cleared. Thus if the number A6 is multiplied by F0, the LSD of the number is
masked off.
DATA
2501- A6
Result
2502- A0
Example:
Number = A6
= 1010 0110
(A) (6)
(0) (6)
46
To mask off 4 most significant bits of a number, 4 MSBs are multiplied by 0000. The least
significant bits are not to be affected and, therefore, they are multiplied by 1111 i.e. F. Thus if an
8 bit number is multiplied by 0F, the 4 most significant bits are cleared.
DATA
2501- A6
Result
2502- 06
Address
47
2005H MVI D, 0AH Counter for 10 elements
example: 42H, 21H, 01H, 1FH, FFH, 25H, 32H, 34H, 0AH, ABH
Arrange E5, A9, 96, B4 and 15 in ascending order. These numbers are in the memory
locations 2501 to 2505 H.
48
Address Machine Label Mnemonics Operands Comments
Codes
2000 11, 01, 26 LXI D,2601 Memory locations to store
result.
2003 21, 00, 25 LXI H,2500 Count address in H-L pair.
2006 46 MOV B,M
2007 C2,00,22 START CALL 2200 Call subroutine-1 to find
smallest number.
200A 12 STAX D Store the result.
200B CD,50,20 CALL 2050 Call subroutine-2 to check
which number is smallest
200E 13 INX D
200F 05 DCR B
2010 C2,07,20 JNZ START
2013 HLT stop
SUBROUTINE-2
49
205F 77 MOV M,A Replace the smallest
number by FF
2060 C9 RET
EXAMPLE:
DATA
2500 – 05, 2501 – E5, 2502 – A9, 2503 – 96, 2504 – B4, 2505 – 15
RESULT
DATA: 2500 – 04, 2501 – 16, 2502 – 2B, 2503 – 39, 2504 – 12
Result: 2450 – 8C
3.9. Multiplication
50
2003 SPHL SAVE IT IN STACK POINTER
200E DAD SP
INPUT:
(2050H) = 04H
(2051H) = 07H
(2052H) = 02H
(2053H) = 01H
OUTPUT:
51
(2054H) = 08H
(2055H) = 12H
(2056H) = 01H
(2057H) = O0H
3.10. Division
INPUT:
(2050H) = 04H
(2051H) = 00H
(2052H) = 02H
(2053H) = 00H
OUTPUT:
(2054H) = 02H
(2055H) = 00H
(2056H) = FEH
(2057H) = FFH
52
200A MOV A, L A<-L
Review Questions
1. Write an assembly language program to add two 8- bit numbers, the sum may be of
16 bits.
2. Write an assembly language program to add two 8-bit decimal numbers, sum may be
of 16 bits.
3. Write an assembly language program to get 2’s complement of a 16-bit number.
4. Write an assembly language program to find the largest number in a data array.
5. Write an assembly language program to find the sum of a series of 8-bit numbers,
sum may be of 16-bits.
6. Write an assembly language program to find the smallest number in a array.
7. Write an assembly language program for 8- bit multiplication.
8. Write an assembly language program for 8-bit division.
53
UNIT IV- PERIPHERAL DEVICES AND THEIR INTERFACING
4.1. Introduction
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.
In this scheme there is only one address space. Address space is defined as set of all
possible addresses that a microprocessor can generate. Some address are assigned to memories
and some address to I/O devices. Suppose memory locations are assigned the address 2000-2500.
One address is assigned to each memory location. These addresses cannot be assigned to I/O
devices. The addresses assigned to I/O devices are different from address assigned to memory.
For example, 2500, 2501, 2502 etc. may be assigned to I/O devices. One address is assigned to
each I/O device.
In this scheme all the data transfer instruction of the microprocessor can be used for
both memory as well as I/O devices. 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.
In this scheme the address are assigned to memory locations can also be assigned to I/O
devices. To distinguish whether the address on an address bus is for memory location or I/O
devices. The Intel 8085 issues IO/M…… signal for this purpose. When the signal is high the
address of an address bus is for I/O device. When low, the address is for a memory location. Two
extra instructions IN and OUT are used to address I/O device. The IN instruction is used to read
data from an input device. And OUT instruction is used to an output device. This scheme is
suitable for large system.
54
4.2. Memory Interfacing
An address decoding circuit is employed to select the required I/O device or a memory
chip. When IO/M is high, decoder is to active and the require IO device is selected. If IO/M is
low, the decoder1 is activated the required memory chip is selected. A few MSB of address line
is applied to the decoder to select the memory chip or an I/O device.
The method that is used to transfer information between internal storage and external I/O
devices is known as I/O interface. The CPU is interfaced using special communication links by
the peripherals connected to any computer system. These communication links are used to
resolve the differences between CPU and peripheral. There exists special hardware components
between CPU and peripherals to supervise and synchronize all the input and output transfers that
are called interface units.
Data transfer to and from the peripherals may be done in any of the three possible ways
Programmed I/O: It is due to the result of the I/O instructions that are written in the computer
program. Each data item transfer is initiated by an instruction in the program. Usually the
55
transfer is from a CPU register and memory. In this case it requires constant monitoring by the
CPU of the peripheral devices.
Example of Programmed I/O: In this case, the I/O device does not have direct access to
the memory unit. A transfer from I/O device to memory requires the execution of several
instructions by the CPU, including an input instruction to transfer the data from device to the
CPU and store instruction to transfer the data from CPU to memory. In programmed I/O, the
CPU stays in the program loop until the I/O unit indicates that it is ready for data transfer. This is
a time consuming process since it needlessly keeps the CPU busy. This situation can be avoided
by using an interrupt facility.
Direct Memory Access: The data transfer between a fast storage media such as magnetic disk
and memory unit is limited by the speed of the CPU. Thus we can allow the peripherals directly
communicate with each other using the memory buses, removing the intervention of the CPU.
This type of data transfer technique is known as DMA or direct memory access. During DMA
the CPU is idle and it has no control over the memory buses. The DMA controller takes over the
buses to manage the transfer directly between the I/O devices and the memory unit.
Burst Transfer : DMA returns the bus after complete data transfer. A register is used as a byte
count, being decremented for each byte transfer, and upon the byte count reaching zero, the
DMAC will release the bus. When the DMAC operates in burst mode, the CPU is halted for the
duration of the data transfer.
Cyclic Stealing :
An alternative method in which DMA controller transfers one word at a time after which it
must return the control of the buses to the CPU. The CPU delays its operation only for one
memory cycle to allow the direct memory I/O transfer to “steal” one memory cycle.
Synchronous means “ at the same time”. The device which spends data and the device which
receives data are synchronized with the same clock. When the CPU and I/O devices match in
speed this technique of data transfer is employed.
Synchronous transmission is effective, dependable, and often utilised for transmitting a large
amount of data. It offers real-time communication between linked devices. An example of
synchronous transmission would be the transfer of a large text file. Before the file is transmitted,
it is first dissected into blocks of sentences. The blocks are then transferred over the
communication link to the target location.
56
Because there are no beginning and end bits, the data transfer rate is quicker but there’s an
increased possibility of errors occurring. Over time, the clocks will get out of sync, and the
target device would have the incorrect time, so some bytes could become damaged on account of
lost bits. To resolve this issue, it’s necessary to regularly re-synchronise the clocks, as well as to
make use of check digits to ensure that the bytes are correctly received and translated.
In the asynchronous mode of transfer, microprocessor is busy all the time in checking for the
availability of data from the slower I/O devices. And it also busy in checking if I/O device is
ready for the data transfer or not. In other words in this data transfer scheme, some of the
microprocessor time is wasted in waiting while an I/O device is getting ready. To overcome this
57
problem interrupt driven I/O data transfer introduced. In this interrupt driven I/O data transfer
method the I/O device informs the microprocessor for the data transfer whenever the I/O device
is ready. This is achieved by interrupting the microprocessor by using the interrupt pins of
microprocessor.
In the beginning the microprocessor initiates data transfer by requesting the I/O device ‘to get
ready’ and then continue executing its original program rather wasting its time by checking the
status of I/O device. Whenever the device is ready to accept or supply data, it informs the
processor through a control signal. This control signal known as interrupt (INTR) signal. In
response to this interrupt signal, the microprocessor sends back an interrupt acknowledge signal
to the I/O device. Interrupts driven data transfer is better from asynchronous mode but it is still
not very effective technique when data needs to be transferred in large amounts because it
requires an interrupt for every character read or written. This leads us to an another approach
called direct memory access(DMA) mode.
Interrupt is a process where an external device can get the attention of the microprocessor.
The process starts from the I/O device. The process is asynchronous, means can occur at any
time during execution of program. ,QRUGHUWRFRPPXQLFDWHZLWKȝ3 ,2GHYLFHVHLWKHU3ROOLQJ
or Interrupt method is used. An interrupt is considered to be an emergency signal. The
Microprocessor should respond to it as soon as possible.
58
4.4. Schematic Diagram of 8085 Interrupts
Interrupt is signal send by an external device to the microprocessor to request the processor
to perform a particular task or work. It is a simple routine program that keeps a check for the
occurrence of the interrupt. Mainly in the microprocessor based system the interrupts are used
IRU GDWD WUDQVIHU EHWZHHQ WKH SHULSKHUDO ,2 DQG WKH PLFURSURFHVVRU ,I WKH ȝ3 DFFHSW WKH
interrupt and send the INTA (active low) signal to the peripheral. When interrupt is receLYHGȝ3
suspends its current activity and upon completion, it resumes the suspended activity. The
processor executes an interrupt service routine (ISR) addressed in program counter. It returned to
PDLQ SURJUDP E\ 5(7 LQVWUXFWLRQ $GYDQWDJH LV WKDW ȝ3 QHHG not waste time in polling the
devices.
x When the MPU is executing a program it checks all the interrupt lines during the
execution of each instruction.
59
x If any Interrupt line is enables, the processor completes the current going
instruction execution.
x If more than one lines are enabled simultaneously then the processor pick up the
request which have the highest priority and all other are discarded.
x After completion of the current instruction execution, processor checks for the
respective conditions for the activated interrupt or selected interrupt in case of
more than one.
x If condition are not favorable then request is discarded or stored or if the condition
are favorable then the processor generates an external INTA or internal
acknowledges signal to insert a RST(restart) instruction or the vector location
respectively.
x Now the processor save the address of the next instruction (program counter
value) on to stack and switch to the related RST location or vector location.
x Service routine written on the location is completed which have RET as its last
instruction which returns the program control to the main program by retrieving
the return address from the stack.
i. Software Interrupt
ii. Hardware Interrupt
The vector address for these interrupts can be calculate as Interrupt number * 8 = vector address
For RST 5 5*8 = 40(in decimal) =28H (in Hexa) Vector address for interrupt RST5 is 0028H.
This vector address is stored in Program Counter(PC). These instruction allow transfer of
program control from the main program to predefined service routine is also referred to as
ISR(Interrupt Service Routine).
Hardware interrupts: This interrupt is caused by sending a signal on one of the interrupt pins of
the microprocessor. An external device initiates the hardware interrupts and placing an
appropriate signal at the interrupt pin of the processor. If the interrupt is accepted then the
process or executes an interrupt service routine (ISR). Hardware interrupt is Asynchronous(it
can occur at any time). The 8085 has five hardware interrupts (1)TRAP (2)RST7.5 (3)RST6.5
(4)RST5.5 (5)INTR(address is supplied externally). The hardware interrupts are classified Two
types:
i. Maskable Interrupts
ii. Non-Maskable Interrupts
60
Maskable interrupts: An interrupt which can be disabled by software that means we can disable
the interrupt by sending appropriate instruction, is called a maskable interrupt. RST 7.5, RST 6,
RST 5.5 , INT R are the example of Maskable Interrupt.
Non-Maskable interrupts: Cannot disable the interrupt by sending any instruction is called Non
Maskable Interrupt. TRAP interrupt is the non-maskable interrupt for 8085. It means that if an
interrupt comes via TRAP, 8085 will have to recognize the interrupt we cannot mask it.
Triggering levels: When a device interrupts, it actually wants the MP to give a service which is
equivalent to asking the MP to call a subroutine. This subroutine is called ISR (Interrupt Service
Routine). This interrupts can be enable and disable by using EI (enable interrupt) & DI (disable
interrupt) instructions. The ‘EI’ instruction is a one byte instruction and is used to Enable the
non-maskable interrupts. The ‘DI’ instruction is a one byte instruction and is used to Disable the
non-maskable interrupts.
Enable Interrupt(EI) The interrupt process is enable by using EI instruction in the main
program. It is 1-byte instruction. It enables the interrupt process. Enabling will save the current
status and jumps to an interrupt service routine (ISR). After completion it will return back to the
main program again.
61
be recognized by microprocessor. To enable It again they must be unmasked (enabled) by using
EI.
x A/D converter
x D/A converter
x CRT
x Printers
x Hard disks
x Floppy disks
x Magnetic tapes
Peripherals are connected to the microcomputer through the electronic circuits known as
interfacing circuits.
i. I/O port
ii. Programmable Peripheral Interface(PPI)
iii. DMA controller
iv. Interrupt controller
v. Communication interface
vi. Programmable Counter/Interval Timer
62
Special purpose interfacing devices are designed to interface a particular type of I/O device to
the microprocessor. Examples of such devices are:
i. CRT controller
ii. Floppy Disk Controller
iii. Key Board and Display Interface.
The Mp provides RD and WR signals to initiate read and write cycle. Because these signals
are used both for reading / writing memory or reading writing an input/output device, it is
necessary to generate separate read and write signals for memory and I/O devices. 8085 provides
IO/M signal to indicate that initiated cycle is for I/O device or for memory device. Using IO/M
signal along with RD and WR, it is possible to generate four signals shown below.
An input device is connected to the microprocessor through an input port. An input port is a
place for unloading data. An input device unloads data into the port. The microprocessor reads
data from the input port. Similarly, an output device is connected to the microprocessor through
an output port. As the output port is connected to the output device , data transferred to the
output device.
63
4.8. Interfacing of I/O device through I/O port
The Intel 8212 is an 8-bit nonprogrammable I/O port. It can be connected to the
microprocessor either as an input port or an output port. If we require one input port and one
output port, two units of 8212 will be required. One of them will be connected in input mode and
other in output mode.
64
The SCL 6532 is a RAM, I/O, Interval Timer Device(RIOT) manufactured
semiconductor Complex LTD. It has an 8-bit bidirectional data bus, 12x8 state R two 8-
bit bidirectional data ports.
It operates with 1 MHz and 2 MHz clock and single supply +5V implemented in a 40-
pin IC. It has been designed to operate in conjunction with the SCL microprocessor
family. SCL 6502 is also manufactured by semiconductor Complex Ltd.
PPI 8255 is a general purpose programmable I/O device designed to interface the CPU with its
outside world such as ADC, DAC, keyboard etc. We can program it according to the given
condition. It can be used with almost any microprocessor. It consists of three 8-bit bidirectional
I/O ports i.e. PORT A, PORT B and PORT C. We can assign different ports as input or output
functions.
It is a tri-state 8-bit buffer, which is used to interface the microprocessor to the system data bus.
Data is transmitted or received by the buffer as per the instructions by the CPU. Control words
and status information is also transferred using this bus.
65
Read/Write Control Logic
This block is responsible for controlling the internal/external transfer of data/control/status word.
It accepts the input from the CPU address and control buses, and in turn issues command to both
the control groups.
CS
It stands for Chip Select. A LOW on this input selects the chip and enables the communication
between the 8255A and the CPU. It is connected to the decoded address, and A0 & A1 are
connected to the microprocessor address lines.
WR
It stands for write. This control signal enables the write operation. When this signal goes low, the
microprocessor writes into a selected I/O port or control register.
RESET
This is an active high signal. It clears the control register and sets all ports in the input mode.
RD
It stands for Read. This control signal enables the Read operation. When the signal is low, the
microprocessor reads the data from the selected I/O port of the 8255.
These pins in conjunction with RD and WR pins control the selection of one of the 3 ports.
Group A and Group B controls receive control from the CPU and issues commands to their
respective ports.
Port A: This has an 8 bit latched/buffered O/P and 8 bit input latch. It can be programmed in 3
modes – mode 0, mode 1, mode 2.
Port B: This has an 8 bit latched / buffered O/P and 8 bit input latch. It can be programmed in
mode 0, mode1.
Port C : This has an 8 bit latched input buffer and 8 bit output latched/buffer. This port can be
divided into two 4 bit ports and can be used as control signals for port A and port B. it can be
programmed in mode 0.
66
Operating modes of 8255:
These are two basic modes of operation of 8255. I/O mode and Bit Set-Reset mode (BSR). In
I/O mode, the 8255 ports work as programmable I/O ports, while in BSR mode only port C
(PC0-PC7) can be used to set or reset its individual port bits.
Under the I/O mode of operation, further there are three modes of operation of 8255, so as to
support different types of applications, mode 0, mode 1 and mode 2.
Mode 0 ( Basic I/O mode ): This mode is also called as basic input/output mode. This mode
provides simple input and output capabilities using each of the three ports. Data can be simply
read from and written to the input and output ports respectively, after appropriate initialization.
Mode 1: ( Strobed input/output mode ) In this mode the handshaking control the input and
output action of the specified port. Port C lines PC0-PC2, provide strobe or handshake lines for
port B. This group which includes port B and PC0-PC2 is called as group B for Strobed data
input/output. Port C lines PC3-PC5 provide strobe lines for port A. This group including port A
and PC3-PC5 from group A. Thus port C is utilized for generating handshake signals.
Mode 2 ( Strobed bidirectional I/O ): This mode of operation of 8255 is also called as strobed
bidirectional I/O. This mode of operation provides 8255 with an additional features for
communicating with a peripheral device on an 8-bit data bus. Handshaking signals are provided
to maintain proper data flow and synchronization between the data transmitter and receiver. The
interrupt generation and other functions are similar to mode 1.
The programmable Interval Timers are specially designed by Intel called as 8253 and 8254
constructed for microprocessors to perform timing and counting functions by using three 16-bit
registers. Each counter has 2 input pins, i.e. Clock & Gate, and 1 pin is for “OUT” output. To
perform a counter, a 16-bit count is loaded in its register. On giving command, it begins to
decrease the count until it reaches 0, then it produces a pulse that can be used to interrupt the
CPU.
67
Intel 8253
It is a tri-state, bi-directional, 8-bit buffer, which is used to interface the 8253/54 to the
system data bus. It has three basic functions are Programming the modes of 8253/54, Loading
the count registers, Reading the count values.
Read/Write Logic
It includes 5 signals, i.e. RD, WR, CS, and the address lines A0 & A1. In the peripheral I/O
mode, the RD and WR signals are connected to IOR and IOW, respectively. In the memory
mapped I/O mode, these are connected to MEMR and MEMW.
Address lines A0 & A1 of the CPU are connected to lines A0 and A1 of the 8253/54, and CS
is tied to a decoded address. The control word register and counters are selected according to the
signals on lines A0 & A1.
This register is accessed when lines A0 & A1 are at logic 1. It is used to write a command
word, which specifies the counter to be used, its mode, and either a read or write operation.
68
MODE 0 Interrupt on terminal count:
In this mode, the output is initially low after the mode is set. The counter starts decrementing the
count value after the falling edge of the clock till the terminal count is reached. When the
terminal count is reached, the output goes high and remains high until the selected control word
register or the corresponding count register is reloaded. This high output may be used to interrupt
the processor. The GATE signal should be high for normal counting and When GATE goes low
counting is terminated.
The gate input is used as trigger input in this mode of operation. Normally the output remains
high. After the application of the trigger, the output goes low and remains low until the count
becomes zero.
The output is normally high after initialization. If GATE goes high, the counter starts counting
down from the initial value. In this mode, if N is loaded as the count value, then, after N pulses,
the output becomes low only for one clock cycle. The count N is reloaded and again the output
becomes high and remains high for N clock pulses.
When the count N loaded is even, then for half of the count, the output remains high and for the
remaining half, it remains low. If the count N loaded is odd, then for (N+1)/2 pulses the output
remains high and for (N-1)/2 pulses it remains low. This procedure is repeated continuously
resulting in the generation of a square wave.
After the mode is set, the output goes high. On terminal count, the output goes low for one clock
cycle, and then it again goes high. The GATE input when low disables the counting and when
high, enables the counting. The difference between Mode 4 and Mode 2 is that in Mode 2, the
OUT pulses are generated continuously after every N clock pulses, but in Mode 4, the OUT
pulse is generated only once after N clock pulses.
The output is initially high. The counter starts counting after the rising edge of the trigger input
(GATE). The output goes low for one clock period when the terminal count is reached. The
hardware circuit should trigger the GATE input to initiate the counting operation, thereby
generating the OUT pulse.
69
Review Questions
1. Explain what is (a) Memory Mapped I/O Scheme, (b) I/O Mapped I/O Scheme.
2. What are the various schemes of data transfer from CPU/memory to I/O devices and
vice-versa? Discuss interrupt driven data transfer scheme with suitable example.
3. Explain in detail about DMA data transfer scheme.
4. What is interrupt? Explain enabling, disabling and masking of interrupts.
5. Explain what is vectored input and device polling.
6. Explain in detail about hardware and software interrupts.
7. What are I/O ports? What are programmable and nonprogrammable ports?
8. Explain in detail about different operating modes of 8255.
9. Discuss how to determine the control word for 8255.
10. Explain about programmable counter in detail.
11. Discuss the various operating modes of 8253.
12. Define Memory mapped I/O.
13. What is an interrupt I/O?
14. What are the two categories of an interrupt?
15. What is the purpose of an interrupt enable?
16. What is the size of ports in 8255?
70
UNIT-V MICROROCESSOR APPLICATIONS
5.1. Delay subroutines
A delay program is used to provide the desired delay in industrial control before issuing the
control signal by the microcomputer.. To generate delay a few registers of the microprocessor are
loaded with desired numbers and then decremented to zero. The delay time depends on the
numbers loaded in the registers.
FC06 C9 RET
To generate very small delay only one register can be used. In the above program register B
has been loaded by 10H(16 decimal). Then the register B is decremented and program moves in
a loop till the content of register B becomes zero. After this program returns to the main
program. The delay time may be calculated as follows:
To calculate delay time it is examined that how many times each instruction of the above
program executed. Number of states required for the execution of each instruction are:
Instructions States
MVI B,10 7
DCR B 4
JNZ 7/10
RET 10
71
The instruction JNZ takes 10 states when the content of register B is not zero and the program
jumps to the label LOOP. JNZ takes only 7 states when the content of register B has become
zero and the program proceeds further to execute RET instruction.
The instructions MVI B, 10H and RET are executed only once. The instruction DCR B is
executed 16 times. The instruction JNZ is executed 16 times, out of which 15 times the program
jumps to the label LOOP as the content of register B has not become zero, and takes 10 states
each time.
At last when the content of register B becomes zero, JNZ is executed and the program proceeds
further. The last execution of instruction JNZ takes only 7 states. The number of states required
for the execution of each instruction and how many times each instruction has been executed are
as follows:
= 7+64+150+7+10
= 238
= 0.238x0.320 millisecond
= 0.07616 millisecond.
To generate maximum delay register B is loaded by FF(255 decimal). The maximum delay using
one register is
= 7x1+4x255+(10x254+7x1)+10x1
= 7+1020+2540+7+10
= 3584 states
72
= 3584x320x10-9 second
= 1.11688 millisecond.
Instruction States
LXI D 10
DCX D 6
MOV A, D 4
ORA E 4
JNZ 7/10
RET 10
If the count in register pair D-E is N the total number of states are:
= 24N+17
= 65,535 decimal.
= 20.97664 millisecond.
73
5.1.3. Delay Subroutine Using TWO Registers
Instructions States
MVI 7
DCR 4
JNZ 7/10
RET 10
x(16-1)+7x1+10x1
= 7+122+7680+19040+112+64+150+7+10
= 27182 states
An output device which is very common is, especially in the kit of 8085 microprocessor and
it is the Light Emitting Diode consisting of seven segments. Moreover, we have eight segments
in a LED display consisting of 7 segments which includes ‘.’, consisting of character 8 and
74
having a decimal point just next to it. We denote the segments as ‘a, b, c, d, e, f, g, and dp’ where
dp signifies ‘.’ which is the decimal point. Moreover, these are LEDs or together a series of Light
Emitting Diodes.
In seven segment displays there are seven light emitting diodes as shown in the above figure.
Each LED can be controlled separately. To display a digit or letter the desired segments are
made ON as shown in the figure.
There are two types of 7-segment displays namely common-cathode type and common-anode
type. In a common-cathode type display all the 7 cathodes of LEDs are tied together to the
ground.
Vd.c.is applied to any segment, the corresponding diode emits light. Thus applying logic'1'i.e.,
positive logic to the desired segments, the desired letter or decimal number can be displayed. In a
common-anode type display all the 7 anodes are tied together and connected to +5 V supply. A
particular segment will emit light when 0 logic is applied to it.
75
5.2. 7-Segment Representations of Digits and Letters
The seven-segment displays are not connected to 1/O ports directly. They are connected
through buffers or drivers/decoders.7446A,74L46,7447,74L47 and /4Ls47 are decoders/drivers
for common-anode type seven segment displays.7448,74LS48,7449 and 74LS49 are
decoders/drivers for common-cathode type seven segment displays.
76
5.3. Common-Cathode 7-Segment Display
FND 500 and FND 503 are common-cathode 7-segment displays. The following figure
shows thepin diagram of FND 503.
77
5.5. Pin Diagram of 74LS48, BCD to 7-Segment.
Fig5.7 shows the interfacing of decoder/driver 74LS48 and 7-segment display MAN 74 A
with microprocessor.The program to display the decimal number is as follows: Example.Write a
program to display 5.
78
5.6. Interfacing of 74LS48 and MAN 74A
The control word 98H makes the port B an output port. Thr microprocessor outputs 05 at the
port B. The pins PB0 – PB3 of the port B are connected to the decoder/driver 74LS48. Thus the
binary bits corresponding to the decimal number 5 are applied to 74LS8 and it is displayed by
the 7-segment display.
79
5.7. Interfacing of 7-Segment Displays
x Pins LT, RBO and RBI may not be used. In case the seven segment display is not
working properly, it may be tried with keeping LT, RBO and RBI high.
x If RBI, A, B, C and D are low and LT is high, no segment glows and RBO goes low.
x If RBO is kept open or made high and LT low, all segments glow.
x If inputs A, B, C and D correspond to the decimal number 10 or more, unknown figures
are displayed.
To measure the frequency of a signal, the time period for half cycle is measured which is
inversely proportional to the frequency. A sinusoidal signal is converted to square wave using a
voltage comparator LM 311 or operational amplifier LM 747 or LM 324 is shown in the
following figure. A diode is used to rectify the output signal. A potential divider is used to
reduce the magnitude to 5 volts.
80
5.8. Schematic Diagram of interface for Reactance Relay.
A program has been developed to sense the zero instant of the rectified square wave. The
microprocessor measures the magnitude of the square wave at two consecutive points as shown
in the following figure. The two magnitudes are compared and decision is taken on the basis of
carry and zero status flags, whether the point is zero instant.
Various points are shown in the figure. Very near to P3 at its left side the magnitude of square
wave is zero, and at P4, 5V, at logic ‘1’. The microprocessor subtracts the first value from the
2nd, so the result is non-zero and there is no carry. This is the basis for the selection of zero
instant point supposes the microprocessor takes reading at P1 and P2 where both magnitudes are
zero.
81
5.9. Rectified Square Wave
As soon as the zero instant point is detected the microprocessor initiates a register pair to count
the number how many times the loop is executed. The microprocessor reads the magnitude of the
square wave again and again, and moves in the loop.
It crosses the loop when the magnitude of the square waves becomes zero. Thus the time for
half cycle is measured. The count can be compared with the stored numbers in a look-up table
and the frequency can be displayed.
82
Frequency measurement using SID line:
The sinusoidal wave is converted into square wave using Op.am. The output is reduced to 5V
and applied to SID line of a microprocessor. The execution of RIM instruction reads the status of
SID line and stores it in the 7th bit of the accumulator. It also reads status of interrupt masks and
stores them in other bits of the accumulator. A program to measure the frequency is given
below.
For the measurement of temperature one of the following devices are used:
Platinum wires are frequently used in resistance thermometers for industrial application because
of greater resolution, and mechanical and electrical stability as compared to copper or nickel
wires.
83
A change in temperature causes a change in resistance. The resistance thermometer is laced
in an arm of a Wheatstone bridge to get a voltage proportional to temperature.
The amplified voltage is applied to an A/D converter. The microprocessor sends a start of
conversion signal to the A/D converter through the port of 8255PPI. When A/D converter
completes conversion, it sends an end of conversional signal to microprocessor.
84
5.12. Microprocessor based scheme for Temperature Measurement
The microprocessor displays the measured temperature. If the temperature of a furnace, oven
or water-bath is to be controlled, the microprocessor first measures its temperature, and then
compares the measured temperature with a reference temperature at which the temperature is to
be maintained.
If the measured temperature is higher than the reference temperature, microprocessor sends
control signal to reduce temperature. If the measured temperature is less than the reference
temperature, the microprocessor sends a control signal to increase temperature.
85
5.13. Three stage Amplifier and D.C. Level Detector
The water level Controller is a reliable circuit, it takes over the task of indicating and
controlling the water level in the overhead water tanks. The level of the water is displayed in the
LED Bar graph. The Copper probes are used to sense the water level. The probes are inserted
into the water tank which is to be monitored.
The Microprocessor will also indicate the water level over the LED display. All the input and
output functions are done through the Programmable Peripheral Interface IC 8255.
The output of the inverter are connected to the port A of 8255. In the interface only six probes
have been used. The 6 output points of the inverter are connected to 6 pins of Port A. The
remaining 2 pins of Port A are grounded. The 2nd unit of 8255, i.e., 8255.2 has been used for this
purpose.
86
5.14. Microprocessor Based water Level Indicator and Automatic pumping
The microprocessor reads the binary logic corresponding to water level from the port, and
displays it on 7-segment displays which are connected to port B. The values of water levels at
which probes are placed in the tank are stored in the memory in the form of look-up table.
The microprocessor counts how many probes are immersed in water and determines the LSB of
the memory address of look-u p table. Suppose 1st and 2nd and 3rd robes are immersed in water.
These robes are at logic 1. The microprocessor counts that 3 robes are immersed in water and it
picks up the water level corresponding to memory location FD03 which is 30cm.
Automatic pumping
Automatic pumping can be done on the basis of water level in the tank. The program given
below has been developed to switch on a pump when water level is 20cm or less than 20cms.
The pump is switched off when water level reaches 60 cms.
87
FC0D D2,11,FC JNC LOOK
FC10 04 INR B
FC11 0D LOOP DCR C
FC12 C2,0C,FC JNZ READ
FC15 68 MOV L,B LSBs of memory address for
look-up table.
FC16 7E MOV A,M
FC17 D3,09 OUT 09 Display water level.
FC19 CD,40,FC CALL DELAY
FC1C FE,20 CPI 20
FC1E D2,27,FC JNC GO Yes; jump to Go
FC21 F5 PUSH PSW Save water level reading which
is in ACC.
FC22 3E,01 MVI A,01
FC24 D3,0A OUT 0A
FC26 F1 POP PSW
FC27 FE,60 CPI 60
FC29 DA,06,FC JC L00P Yes; jump to LOOP
FC2C 3E,00 MVI A,00 NO; switch off pump
FC2E D3,0A OUT OA
FC30 C3,06,FC JMP LOOP
All ports of 8255 have been programmed as output ports. The control word to make all ports
output ports for Mode 0 operation is 80H. The connection of pins of the ports to LED have been
made through buffers(7407).
Positive logic has been used to switch on LEDs. Three types of LEDs have been used red,
yellow and green. Green light glows to allow crossing, yellow to make alert, and red does not
allow crossing. The following figure shows a simple arrangement and port connections for
microprocessor-based traffic control.
88
5.15. Traffic Light Control
Green light for right turns have not been shown. One can add some more LEDs for this
purpose, connect them to ports and make additions to the program.
89
FC15 3E,02 MVI A,02
FC17 D3,09 OUT 09 Yellow ON for south.
FC19 D3,08 OUT 08 Yellow ON for north
FC1B CD,13,FD CALL DELAY
II
FC1E 3E,11 MVI A,11
FC20 D3,0A OUT 0A Red ON east and west
FC22 3E,04 MVI A,04
FC24 D3,09 OUT 08 Green for north
FC26 CD,00,FD OUT 09 Green for south
FC28 3E,22 CALL DELAY I
FC2B D3,0A MVI A,22
FC2D 3E,02 OUT 0A
FC2F D3,09 MVI A,02
FC31 D3,08 OUT 09 Yellow ON for south
FC33 CD,13,FD OUT 08 Yellow ON for north
FC35 C3,04,FC CALL DELAY
II
FC38 JMP LOOP
DELAY I
DELAY II
90
Review Questions
91
92