Ref Manual Microprocessor - Microcontroller by Krishna Gaihre
Ref Manual Microprocessor - Microcontroller by Krishna Gaihre
EG 2206 EE
Total: 5 hours /week
Year: II Lecture: 3 hours/week Semester: II Tutorial: hours/week
Practical: hours/week Lab: 2 hours/week
Microprocessors were categorized into five generations: first, second, third, fourth, and fifth
generations. Their characteristics are described below:
First-generation
The microprocessors that were introduced in 1971 to 1972 were referred to as the first
generation systems. First-generation microprocessors processed their instructions serially—
they fetched the instruction, decoded it, then executed it. When an instruction was completed,
the microprocessor updated the instruction pointer and fetched the next instruction, performing
this sequential drill for each instruction in turn.
Second generation
By the late 1970s, enough transistors were available on the IC to usher in the second generation
of microprocessor sophistication: 16-bit arithmetic and pipelined instruction processing.
Motorola’s MC68000 microprocessor, introduced in 1979, is an example. Another example is
Intel’s 8080. This generation is defined by overlapped fetch, decode, and execute steps
(Computer 1996). As the first instruction is processed in the execution unit, the second
instruction is decoded and the third instruction is fetched.
The distinction between the first and second generation devices was primarily the use of newer
semiconductor technology to fabricate the chips. This new technology resulted in a five-fold
increase in instruction, execution, speed, and higher chip densities.
Third generation
The third generation, introduced in 1978, was represented by Intel’s 8086 and the Zilog Z8000,
which were 16-bit processors with minicomputer-like performance. The third generation came
about as IC transistor counts approached 250,000.
Motorola’s MC68020, for example, incorporated an on-chip cache for the first time and the
depth of the pipeline increased to five or more stages. This generation of microprocessors was
different from the previous ones in that all major workstation manufacturers began developing
their own RISC-based microprocessor architectures (Computer, 1996).
Fourth generation
As the workstation companies converted from commercial microprocessors to in-house
designs, microprocessors entered their fourth generation with designs surpassing a million
transistors.
1|Page
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Leading-edge microprocessors such as Intel’s 80960CA and Motorola’s 88100 could issue and
retire more than one instruction per clock cycle.
Fifth generation
Microprocessors in their fifth generation, employed decoupled super scalar processing, and
their design soon surpassed 10 million transistors. In this generation, PCs are a low-margin,
high-volume-business dominated by a single microprocessor
1.2 Intel 8085 Hardware Architecture ,Pin description ,Internal Registers – Arithmetic
and Logic Unit, Control Unit
i. Intel 8085 Hardware Architecture
2|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
3|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
It controls all the operations of microprocessor and peripheral devices. Depending upon
the machine cycles received from Instruction Decoder, it generates 12 control signals.
vi. Accumulator
The accumulator is an 8-bit register that is a part of arithmetic/logic unit (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.
vii. Flags
The ALU includes five flip-flops, which are set or reset after an operation according to data
conditions 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; they are listed in the
Table and their bit positions in the flag register are shown in the Figure below. The most
commonly used flags are Zero, Carry, and Sign. The microprocessor uses these flags to test
data conditions. The flags of 8085 is shown in 8bit format in below.
4|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
1.3 Instruction word size, Addressing modes, Instruction Set, Assembly Language
Programming, Stacks and Subroutines, Timing Diagrams.
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.
One-Byte Instructions
A 1-byte instruction includes the opcode and operand in the same byte. Operand(s)
are internal register and are coded into the instruction.
5|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
These instructions are 1-byte instructions performing three different tasks. In the first
instruction, both operand registers are specified. In the second instruction, the operand
B is specified and the accumulator is assumed. Similarly, in the third instruction, the
accumulator is assumed to be the implicit operand. These instructions are stored in 8-
bit binary format in memory; each requires one memory location.
Two-Byte Instructions
In a two-byte instruction, the first byte specifies the operation code and the second
byte specifies the operand. Source operand is a data byte immediately following the
opcode. For example:
Three-Byte Instructions
In a three-byte instruction, the first byte specifies the opcode, and the following two
bytes specify the 16-bit address. Note that the second byte is the low-order address
and the third byte is the high-order address.
opcode + data byte + data byte, for example:
6|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
number (00H to FFH). Similarly, a destination can be a register or an output port. The
sources and destination are operands. The various formats for specifying operands are
called the ADDRESSING MODES. For 8085, they are:
a. Immediate addressing.
Data is present in the instruction. Load the immediate data to the destination
provided.
Example: MVI R,data
b. Register addressing
Data is provided through the registers.
Example: MOV Rd, Rs
c. Direct addressing
Used to accept data from outside devices to store in the accumulator or send the data
stored in the accumulator to the outside device. Accept the data from the port 00H
and store them into the accumulator or Send the data from the accumulator to the
port 01H.
Example: IN 00H or OUT 01H
d. Indirect Addressing
This means that the Effective Address is calculated by the processor. And the
contents of the address (and the one following) is used to form a second address.
The second address is where the data is stored. Note that this requires several
memory accesses; two accesses to retrieve the 16-bit address and a further access
(or accesses) to retrieve the data which is to be loaded into the register.
Arithmetic Operations
These instructions perform arithmetic operations such as addition, subtraction, increment,
and decrement.
Addition –
Any 8-bit number, or the contents of a register or the contents of a memory location
can be added to the contents of the accumulator and the sum is stored in the
accumulator. No two other 8-bit registers can be added directly (e.g., the contents
of register B cannot be added directly to the contents of the register C). The
instruction DAD is an exception; it adds 16-bit data directly in register pairs.
7|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Subtraction –
Any 8-bit number, or the contents of a register, or the contents of a memory location
can be subtracted from the contents of the accumulator and the results 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 contents of a register or a memory location can b incremented or
decrement by 1. Similarly, the 16-bit contents of a register pair (such as BC) can be
incremented or decrement 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 location.
Logical Operations
These instructions perform various logical operations with the contents of the accumulator.
AND, OR Exclusive-OR –
Any 8-bit number, or the contents of a register, or of
a memory location can be logically ANDed, Ored, or Exclusive-ORed with the contents of
the accumulator. The results are stored in the accumulator.
Rotate-
Each bit in the accumulator can be shifted either left or right to the next position.
Compare-
Any 8-bit number, or the contents of a register, or a memory location can
be compared for equality, greater than, or less than, with the contents of the accumulator.
Complement –
The contents of the accumulator can be complemented. All 0s are replaced by 1s and all 1s
are replaced by 0s.
Branching Operations
This group of instructions alters the sequence of program execution either conditionally or
unconditionally.
Jump - Conditional jumps are an important aspect of the decision-making process in the
programming. These instructions test for a certain conditions (e.g., Zero or Carry flag) and
alter the program sequence when the condition is met. In addition, the instruction set
includes an instruction called unconditional jump.
Call, Return, and Restart - These instructions change the sequence of a program either by
calling a subroutine or returning from a subroutine. The conditional Call and
Return instructions also can test condition flags.
8|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Level program but it need the assembler for creating machine level code from the assembly
programs.
Information is saved on the stack by PUSHing it on. It is retrieved from the stack by POPing
it off.
Subroutines
A subroutine is a group of instructions that will be used repeatedly in different locations of
the program, rather than repeat the same instructions several times they can be grouped
into a subrouting that is called from the different locaitons. In asembly language , a
subroutin can exist anywhere in the code. However it is customary to place subroutines
separately from the main program.
The 8085 has two instructiions for dealing with subroutines: the CALL instructions is used
to redirect program execution to the subroutine and the RTE instruction is used to return
the execution to the calling routine. In Assembly Language data is passed to a subroutine
through registers.
9|Page
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Instruction Cycle: The time taken by the processor to complete the execution of an
instruction. An instruction cycle consists of one to six machine cycles.
Machine Cycle: The time required to complete one operation; accessing either the memory
or I/O device. A machine cycle consists of three to six T-states.
T-State: Time corresponding to one clock period. It is the basic unit to calculate execution
of instructions or programs in a processor.
10 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
interrupt is called interrupt service routine (ISR). After execution of ISR, the processor must return to
the interrupted program. Key features in the interrupt structure of any microprocessor are as follows:
i. Number and types of interrupt signals available.
ii. The address of the memory where the ISR is located for a particular interrupt signal. This
address is called interrupt vector address (IVA).
iii. Masking and unmasking feature of the interrupt signals.
iv. Priority among the interrupts.
v. Timing of the interrupt signals.
vi. Handling and storing of information about the interrupt program (status information).
Types of Interrupts:
Interrupts are classified based on their maskability, IVA and source. They are classified as:
11 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The software interrupts can be treated as CALL instructions with default call locations. The concept
of priority does not apply to software interrupts as they are inserted into the program as instructions
by the programmer and executed by the processor when the respective program lines are read.
Features:
8 levels of interrupts.
Can be cascaded in master-slave configuration to handle 64 levels of interrupts.
Internal priority resolver.
Fixed priority mode and rotating priority mode.
Individually maskable interrupts.
12 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The 8259 A is contained in a 28-element in line package that requires only a compatible with 8259.
The main difference between the two is that the 8259 A can be used with Intel 8086/8088
processor. It also induces additional features such as level triggered mode, buffered mode and
automatic end of interrupt mode. The pin diagram and interval block diagram is shown below:
D0-D7 Bi-directional, tristated, buffered data lines. Connected to data bus directly or
through buffers
RD-bar Active low read control
WR-bar Active low write control
A0 Address input line, used to select control register
CS-bar Active low chip select
13 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
CAS0-2 Bi-directional, 3 bit cascade lines. In master mode, PIC places slave ID no. on
these lines. In slave mode, the PIC reads slave ID no. from master on these lines.
It may be regarded as slave-select.
SP-bar / Slave program / enable. In non-buffered mode, it is SP-bar input, used to
EN-bar distinguish master/slave PIC. In buffered mode, it is output line used to enable
buffers
INT Interrupt line, connected to INTR of microprocessor
INTA-bar Interrupt ack, received active low from microprocessor
IR0-7 Asynchronous IRQ input lines, generated by peripherals.
14 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
2.2 Data Transfer Techniques – Synchronous, Asynchronous and Direct Memory Access
(DMA) and 8237 DMA Controller- 8253 Programmable Interval Timer.
i. A wide variety of IO devices having wide range of speed and other different characteristics
are available .A slow responding IO device cannot transfer data when microprocessor issues
instruction for it as it takes some time to get Transfers ratesready. Of peripherals is usually
slower than the transfer rates of CPU. Operating modes of peripheral are different from each
other and each must be controlled so as not to disturb the operation of each other peripherals
connected to CPU. Different types of data transfer techniques are available which can be
broadly divided into two categories:-
MICROPROCESSOR CONTROLLED
DEVICE CONTROLLED
Program data transfer scheme
Synchronous Data Transfer
Asynchronous mode of transfer
Interrupt driven IO data transfer
DMA Data Transfer
ii. Synchronous Data Transfer:- Synchronous means „at the same time‟. The device Which
sends data and the device which received data are synchronized with the same clock. When
the CPU and IO devices match in speed, Synchronous Data Transfer technique is employed.
The data transfer with IO devices is performed by executing IN and OUT instruction. The IN
instruction is used to read data from an input device or input port. The OUT instruction is
used to sends data from CPU to the output device or output port. As the CPU and the IO
devices match in speed, the I/O device is ready to transfer data when IN or OUT instruction is
executes. The status of the I/O device, whether it is ready or not, is not examined before the
data is transferred.
iii. Asynchronous mode of transfer:- Asynchronous means „at irregular intervals‟. In this
method data transfer is not based on predetermined timing pattern. This technique of data
transfer is used when the speed of an I/O device does not match the speed of the
microprocessor. In this technique the status of the I/O device i.e. whether the device is ready
or not, is checked by the microprocessor before the data are transferred. The microprocessor
initiates the I/O device to get ready and then continuously checks the status of I/O device till
the I/O device becomes ready to transfer data. When I/O device becomes ready, the
microprocessor executes instruction to transfer data.
This mode of data transfer is also called handshaking mode of data transfer because some
signals are exchanged between microprocessor and I/O devices before the actual data
transfer takes place. Such signals are called handshake signals. The microprocessor is too
busy. CPU is wasting time while checking the flag instead of doing some useful work.
The problem with programmed I/O is that CPU has to wait along time for the I/O device to be
ready for reception or transmission of data .The CPU while waiting, must repeatedly
interrogate the status of the I/O device. As a result the level of the performance of the entire
system is severely degraded.
iv. DMA Data Transfer: The transfer of data between the mass storage device and a system
memory is often limited by the speed of microprocessor. Removing the microprocessor
during such a transfer and letting the peripheral manage the transfer to or from memory
15 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
would improve the speed of transfer and hence will make the system more efficient. This
transfer technique is called DMA Data Transfer. During DMA transfer microprocessor is idle,
so it has no longer control on the system buses. A DMA Controller takes over the buses and
manage the transfer directly between the peripheral and the memory It is fastest scheme
then Programmed Data Transfer Scheme and the microprocessor regains the control of buses
after data transfer.
v. 8237 DMA Controller:-
DMA stands for Direct Memory Access. It is designed by Intel to transfer data at the fastest
rate. It allows the device to transfer the data directly to/from memory without any
interference of the CPU.
Using a DMA controller, the device requests the CPU to hold its data, address and control
bus, so the device is free to transfer data directly to/from the memory. The DMA data
transfer is initiated only after receiving HLDA signal from the CPU.
Initially, when any device has to send data between the device and the memory, the
device has to send DMA request (DRQ) to DMA controller.
The DMA controller sends Hold request (HRQ) to the CPU and waits for the CPU to
assert the HLDA.
Then the microprocessor tri-states all the data bus, address bus, and control bus. The
CPU leaves the control over bus and acknowledges the HOLD request through
HLDA signal.
Now the CPU is in HOLD state and the DMA controller has to manage the operations
over buses between the CPU, memory, and I/O devices.
Features of 8257
Here is a list of some of the prominent features of 8257 −
It has four channels which can be used over four I/O devices.
Each channel has 16-bit address and 14-bit counter.
Each channel can transfer data up to 64kb.
Each channel can be programmed independently.
Each channel can perform read transfer, write transfer and verify transfer operations.
It generates MARK signal to the peripheral device that 128 bytes have been
transferred.
It requires a single phase clock.
Its frequency ranges from 250Hz to 3MHz.
It operates in 2 modes, i.e., Master mode and Slave mode.
16 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
DRQ0−DRQ3
These are the four individual channel DMA request inputs, which are used by the
peripheral devices for using DMA services. When the fixed priority mode is selected,
then DRQ0 has the highest priority and DRQ3 has the lowest priority among them.
DACKo − DACK3
These are the active-low DMA acknowledge lines, which updates the requesting
peripheral about the status of their request by the CPU. These lines can also act as strobe
lines for the requesting devices.
Do − D 7
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.
17 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
IOR
It is an active-low bidirectional tri-state input line, which is used by the CPU to read
internal registers of 8257 in the Slave mode. In the master mode, it is used to read data
from the peripheral devices during a memory write cycle.
IOW
It is an active low bi-direction tri-state line, which is used to load the contents of the data
bus to the 8-bit mode register or upper/lower byte of a 16-bit DMA address register or
terminal count register. In the master mode, it is used to load the data to the peripheral
devices during DMA memory read cycle.
CLK
It is a clock frequency signal which is required for the internal operation of 8257.
RESET
This signal is used to RESET the DMA controller by disabling all the DMA channels.
Ao - A3
These are the four least significant address lines. In the slave mode, they act as an input,
which selects one of the registers to be read or written. In the master mode, they are the
four least significant memory address output lines generated by 8257.
CS
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 in the master
mode.
READY
It is an active-high asynchronous input signal, which makes DMA ready by inserting wait
states.
18 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
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 it is set to 1.
MEMR
It is the low memory read signal, which is used to read the data from the addressed
memory locations during DMA read cycles.
MEMW
It is the active-low three state 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
TC
It stands for ‘Terminal Count’, which indicates the present DMA cycle to the present
peripheral devices.
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.
Vcc
It is the power signal which is required for the operation of the circuit.
19 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
In the above figure, there are three counters, a data bus buffer, Read/Write control logic,
and a control register. Each counter has two input signals - CLOCK & GATE, and one
output signal - OUT.
20 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
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 −
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
memorymapped 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.
A1 A0 Result
0 0 Counter 0
0 1 Counter 1
1 0 Counter 2
1 1 Control Word Register
X X No Selection
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. Following table shows the result for various control inputs.
A1 A0 RD WR CS Result
0 0 1 0 0 Write Counter 0
0 1 1 0 0 Write Counter 1
1 0 1 0 0 Write Counter 2
1 1 1 0 0 Write Control Word
0 0 0 1 0 Read Counter 0
0 1 0 1 0 Read Counter 1
1 0 0 1 0 Read Counter 2
1 1 0 1 0 No operation
X X 1 1 0 No operation
X X X X 1 No operation
Counters
21 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Each counter consists of a single, 16 bit-down counter, which can be operated in either
binary or BCD. Its input and output is configured by the selection of modes stored in the
control word register. The programmer can read the contents of any of the three counters
without disturbing the actual count in process.
The 8085 family can address 64K bytes of memory which is used for both code and data space.
Memory is accessed via 20 pins. 8 address high pins and 8 pins that are used both for the 8 address
low signals during the address setup phase and for the 8 data signals during the data transfer phase.
4 pins are used for control. A READY input line allows memory or I/O access to slow down the
data transfer. This allows slow memory or I/O hardware to be easily interfaced.
And a HOLD line allows peripheral hardware to take over the memory bus allowing DMA
transfers to be implemented.
a. Types of Memory: RAM & ROM (PROM,EPROM)
The programs and data that are executed by the microprocessor have to be stored in ROM/EPROM
and RAM, which are basically semiconductor memory chips. The programs and data that are
stored in ROM/EPROM are not erased even when power supply to the chip is removed. Hence,
they are called non-volatile memory. They can be used to store permanent programs.
In a RAM, stored programs and data are erased when the power supply to the chip is removed.
Hence, RAM is called volatile memory. RAM can be used to store programs and data that include,
programs written during software development for a microprocessor based system, program
written when one is learning assembly language programming and data enter while testing these
programs.
The same memory mapping technique can be used to interface disk-drive controllers and
graphics controller cards to a microprocessor within a computer system. A range of memory
locations or registers in these devices are mapped into system memory as if they are normal
memory chips. The microprocessor moves data to and from them as though they are normal
22 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
memory locations. The devices that are mapped onto the system use the data supplied by the
microprocessor to do their respective tasks. For example, the graphics controller card uses the
data provided by the microprocessor to create an image on a screen.
23 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Memory Addressing:
Memory address decoding is nothing but to assign an address for each location in the memory
chip. The data stored in the memory is accessed by specifying its address. Memory address can be
decoded in two ways:
i) Absolute or Fully decoding and ii) Linear Select or Partial decoding
24 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
25 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
26 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Figure:
IN instruction is used to access input device and OUT instruction is used to access output
device. Each I/O device is identified by a unique 8-bit address assigned to it. Since the
control signals used to access input and output devices are different, and all I/O device use
8-bit address, a maximum of 256 (2^8) input devices and 256 output devices can be
interfaced with 8085.
Ex: Interface an 8-bit DIP switch with the 8085 such that the address assigned to the DIP
switch if F0H.
IN instruction is used to get data from DIP switch and store it in accumulator. Steps
involved in the execution of this instruction are:
i. Address F0H is placed in the lines A0 – A7 and a copy of it in lines A8 – A15.
ii. The IOR signal is activated ( IOR = 0), which makes the selected input device to
place its data in the data bus.
iii. The data in the data bus is read and store in the accumulator.
A0 – A7 lines are connected to a NAND gate decoder such that the output of NAND gate is
0. The output of NAND gate is ORed with the IOR signal and the output of OR gate is
connected to 1G and 2G of the 74LS244. When 74LS244 is enabled, data from the DIP
switch is placed on the data bus of the 8085. The 8085 read data and store in the
accumulator. Thus data from DIP switch is transferred to the accumulator.
27 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
3.2 Types – I/O decode logic – Interfacing key switches and LEDs – 8279
Keyboard/Display Interface - 8255 Programmable Peripheral Interface –
Concept of Serial Communication – 8251 USART – RS232C Interface.
28 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
First Step is to decode the address bus using 3x8 Decoder and 4-input NAND gate. A0 to A2 are
used as input and remaining A3 to A7 are used to enable decoder.
Second step is to decode address with appropriate control signal (IOR’/IOW’) output will generate
select pulse.
Third step is to use this pulse to enable I/O port (pulse enables LED latch with the output port
address F8H similarly input buffer is enable with address FAH).
29 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The INTEL 8279 is specially developed for interfacing keyboard and display devices to
8085/8086/8088 microprocessor based system. The important features of 8279 are,
• Simultaneous keyboard and display operations.
• Scanned keyboard mode.
30 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The four major sections of 8279 are keyboard, scan, display and CPU interface.
Keyboard section:
• The keyboard section consists of eight return lines RL0 – RL7 that can be used to form
the columns of a keyboard matrix.
• It has two additional input : shift and control/strobe. The keys are automatically
debounced.
• The two operating modes of keyboard section are 2-key lockout and N-key rollover.
• In the 2-key lockout mode, if two keys are pressed simultaneously, only the first key is
recognized.
• In the N-key rollover mode simultaneous keys are recognized and their codes are stored
in FIFO.
• The keyboard section also have an 8 x 8 FIFO (First In First Out) RAM.
• The FIFO can store eight key codes in the scan keyboard mode. The status of the shift
key and control key are also stored along with key code. The 8279 generate an interrupt
signal when there is an entry in FIFO. The format of key code entry in FIFO for scan
keyboard mode is,
31 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
• In sensor matrix mode the condition (i.e., open/close status) of 64 switches is stored in
FIFO RAM. If the condition of any of the switches changes then the 8279 asserts IRQ as
high to interrupt the processor.
Display section:
• The display section has eight output lines divided into two groups A0-A3 and B0-B3.
• The output lines can be used either as a single group of eight lines or as two groups of
four lines, in conjunction with the scan lines for a multiplexed display.
• The output lines are connected to the anodes through driver transistor in case of
common cathode 7-segment LEDs.
• The cathodes are connected to scan lines through driver transistors.
• The display can be blanked by BD (low) line.
• The display section consists of 16 x 8 display RAM. The CPU can read from or write
into any location of the display RAM.
Scan section:
• The scan section has a scan counter and four scan lines, SL0 to SL3.
• In decoded scan mode, the output of scan lines will be similar to a 2-to-4 decoder.
• In encoded scan mode, the output of scan lines will be binary count, and so an external
decoder should be used to convert the binary count to decoded output.
• The scan lines are common for keyboard and display.
• The scan lines are used to form the rows of a matrix keyboard and also connected to
digit drivers of a multiplexed display, to turn ON/OFF.
CPU interface section:
• The CPU interface section takes care of data transfer between 8279 and the processor.
• This section has eight bidirectional data lines DB0 to DB7 for data transfer between
8279 and CPU.
• It requires two internal address A =0 for selecting data buffer and A = 1 for selecting
control register of8279.
• The control signals WR (low), RD (low), CS (low) and A0 are used for read/write to
8279.
• It has an interrupt request line IRQ, for interrupt driven data transfer with processor.
• The 8279 require an internal clock frequency of 100 kHz. This can be obtained by
dividing the input clock by an internal prescaler.
• The RESET signal sets the 8279 in 16-character display with two -key lockout
keyboard modes.
32 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The two groups can be programmed in three different modes. In the first mode (mode 0), each
group may be programmed in either input mode or output mode (PORT A, PORT B, PORT C
lower, PORT C upper). In mode 1, the second’s mode, each group may be programmed to have 8-
lines of input or output (PORT A or PORT B) of the remaining 4-lines (PORT C lower or PORT
C upper) 3-lines are used for hand shaking and interrupt control signals. The third mode of
operation (mode 2) is a bidirectional bus mode which uses 8-line (PORT A only for a bidirectional
bus and five lines (PORT C upper 4 lines and borrowing one from other group) for handshaking.
The 8255 is contained in a 40-pin package, whose pin out is shown below:
33 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Functional Description: This support chip is a general purpose I/O component to interface
peripheral equipment to the microcomputer system bus. It is programmed by the system software
so that normally no external logic is necessary to interface peripheral devices or structures.
BSR Mode:
BSR means bit set reset mode for Port C.BSR mode mode is selected when bit D7=0 of the control word
register.
See lecture 14328 page 46
34 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
8251 USART :–
The 8251 is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial
data communication. As a peripheral device of a microcomputer system, the 8251 receives
35 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
parallel data from the CPU and transmits serial data after conversion. This device also receives
serial data from the outside and transmits parallel data to the CPU after conversion.
The 8251 functional configuration is programed by software. Operation between the 8251 and a
CPU is executed by program control. Table 1 shows the operation between a CPU and the
device.
36 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Control Words
1) Mode Instruction
Mode instruction is used for setting the function of the 8251. Mode instruction will be in "wait
for write" at either internal reset or external reset. That is, the writing of a control word after
resetting will be recognized as a "mode instruction."
• Synchronous/asynchronous mode
• Character length
• Parity bit
37 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The bit configuration of mode instruction is shown in Figures 2 and 3. In the case of synchronous
mode, it is necessary to write one-or two byte sync characters. If sync characters were written, a
function will be set because the writing of sync characters constitutes part of mode instruction.
38 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
2) Command
Command is used for setting the operation of the 8251. It is possible to write a command
whenever necessary after writing a mode instruction and sync characters.
• Transmit Enable/Disable
• Receive Enable/Disable
39 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
• Internal resetting
40 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Status Word
It is possible to see the internal status of the 8251 by reading a status word. The bit configuration
of status word is shown in Fig. 5.
Pin Description
D 0 to D 7 (l/O terminal)
41 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
This is bidirectional data bus which receive control words and transmits data from the CPU and
sends status words and received data to CPU.
A "High" on this input forces the 8251 into "reset status." The device waits for the writing of
"mode instruction." The min. reset width is six clock inputs during the operating status of CLK.
CLK signal is used to generate internal device timing. CLK signal is independent of RXC or
TXC. However, the frequency of CLK must be greater than 30 times the RXC and TXC at
Synchronous mode and Asynchronous "x1" mode, and must be greater than 5 times at
Asynchronous "x16" and "x64" mode.
WR (Input terminal)
This is the "active low" input terminal which receives a signal for writing transmit data and
control words from the CPU into the 8251.
RD (Input terminal)
This is the "active low" input terminal which receives a signal for reading receive data and status
words from the 8251.
This is an input terminal which receives a signal for selecting data or command words and status
words when the 8251 is accessed by the CPU. If C/D = low, data will be accessed. If C/D = high,
command word or status word will be accessed.
CS (Input terminal)
This is the "active low" input terminal which selects the 8251 at low level when the CPU
accesses. Note: The device won’t be in "standby status"; only setting CS = High.
This is an output terminal for transmitting data from which serial-converted data is sent out. The
device is in "mark status" (high level) after resetting or during a status when transmit is disabled.
It is also possible to set the device in "break status" (low level) by a command.
This is an output terminal which indicates that the 8251is ready to accept a transmitted data
character. But the terminal is always at low level if CTS = high or the device was set in "TX
42 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
disable status" by a command. Note: TXRDY status word indicates that transmit data character is
receivable, regardless of CTS or command. If the CPU writes a data character, TXRDY will be
reset by the leading edge or WR signal.
This is an output terminal which indicates that the 8251 has transmitted all the characters and had
no data character. In "synchronous mode," the terminal is at high level, if transmit data
characters are no longer remaining and sync characters are automatically transmitted. If the CPU
writes a data character, TXEMPTY will be reset by the leading edge of WR signal. Note : As the
transmitter is disabled by setting CTS "High" or command, data written before disable will be
sent out. Then TXD and TXEMPTY will be "High". Even if a data is written after disable, that
data is not sent out and TXE will be "High".After the transmitter is enabled, it sent out. (Refer to
Timing Chart of Transmitter Control and Flag Timing)
This is a clock input signal which determines the transfer speed of transmitted data. In
"synchronous mode," the baud rate will be the same as the frequency of TXC. In "asynchronous
mode", it is possible to select the baud rate factor by mode instruction. It can be 1, 1/16 or 1/64
the TXC. The falling edge of TXC sifts the serial data out of the 8251.
This is a terminal which indicates that the 8251 contains a character that is ready to READ. If the
CPU reads a data character, RXRDY will be reset by the leading edge of RD signal. Unless the
CPU reads a data character before the next one is received completely, the preceding data will be
lost. In such a case, an overrun error flag status word will be set.
This is a clock input signal which determines the transfer speed of received data. In
"synchronous mode," the baud rate is the same as the frequency of RXC. In "asynchronous
mode," it is possible to select the baud rate factor by mode instruction. It can be 1, 1/16, 1/64 the
RXC.
This is a terminal whose function changes according to mode. In "internal synchronous mode."
this terminal is at high level, if sync characters are received and synchronized. If a status word is
read, the terminal will be reset. In "external synchronous mode, "this is an input terminal. A
"High" on this input forces the 8251 to start receiving data characters.
43 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
In "asynchronous mode," this is an output terminal which generates "high level"output upon the
detection of a "break" character if receiver data contains a "low-level" space between the stop
bits of two continuous characters. The terminal will be reset, if RXD is at high level. After Reset
is active, the terminal will be output at low level.
This is an input port for MODEM interface. The input status of the terminal can be recognized
by the CPU reading status words.
This is an output port for MODEM interface. It is possible to set the status of DTR by a
command.
This is an input terminal for MODEM interface which is used for controlling a transmit circuit.
The terminal controls data transmission if the device is set in "TX Enable" status by a command.
Data is transmitable if the terminal is at low level.
This is an output port for MODEM interface. It is possible to set the status RTS by a command.
RS232C Interface:-
RS-232 – Recommended Standard 232: The RS-232 is typically connected using a DB9 connector,
which has 9 pins, out of which 5 are input, 3 are output, and one is Ground. You can still find this
so-called “Serial” port in some old PCs. In our upcoming posts, we will discuss mainly about
RS232 and USART of Microporcessor/microcontrollers.
44 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
45 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
RS-232 connections
The RS-232C specification does not include a description of the connector to be used. However,
the most common type found is the 25 pin D-type connector.
RS232 did not define elements such as character encoding, framing of characters, error detection
protocols etc that are essential features when data transfer takes place between a computer and a
printer. Without which it could not be adopted to transfer data between a computer and a printer.
To overcome this problem a single integrated circuit called as UART known as universal
asynchronous receiver/transmitter is used in conjunction with RS232.
DTE-A DTE stands for data terminal equipment is an end instrument that convert user information
into signals or reconverts the receive signal. It is a functional unit of station that serves as data
source or data sink and provides for communication control function according to the link protocol.
A male connector is used in DTE and has pin out configuration.
DCE-A DCE stands for data communication equipments. It sits between the DTE and data
transmission circuit for example modem. A DCE device uses a female connector which has holes
on the surface to hold male connector.
A minimum of three signals are required for communication between a DTE and a DCE devices.
These signals are a transmission line, a reception line and ground. These two devices communicate
with each other by handshaking. It allows a DTE and a DCE device system to acknowledge each
other before sending the data.
Handshaking is a process in which a DTE device sends a signal to a DCE device to establish a
connection between the devices before the actual transfer of data. It sets the parameters of
communication channel established between two equipment’s before normal communication over
the channel begins. It follows physical establishment of the channel and precedes normal
information transfer. Handshaking makes it possible to connect relatively heterogeneous systems
or equipment over a communication channel without the need for human intervention to set
46 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
parameters. This same concept is used in RS232 to allow two devices communicate with each
other before the actual exchange of information.
All these terms put together gives a complete picture of a RS232 system starting from DTE to
DCE with UART, line drivers and RS232 as conjunction between them.
The Electronic Industries Association (EIA)-232 standard supports two types of connectors -- a
25-pin D-type connector (DB-25) and a 9-pin D-type connector (DB-9). The type of serial
communications used by PCs requires only 9 pins so either type of connector will work equally
well.
Memory − 8085 can access up to 64Kb, whereas 8086 can access up to 1 Mb of memory.
Instruction − 8085 doesn’t have an instruction queue, whereas 8086 has an instruction queue.
Pipelining − 8085 doesn’t support a pipelined architecture while 8086 supports a pipelined
architecture.
I/O − 8085 can address 2^8 = 256 I/O's, whereas 8086 can access 2^16 = 65,536 I/O's.
Architecture of 8086
The following diagram depicts the architecture of a 8086 Microprocessor
47 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
8086 Microprocessor is divided into two functional units, i.e., EU (Execution Unit) and BIU (Bus
Interface Unit).
EU (Execution Unit)
Execution unit gives instructions to BIU stating from where to fetch the data and then decode
and execute those instructions. Its function is to control operations on data using the instruction
decoder & ALU. EU has no direct connection with system buses as shown in the above figure, it
performs operations over data through BIU.
ALU
It handles all arithmetic and logical operations, like +, −, ×, /, OR, AND, NOT operations.
Flag Register
It is a 16-bit register that behaves like a flip-flop, i.e. it changes its status according to the result
stored in the accumulator. It has 9 flags and they are divided into 2 groups − Conditional Flags
and Control Flags.
48 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Conditional Flags
It represents the result of the last arithmetic or logical instruction executed. Following is the list
of conditional flags −
Carry flag − This flag indicates an overflow condition for arithmetic operations.
Auxiliary flag − When an operation is performed at ALU, it results in a carry/barrow
from lower nibble (i.e. D0 – D3) to upper nibble (i.e. D4 – D7), then this flag is set, i.e.
carry given by D3 bit to D4 is AF flag. The processor uses this flag to perform binary to
BCD conversion.
Parity flag − This flag is used to indicate the parity of the result, i.e. when the lower
order 8-bits of the result contains even number of 1’s, then the Parity Flag is set. For odd
number of 1’s, the Parity Flag is reset.
Zero flag − This flag is set to 1 when the result of arithmetic or logical operation is zero
else it is set to 0.
Sign flag − This flag holds the sign of the result, i.e. when the result of the operation is
negative, then the sign flag is set to 1 else set to 0.
Overflow flag − This flag represents the result when the system capacity is exceeded.
Control Flags
Control flags controls the operations of the execution unit. Following is the list of control flags −
Trap flag − It is used for single step control and allows the user to execute one
instruction at a time for debugging. If it is set, then the program can be run in a single
step mode.
Interrupt flag − It is an interrupt enable/disable flag, i.e. used to allow/prohibit the
interruption of a program. It is set to 1 for interrupt enabled condition and set to 0 for
interrupt disabled condition.
Direction flag − It is used in string operation. As the name suggests when it is set then
string bytes are accessed from the higher memory address to the lower memory address
and vice-a-versa.
There are 8 general purpose registers, i.e., AH, AL, BH, BL, CH, CL, DH, and DL. These
registers can be used individually to store 8-bit data and can be used in pairs to store 16bit data.
The valid register pairs are AH and AL, BH and BL, CH and CL, and DH and DL. It is referred
to the AX, BX, CX, and DX respectively.
49 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
DX register − This register is used to hold I/O port address for I/O instruction.
It is a 16-bit register, which holds the address from the start of the segment to the memory
location, where a word was most recently stored on the stack.
Instruction queue − BIU contains the instruction queue. BIU gets upto 6 bytes of next
instructions and stores them in the instruction queue. When EU executes instructions and
is ready for its next instruction, then it simply reads the instruction from this instruction
queue resulting in increased execution speed.
Fetching the next instruction while the current instruction executes is called pipelining.
Segment register − BIU has 4 segment buses, i.e. CS, DS, SS& ES. It holds the
addresses of instructions and data in memory, which are used by the processor to access
memory locations. It also contains 1 pointer register IP, which holds the address of the
next instruction to executed by the EU.
o CS − It stands for Code Segment. It is used for addressing a memory location in
the code segment of the memory, where the executable program is stored.
o DS − It stands for Data Segment. It consists of data used by the program andis
accessed in the data segment by an offset address or the content of other register
that holds the offset address.
o SS − It stands for Stack Segment. It handles memory to store data and addresses
during execution.
o ES − It stands for Extra Segment. ES is additional data segment, which is used by
the string to hold the extra destination data.
Instruction pointer − It is a 16-bit register used to hold the address of the next
instruction to be executed.
50 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
8086 was the first 16-bit microprocessor available in 40-pin DIP (Dual Inline Package) chip. Let us now
discuss in detail the pin configuration of a 8086 Microprocessor.
It uses 5V DC supply at VCC pin 40, and uses ground at VSS pin 1 and 20 for its operation.
Clock signal
Clock signal is provided through Pin-19. It provides timing to the processor for operations. Its
frequency is different for different versions, i.e. 5MHz, 8MHz and 10MHz.
Address/data bus
AD0-AD15. These are 16 address/data bus. AD0-AD7 carries low order byte data and
AD8AD15 carries higher order byte data. During the first clock cycle, it carries 16-bit address
and after that it carries 16-bit data.
Address/status bus
51 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
A16-A19/S3-S6. These are the 4 address/status buses. During the first clock cycle, it carries 4-bit
address and later it carries status signals.
S7/BHE
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.
Read($\overline{RD}$)
Ready
It is available at pin 32. It is an acknowledgement signal from I/O devices that data is transferred.
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.
RESET
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
It is available at pin 18. It is an interrupt request signal, which is sampled during the last clock
cycle of each instruction to determine if the processor considered this as an interrupt or not.
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.
$\overline{TEST}$
This signal is like wait state and is available at pin 23. When this signal is high, then the
processor has to wait for IDLE state, else the execution continues.
MN/$\overline{MX}$
It stands for Minimum/Maximum and is available at pin 33. It indicates what mode the processor
is to operate in; when it is high, it works in the minimum mode and vice-aversa.
INTA
52 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
It is an interrupt acknowledgement signal and id available at pin 24. When the microprocessor
receives this signal, it acknowledges the interrupt.
ALE
It stands for address enable latch and is available at pin 25. A positive pulse is generated each
time the processor begins any operation. This signal indicates the availability of a valid address
on the address/data lines.
DEN
It stands for Data Enable and is available at pin 26. It is used to enable Transreceiver 8286. The
transreceiver is a device used to separate data from the address/data bus.
DT/R
It stands for Data Transmit/Receive signal and is available at pin 27. It decides the direction of
data flow through the transreceiver. When it is high, data is transmitted out and vice-a-versa.
M/IO
This signal is used to distinguish between memory and I/O operations. When it is high, it
indicates I/O operation and when it is low indicates the memory operation. It is available at pin
28.
WR
It stands for write signal and is available at pin 29. It is used to write the data into the memory or
the output device depending on the status of M/IO signal.
HLDA
It stands for Hold Acknowledgement signal and is available at pin 30. This signal acknowledges
the HOLD signal.
HOLD
This signal indicates to the processor that external devices are requesting to access the
address/data buses. It is available at pin 31.
These are queue status signals and are available at pin 24 and 25. These signals provide the status
of instruction queue. Their conditions are shown in the following table −
53 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
0 0 No operation
0 1 First byte of opcode from the queue
1 0 Empty the queue
1 1 Subsequent byte from the queue
S0, S1, S2
These are the status signals that provide the status of operation, which is used by the Bus
Controller 8288 to generate memory & I/O control signals. These are available at pin 26, 27, and
28. Following is the table showing their status −
S2 S1 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
1 0 1 Memory read
1 1 0 Memory write
1 1 1 Passive
LOCK
When this signal is active, it indicates to the other processors not to ask the CPU to leave the
system bus. It is activated using the LOCK prefix on any instruction and is available at pin 29.
These are the Request/Grant signals used by the other processors requesting the CPU to release
the system bus. When the signal is received by CPU, then it sends acknowledgment. RQ/GT0 has
a higher priority than RQ/GT1.
The programming model for a microprocessor shows the various internal registers that are
accessible to the programmer. The Following Figure is a model for the 8086. In general, each
register has a special function.
54 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
c. Assembler directives:
55 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
1. DB - The DB directive is used to declare a BYTE -2-BYTE variable - A BYTE is made up of 8 bits.
Declaration examples:
Byte1 DB 10h
Byte2 DB 255 ; 0FFh, the max. possible for a BYTE
CRLF DB 0Dh, 0Ah, 24h ;Carriage Return, terminator BYTE
2. DW - The DW directive is used to declare a WORD type variable - A WORD occupies 16 bits or (2 BYTE).
Declaration examples:
Word DW 1234h
Word2 DW 65535; 0FFFFh, (the max. possible for a WORD)
3. DD - The DD directive is used to declare a DWORD - A DWORD double word is made up of 32 bits =2
Word's or 4 BYTE.
Declaration examples:
Dword1 DW 12345678h
Dword2 DW 4294967295 ;0FFFFFFFFh.
4. STRUCT and ENDS directives to define a structure template for grouping data items.
(1) The STRUCT directive tells the assembler that a user defined uninitialized data structure follows. The uninitialized
data structure consists of a combination of the three supported data types. DB, DW, and DD. The labels serve as
zero-based offsets into the structure. The first element's offset for any structure is 0. A structure element is referenced
with the base "+" operator before the element's name.
A Structure ends by using the ENDS directive meaning END of Structure.
Syntax:
STRUCT
56 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Structure_element_name element_data_type?
...
...
...
ENDS
(OR)
STRUC
Structure_element_name element_data_type?
...
...
...
ENDS
DECLARATION:
STRUCT
Byte1 DB?
Byte2 DB?
Word1 DW?
Word2 DW?
Dword1DW?
Dword2 DW?
ENDS
Use OF STRUCT:
The STRUCT directive enables us to change the order of items in the structure when, we reform a file header and
shuffle the data. Shuffle the data items in the file header and reformat the sequence of data declaration in the
STRUCT and off you go. No change in the code we write that processes the file header is necessary unless you
inserted an extra data element.
The EQU directive is used to give name to some value or symbol. Each time the assembler finds the given names in
the program, it will replace the name with the value or a symbol. The value can be in the range 0 through 65535 and
it can be another Equate declared anywhere above or below.
THIS BYTE
THIS WORD
THIS DWORD
A variable - declared with a DB, DW, or DD directive - has an address and has space reserved at that address for it in
the .COM file. But an Equate does not have an address or space reserved for it in the .COM file.
57 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Example:
(6) Extern:
It is used to tell the assembler that the name or label following the directive are I some other assembly module. For
example: if you call a procedure which is in program module assembled at a different time from that which contains
the CALL instructions ,you must tell the assembler that the procedure is external the assembler will put information in
the object code file so that the linker can connect the two module together.
Example:
(7) GLOBAL:
The GLOBAL directive can be used in place of PUBLIC directive .for a name defined in the current assembly module;
the GLOBAL directive is used to make the symbol available to the other modules. Example:
GLOBAL DIVISOR:
WORD tells the assembler that DIVISOR is a variable of type of word which is in another assembly module or
EXTERN.
(8) SEGMENT:
It is used to indicate the start of a logical segment. It is the name given to the the segment. Example: the code
segment is used to indicate to the assembler the start of logical segment.
It is used to identify the start of a procedure. It follows a name we give the procedure.
After the procedure the term NEAR and FAR is used to specify the procedure Example: SMART-DIVIDE PROC FAR
identifies the start of procedure named SMART-DIVIDE and tells the assembler that the procedure is far.
(10) NAME:
It is used to give a specific name to each assembly module when program consists of several modules.
Example: PC-BOARD used to name an assembly module which contains the instructions for controlling a printed
circuit board.
58 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
(11) INCLUDE:
It is used to tell the assembler to insert a block of source code from the named file into the current source module.
This shortens the source module. An alternative is use of editor block command to cop the file into the current source
module.
(12) OFFSET:
It is an operator which tells the assembler to determine the offset or displacement of a named data item from the start
of the segment which contains it. It is used to load the offset of a variable into a register so that variable can be
accessed with one of the addressed modes. Example: when the assembler read MOV BX.OFFSET PRICES, it will
determine the offset of the prices.
(13) GROUP:
It can be used to tell the assembler to group the logical segments named after the directive into one logical group.
This allows the contents of all he segments to be accessed from the same group. Example: SMALL-SYSTEM
GROUP CODE, DATA, STACK-SEG.
4.3 Instruction set- data transfer group, Arithmetic group, logical group, control transfer
group, miscellaneous instruction groups
MOV − Used to copy the byte or word from the provided source to the provided
destination.
PPUSH − Used to put a word at the top of the stack.
POP − Used to get a word from the top of the stack to the provided location.
PUSHA − Used to put all the registers into the stack.
59 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
IN − Used to read a byte or word from the provided port to the accumulator.
OUT − Used to send out a byte or word from the accumulator to the provided port.
LEA − Used to load the address of operand into the provided register.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
LAHF − Used to load AH with the low byte of the flag register.
SAHF − Used to store AH register to low byte of the flag register.
PUSHF − Used to copy the flag register at the top of the stack.
POPF − Used to copy a word at the top of the stack to the flag register.
Arithmetic Instructions
These instructions are used to perform arithmetic operations like addition, subtraction,
multiplication, division, etc.
60 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
DIV − Used to divide the unsigned word by byte or unsigned double word by word.
IDIV − Used to divide the signed word by byte or signed double word by word.
AAD − Used to adjust ASCII codes after division.
CBW − Used to fill the upper byte of the word with the copies of sign bit of the lower
byte.
CWD − Used to fill the upper word of the double word with the sign bit of the lower
word.
SHL/SAL − Used to shift bits of a byte/word towards left and put zero(S) in LSBs.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB into the
new MSB.
61 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
ROL − Used to rotate bits of byte/word towards the left, i.e. MSB to LSB and to Carry
Flag [CF].
ROR − Used to rotate bits of byte/word towards the right, i.e. LSB to MSB and to Carry
Flag [CF].
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to LSB.
String Instructions
String is a group of bytes/words and their memory is always allocated in a sequential order.
CALL − Used to call a procedure and save their return address to the stack.
RET − Used to return from the procedure to the main program.
JMP − Used to jump to the provided address to proceed to the next instruction.
62 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
LOOP − Used to loop a group of instructions until the condition satisfies, i.e., CX = 0
LOOPE/LOOPZ − Used to loop a group of instructions till it satisfies ZF = 1 & CX = 0
LOOPNE/LOOPNZ − Used to loop a group of instructions till it satisfies ZF = 0 & CX
=0
JCXZ − Used to jump to the provided address if CX = 0
Interrupt Instructions
These instructions are used to call the interrupt during program execution.
63 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
INT − Used to interrupt the program during execution and calling service specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program
64 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
A single chip computer or A CPU with all the peripherals like RAM, ROM, I/O Ports,
Timers , ADCs etc... on the same chip. For ex: Motorola’s 6811, Intel’s 8051, Zilog’s Z8 and
PIC 16X etc…
A microcontroller is a highly integrated single chip, which consists of on chip CPU (Central
Processing Unit), RAM (Random Access Memory), EPROM/PROM/ROM (Erasable
Programmable Read Only Memory), I/O (input/output) – serial and parallel, timers, interrupt
controller. For example, Intel 8051 is 8-bit microcontroller and Intel 8096 is 16-bit
microcontroller. The block diagram of Microcontroller is shown in Fig.2.
65 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
66 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
ix. Four Parallel ports each of 8-bits (PORT0, PORT1,PORT2,PORT3) with a total of 32 I/O
67 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
lines.
x. One 16-bit program counter and One 16-bit DPTR ( data pointer)
68 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
8051 has 8-bit ALU which can perform all the 8-bit arithmetic and logical operations in one
machine cycle. The ALU is associated with two registers A & B
A and B Registers : The A and B registers are special function registers which hold the results of
many arithmetic and logical operations of 8051.The A register is also called the Accumulator and
as it’s name suggests, is used as a general register to accumulate the results of a large number of
instructions. By default it is used for all mathematical operations and also data transfer operations
between CPU and any external memory.
The B register is mainly used for multiplication and division operations along with A register.
It has no other function other than as a location where data may be stored.
The R registers: The "R" registers are a set of eight registers that are named R0, R1, etc. up to
and including R7. These registers are used as auxillary registers in many operations. The "R"
registers are also used to temporarily store values.
Program Counter(PC) : 8051 has a 16-bit program counter .The program counter always points
to the address of the next instruction to be executed. After execution of one instruction the program
counter is incremented to point to the address of the next instruction to be executed.It is the
contents of the PC that are placed on the address bus to find and fetch the desired instruction.Since
the PC is 16-bit width ,8051 can access program addresses from 0000H to FFFFH ,a total of 6kB
of code.
Stack Pointer Register (SP) : It is an 8-bit register which stores the address of the stack top. i.e
the Stack Pointer is used to indicate where the next value to be removed from the stack should be
taken from. When a value is pushed onto the stack, the 8051 first increments the value of SP and
then stores the value at the resulting memory location. Similarly when a value is popped off the
stack, the 8051 returns the value from the memory location indicated by SP, and then decrements
the value of SP. Since the SP is only 8-bit wide it is incremented or decremented by two . SP is
modified directly by the 8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI.
It is also used intrinsically whenever an interrupt is triggered.
69 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
STACK in 8051 Microcontroller : The stack is a part of RAM used by the CPU to store
information temporarily. This information may be either data or an address .The CPU needs this
storage area as there are only limited number of registers. The register used to access the stack is
called the Stack pointer which is an 8-bit register..So,it can take values of 00 to FF H.When the
8051 is powered up ,the SP register contains the value 07.i.e the RAM location value 08 is the first
location being used for the stack by the 8051 controller
There are two important instructions to handle this stack.One is the PUSH and the Other
is the POP. The loading of data from CPU registers to the stack is done by PUSH and the loading
of the contents of the stack back into aCPU register is done by POP.
EX : MOV R6 ,#35 H
MOV R1 ,#21 H
PUSH 6
PUSH 1
In the above instructions the contents of the Registers R6 and R1 are moved to stack and they
occupy the 08 and 09 locations of the stack.Now the contents of the SP are incremented by two
and it is 0A
Similarly POP 3 instruction pops the contents of stack into R3 register.Now the contents of the SP
is decremented by 1
In 8051 the RAM locations 08 to 1F (24 bytes) can be used for the Stack.In any program if we
need more than 24 bytes of stack ,we can change the SP point to RAM locations 30-7F H.this can
be done with the instruction MOV SP,# XX.
Data Pointer Register(DPTR) : It is a 16-bit register which is the only user-accessible. DPTR,
as the name suggests, is used to point to data. It is used by a number of commands which allow
the 8051 to access external memory. When the 8051 accesses external memory it will access
external memory at the address indicated by DPTR. This DPTR can also be used as two 8-registers
DPH and DPL.
Program Status Register (PSW) : The 8051 has a 8-bit PSW register which is alsoknown as Flag
register.In the 8-bit register only 6-bits are used by 8051.The two unused bits are user definable
bits.In the 6-bits four of them are conditional flags .They are Carry –CY,Auxiliary Carry-AC,
70 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Parity-P,and Overflow-OV .These flag bits indicate some conditions that resulted after an
instruction was executed.
The bits PSW3 and PSW4 are denoted as RS0 and RS1 and these bits are used th select the bank
registers of the RAM location. The meaning of various bits of PSW register is shown below.
CY PSW.7 Carry Flag
AC PSW.6 Auxiliary Carry Flag
FO PSW.5 Flag 0 available for general purpose .
RS1 PSW.4 Register Bank select bit 1
RS0 PSW.3 Register bank select bit 0
OV PSW.2 Overflow flag
--- PSW.1 User difinable flag
P PSW.0 Parity flag .set/cleared by hardware.
The selection of the register Banks and their addresses are given below.
RS1 RS0 Register Bank Address
0 0 0 00H-07H
0 1 1 08H-0FH
1 0 2 10H-17H
1 1 3 18H-1FH
71 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Memory organization :
The 8051 microcontroller has 128 bytes of Internal RAM and 4kB of on chip ROM .The RAM is
also known as Data memory and the ROM is known as program memory. The program memory
is also known as Code memory .This Code memory holds the actual 8051 program that is to be
executed. In 8051 this memory is limited to 64K .Code memory may be found on-chip, as ROM
or EPROM. It may also be stored completely off-chip in an external ROM or, more commonly,
an external EPROM. The 8051 has only 128 bytes of Internal RAM but it supports 64kB of external
RAM. As the name suggests, external RAM is any random access memory which is off-chip.
Since the memory is off-chip it is not as flexible interms of accessing, and is also slower. For
example, to increment an Internal RAM location by 1,it requires only 1 instruction and 1
instruction cycle but to increment a 1-byte value stored in External RAM requires 4 instructions
and 7 instruction cycles. So, here the external memory is 7 times slower.
(iii) 80 bytes of general purpose area (Scratch pad memory) as shown in the diagram below. This
area is also utilized by the microcontroller as a storage area for the operating stack.
72 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The 32 bytes of RAM from address 00 H to 1FH are used as working registers organized as four
banks of eight registers each.The registers are named as R0-R7 .Each register can be addressed
by its name or by its RAM address.
Internal ROM (On –chip ROM): The 8051 microcontroller has 4kB of on chip ROM but it can
be extended up to 64kB.This ROM is also called program memory or code memory. The CODE
segment is accessed using the program counter (PC) for opcode fetches and by DPTR for data.
The external ROM is accessed when the EA(active low) pin is connected to ground or the contents
of program counter exceeds 0FFFH.When the Internal ROM address is exceeded the 8051
automatically fetches the code bytes from the external program memory.
73 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The list of SFRs and their functional names are given below. In these SFRs some of them are
related to I/O ports (P0,P1,P2 and P3) and some of them are meant for control operations
(TCON,SCON, PCON..) and remaining are the auxillary SFRs, in the sense that they don't directly
configure the 8051.
74 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
5.2 Special Function Registers , Pins and Signals ,Timing and control , Port Operation –
Memory and I/O interfacing , Interrupts , Instruction Set and Programming.
PIN Diagram of 8051 Microcontroller : The 8051 microcontroller is available as a 40 pin DIP
chip and it works at +5 volts DC. Among the 40 pins , a total of 32 pins are allotted for the four
parallel ports P0,P1,P2 and P3 i.e each port occupies 8-pins .The remaining pins are VCC, GND,
XTAL1, XTAL2, RST, EA ,PSEN.
75 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
XTAL1,XTAL2: These two pins are connected to Quartz crystal oscillator which runs the on-
chip oscillator. The quartz crystal oscillator is connected to the two pins along with a capacitor of
30pF as shown in the circuit. If we use a source other than the crystal oscillator, it will be
connected to XTAL1 and XTAL2 is left unconnected.
76 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
RST: The RESET pin is an input pin and it is an active high pin. When a high pulse is applied to
this pin the microcontroller will reset and terminate all activities. Upon reset all the registers except
PC will reset to 0000 Value and PC register will reset to 0007 value.
(External Access): This pin is an active low pin. This pin is connected to ground when
microcontroller is accessing the program code stored in the external memory and connected to
Vcc when it is accessing the program code in the on chip memory. This pin should not be left
unconnected.
(Program Store Enable) : This is an output pin which is active low. When the
microcontroller is accessing the program code stored in the external ROM ,this pin is connected
to the OE (Output Enable) pin of the ROM.
77 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
ALE (Address latch enable): This is an output pin, which is active high. When connected to
external memory , port 0 provides both address and data i.e address and data are multiplexed
through port 0 .This ALE pin will demultiplex the address and data bus .When the pin is High ,
the AD bus will act as address bus otherwise the AD bus will act as Data bus.
P0.0- P0.7(AD0-AD7) : The port 0 pins multiplexed with Address/data pins .If the microcontroller
is accessing external memory these pins will act as address/data pins otherwise they are used for
Port 0 pins.
P2.0- P2.7(A8-A15) : The port2 pins are multiplexed with the higher order address pins .When
the microcontroller is accessing external memory these pins provide the higher order address byte
otherwise they act as Port 2 pins.
P1.0- P1.7 :These 8-pins are dedicated for Port1 to perform input or output port operations.
P3.0- P3.7 :These 8-pins are meant for Port3 operations and also for some control operations like
Read,Write,Timer0,Timer1 ,INT0,INT1 ,RxD and TxD
Arithmetic Instructions
Branch Instructions
Data Transfer Instructions
Logic Instructions
Bit-oriented Instructions
The first part of each instruction, called MNEMONIC refers to the operation an
instruction performs (copy, addition, logic operation etc.). Mnemonics are
abbreviations of the name of operation being executed. For example:
78 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
The 8051 Microcontroller is used to provide the control signals to the ADC. CS(chip select) pin of ADC is
directly connected to ground. The pin P1.1, P1.0 and P1.2 are connected to the pin WR, RD and INTR of
the ADC respectively. When the input voltage from the preset is varied the output of ADC varies also
varies.
79 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
From the circuit it is clear that the ADC interfaced directly to the microcontroller. The Port1 is
used as an input port which receives the digital data from the ADC.Port pins P2.5 and P2.6 are
used for SOC and EOC operation.When the conversion is over the ADC will send an interrupt
signal to the microcontroller through the pin P2.7 .Now the Microcontroller receives digital data
through the Port1.This data after conversion to decimal data is displayed on the LCD module .
MOV P1 , 0FF H ; Make the port1 high and configure port1 as Input port
SETB P2.5 ;
80 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
A stepper motor is a device that translates electrical pulses into mechanical movement. The
stepper motor rotates in steps in response to the applied signals. It is used in applications such as
disk drives, dot matrix printers, plotters and robotics.It is mainly used for position control. Stepper
motors have a permanent magnet called rotor (also called the shaft) surrounded by a stator . There
are also steppers called variable reluctance stepper motors that do not have a PM rotor. The most
common stepper motors have four stator windings that are paired with a center-tapped. This type
of stepper motor is commonly referred to as a. four-phase or unipolar stepper motor. The center
tap allows a change of current direction in each of two coils when a winding is grounded, thereby
resulting in a polarity change of the stator.
81 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
acall delay
mov stepper, #06H ; phase II code
acall delay
mov stepper, #03H ;Phase III code
acall delay ;Call delay subroutine program
mov stepper, #09H ;Phase IV code
acall delay
sjmp Main
CALL DELAY PROGRAM :
mov r7,#4
wait2:
mov r6,#0FFH
wait1:
mov r5,#0FFH
wait:
djnz r5,wait
djnz r6,wait1
djnz r7,wait2
ret
end
82 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Continuous, sustained operation of the motor will cause the L293 Dual H-Bridge driver to
overheat. So,a suitable heat sink must be used.
83 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
MONITOR
SETB P1.0 Enable the H-bridge driver
JNB P2.7 CLOCKWISE
CLR P1.1 01 is for Counter clockwise
SETB P1.2
SJMP MONITOR
CLOCKWISE SETB P1.1 10 is for clockwise
CLR P1.2
SJMP MONITOR
INTERFACING DAC -8051 MICROCONTROLLER
The DAC 0800 is a simple monolithic 8-bit D/A converter. It has fast settling time of 100ns. It can be
directly interfaced to TTL, CMOS, PMOS and others. It operates at 4.5V to +18V supply. The number of
data bit inputs decides the resolution of the DAC since the number of analog output levels is equal to 2″,
where n is the number of data bit inputs. Therefore, an 8-input DAC such as the DAC0808 provides 256
discrete voltage (or current) levels of output.
The interfacing circuit is shown below. port 1(8 bits of the microcontroller is connected to the
input data lines of DAC-08.The reference current is determined by the resistor R1 and the reference
voltage V ref. The resistor R2 is generally equal to R1 to match the input impedance of reference
source. The output (taken from pin number 4 is observed either on a digital multimeter or on a
cathode ray oscilloscope.
84 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
INC A
The 8051 microcontroller has FIVE interrupts in addition to Reset. They are
Timer 0 overflow Interrupt
85 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Each interrupt has a specific place in code memory where program execution (interrupt service
routine) begins.
External Interrupt 0: 0003 H
Upon reset all Interrupts are disabled & do not respond to the Microcontroller. These interrupts
must be enabled by software in order for the Microcontroller to respond to them. This is done by
an 8-bit register called Interrupt Enable Register (IE).
EA : Global enable/disable. To enable the interrupts this bit must be set High.
86 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Upon reset the interrupts have the following priority.(Top to down). The interrupt with the highest
PRIORITY gets serviced first.
1. External interrupt 0 (INT0)
Priority can also be set to “high” or “low” by 8-bit IP register.- Interrupt priority register
IP.7: reserved
IP.6: reserved
IP.5: Timer 2 interrupt priority bit (8052 only)
IP.4: Serial port interrupt priority bit
IP.3: Timer 1 interrupt priority bit
IP.2: External interrupt 1 priority bit
IP.1: Timser 0 interrupt priority bit
IP.0: External interrupt 0 priority bit
TIMERS in 8051 Microcontrollers : The 8051 microcontroller has two 16-bit timers
Timer 0 (T0) and Timer 1(T1) which can be used either to generate accurate time delays or as
event counters. These timers are accessed as two 8-bit registers TLO, THO & TL1 ,TH1 because
the 8051 microcontroller has 8-bit architecture.
TIMER 0 : The Timer 0 is a 16-bit register and can be treated as two 8-bit registers (TL0 & TH0)
and these registers can be accessed similar to any other registers like A,B or R1,R2,R3 etc…
Ex : The instruction Mov TL0,#07 moves the value 07 into lower byte of Timer0.
87 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
TIMER 1 : The Timer 1 is also a 16-bit register and can be treated as two 8-bit registers (TL1 &
TH1) and these registers can be accessed similar to any other registers like A,B or R1,R2,R3 etc…
Ex : The instruction MOV TL1,#05 moves the value 05 into lower byte of Timer1.
Similarly MOV R0,TH1 saves the contents of TH1 in the R0 register
TMOD Register : The various operating modes of both the timers T0 and T1 are set by an 8-bit
register called TMOD register. In this TMOD register the lower 4-bits are meant for Timer 0 and
the higher 4-bits are meant for Timer1.
GATE: This bit is used to start or stop the timers by hardware .When GATE= 1 ,the timers can be
started / stopped by the external sources. When GATE= 0, the timers can be started or stopped by
software instructions like SETB TR0 or SETB TR1
C/T (clock/Timer) : This bit decides whether the timer is used as delay generator or event
counter. When C/T = 0 ,the Timer is used as delay generator and if C/T=1 the timer is used as
an event counter. The clock source for the time delay is the crystal frequency of 8051.
M1,M0 (Mode) : These two bits are the timer mode bits. The timers of the 8051 can be configured
in three modes.Mode0, Mode1 and Mode2.The selection and operation of the modes is shown
below.
88 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
5.4 Introduction to high end processors and Introduction to AVR family architecture
There are major Microprocessor companies as Intel , AMD, ARM etc. These companies design
and manufacture different architecture of microprocessor as 32 bit and 64 bit. The ARM company
design 32 bit Microprocessor for Smartphone’s and Intel/AMD design and manufacture
Microprocessor for PC and High End Computers’s (Servers, Workstations, Data Centers). Intel
has x86 series of Microprocessor which now branded with multicore Itanium (I3, I5, I7 etc.) series
where AMD also have such 64 bit Microprocessors.
AVR was developed in the year 1996 by Atmel Corporation. The architecture of AVR was
developed by Alf-Egil Bogen and Vegard Wollan. AVR derives its name from its developers and
stands for Alf-Egil Bogen Vegard Wollan RISC microcontroller, also known
as Advanced Virtual RISC.
89 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
AVR Architecture
• RISC architecture with CISC instruction set • Powerful instruction set for C and Assembly
• Scalable • Same powerful AVR core in all devices
• Single cycle execution • One instruction per external clock
• Low power consumption • 32 Working Registers
• All Directly connected to ALU! • Very efficient core
• 20 MIPS @ 20MHz • High System Level Integration
• Lowest total system cost • User Friendly
90 | P a g e
Email: [email protected] or www.digitronixnepal.com
Microprocessor and Microcontroller Reference Manual (CTEVT, DEE/II/II) Prepared by Er. Krishna Gaihre
Reference books:
1. Douglas V Hal, ‘Microprocessor and Interfacing, Programming and Hardware’ TMH
2006
2. Liu and Gibson,’ Micro computer System 8086/8088 family architecture,
programming and design’ PHI 2nd edition.
3. K Uma Rao, The 8051 Microcontroller, architecture, programming and applications’,
Pearson 2009.
3. Muhammed Ali Mazidi, Janice Gillies Pie Mazidi, “The 8051 Microcontroller and Embedded
Systems”— Pearson EducationAsia.
91 | P a g e
Email: [email protected] or www.digitronixnepal.com