w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INTRODUCTION
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Control Unit
Generates signals within uP to carry out the instruction, which has been decoded. In
reality causes certain connections between blocks of the uP to be opened or closed, so
that data goes where it is required, and so that ALU operations occur.
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
The ALU performs the actual numerical and logic operation such as add, subtract,
AND, OR, etc. Uses data from memory and from Accumulator to perform
arithmetic. Always stores result of operation in Accumulator.
Registers
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.
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.
For example, after an addition of two numbers, if the sum in the accumulator id larger
than eight bits, the flip-flop uses to indicate a carry -- called the Carry flag (CY) -- is
set to one. When an arithmetic operation results in zero, the flip-flop called the
Zero(Z) flag is set to one. The first Figure shows an 8-bit register, called the flag
register, adjacent to the accumulator. However, it is not used as a register; five bit
positions out of eight are used to store the outputs of the five flip-flops. The flags are
stored in the 8-bit register so that the programmer can examine these flags (data
conditions) by accessing the register through an instruction.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
These flags have critical importance in the decision-making process of the microprocessor. The conditions (set or reset) of the flags are tested through the software
instructions. For example, the instruction JC (Jump on Carry) is implemented to
change the sequence of a program when CY flag is set. The thorough understanding
of flag is essential in writing assembly language programs.
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
This 16-bit register deals with sequencing the execution of instructions. This register
is a memory pointer. Memory locations have 16-bit addresses, and that is why this is a
16-bit register.
The microprocessor uses this register to sequence the execution of the instructions.
The function of the program counter is to point to the memory address from which the
next byte is to be fetched. When a byte (machine code) is being fetched, the program
counter is incremented by one to point to the next memory location
The stack pointer is also a 16-bit register used as a memory pointer. It points to a
memory location in R/W memory, called the stack. The beginning of the stack is
defined by loading 16-bit address in the stack pointer. The stack concept is explained
in the chapter "Stack and Subroutines."
Instruction Register/Decoder
Temporary store for the current instruction of a program. Latest instruction sent here
from memory prior to execution. Decoder then takes instruction and decodes or
interprets the instruction. Decoded instruction then passed to next stage.
Holds address, received from PC, of next program instruction. Feeds the address bus
with addresses of location of the program under execution.
Control Generator
Generates signals within uP to carry out the instruction which has been decoded. In
reality causes certain connections between blocks of the uP to be opened or closed, so
that data goes where it is required, and so that ALU operations occur.
Register Selector
This block controls the use of the register stack in the example. Just a logic circuit
which switches between different registers in the set will receive instructions from
Control Unit.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprogramming
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
How does the P knows what an instruction means, especially when it is only a
binary number? The microprogram in a uP/uC is written by the chip designer and tells
the uP/uC the meaning of each instruction uP/uC can then carry out operation.
Typical system uses a number of busses, collection of wires, which transmit binary
numbers, one bit per wire. A typical microprocessor communicates with memory and
other devices (input and output) using three busses: Address Bus, Data Bus and
Control Bus.
Address Bus
One wire for each bit, therefore 16 bits = 16 wires. Binary number carried alerts
memory to open the designated box. Data (binary) can then be put in or taken
out.The Address Bus consists of 16 wires, therefore 16 bits. Its "width" is 16 bits. A
16 bit binary number allows 216 different numbers, or 32000 different numbers, ie
0000000000000000 up to 1111111111111111. Because memory consists of boxes,
each with a unique address, the size of the address bus determines the size of memory,
which can be used. To communicate with memory the microprocessor sends an
address on the address bus, eg 0000000000000011 (3 in decimal), to the memory. The
memory the selects box number 3 for reading or writing data. Address bus is
unidirectional, ie numbers only sent from microprocessor to memory, not other way.
Question?: If you have a memory chip of size 256 kilobytes (256 x 1024 x 8 bits),
how many wires does the address bus need, in order to be able to specify an address in
this memory? Note: the memory is organized in groups of 8 bits per location,
therefore, how many locations must you be able to specify?
Data Bus
Data Bus: carries data, in binary form, between P and other external units, such as
memory. Typical size is 8 or 16 bits. Size determined by size of boxes in memory and
P size helps determine performance of P. The Data Bus typically consists of 8
wires. Therefore, 28 combinations of binary digits. Data bus used to transmit "data",
ie information, results of arithmetic, etc, between memory and the microprocessor.
Bus is bi-directional. Size of the data bus determines what arithmetic can be done. If
only 8 bits wide then largest number is 11111111 (255 in decimal). Therefore, larger
number have to be broken down into chunks of 255. This slows microprocessor. Data
Bus also carries instructions from memory to the microprocessor. Size of the bus
therefore limits the number of possible instructions to 256, each specified by a
separate number.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Control Bus
Control Bus are various lines which have specific functions for coordinating and
controlling uP operations. Eg: Read/NotWrite line, single binary digit. Control
whether memory is being written to (data stored in mem) or read from (data taken
out of mem) 1 = Read, 0 = Write. May also include clock line(s) for
timing/synchronising, interrupts, reset etc. Typically P has 10 control lines.
Cannot function correctly without these vital control signals.
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
The Control Bus carries control signals partly unidirectional, partly bi-directional.
Control signals are things like "read or write". This tells memory that we are either
reading from a location, specified on the address bus, or writing to a location
specified. Various other signals to control and coordinate the operation of the system.
Modern day microprocessors, like 80386, 80486 have much larger busses. Typically
16 or 32 bit busses, which allow larger number of instructions, more memory
location, and faster arithmetic. Microcontrollers organized along same lines, except:
because microcontrollers have memory etc inside the chip, the busses may all be
internal. In the microprocessor the three busses are external to the chip (except for the
internal data bus). In case of external busses, the chip connects to the busses via
buffers, which are simply an electronic connection between external bus and the
internal data bus.
Single + 5V Supply
4 Vectored Interrupts (One is Non Maskable)
Serial In/Serial Out Port
Decimal, Binary, and Double Precision Arithmetic
Direct Addressing Capability to 64K bytes of memory
The Intel 8085A is a new generation, complete 8 bit parallel central processing unit
(CPU). The 8085A uses a multiplexed data bus. The address is split between the 8bit
address bus and the 8bit data bus. Figures are at the end of the document.
Pin Description
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
ALE (Output)
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
Address Latch Enable: It occurs during the first clock cycle of a machine state and
enables the address to get latched into the on chip latch of peripherals. The falling
edge of ALE is set to guarantee setup and hold times for the address information.
ALE can also be used to strobe the status information. ALE is never 3stated.
SO, S1 (Output)
HALT
WRITE
READ
FETCH
RD (Output 3state)
READ; indicates the selected memory or 1/0 device is to be read and that the Data
Bus is available for the data transfer.
WR (Output 3state)
WRITE; indicates the data on the Data Bus is to be written into the selected memory
or 1/0 location. Data is set up at the trailing edge of WR. 3stated during Hold and Halt
modes.
READY (Input)
If Ready is high during a read or write cycle, it indicates that the memory or
peripheral is ready to send or receive data. If Ready is low, the CPU will wait for
Ready to go high before completing the read or write cycle.
HOLD (Input)
HOLD; indicates that another Master is requesting the use of the Address and Data
Buses. The CPU, upon receiving the Hold request. will relinquish the use of buses as
soon as the completion of the current machine cycle. Internal processing can continue.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
The processor can regain the buses only after the Hold is removed. When the Hold is
acknowledged, the Address, Data, RD, WR, and IO/M lines are 3stated.
HLDA (Output)
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
HOLD ACKNOWLEDGE; indicates that the CPU has received the Hold request and
that it will relinquish the buses in the next clock cycle. HLDA goes low after the Hold
request is removed. The CPU takes the buses one half clock cycle after HLDA goes
low.
INTR (Input)
INTA (Output)
INTERRUPT ACKNOWLEDGE; is used instead of (and has the same timing as) RD
during the Instruction cycle after an INTR is accepted. It can be used to activate the
8259 Interrupt chip or some other interrupt port.
RST 5.5
RST 6.5 - (Inputs)
RST 7.5
RESTART INTERRUPTS; These three inputs have the same timing as I NTR except
they cause an internal RESTART to be automatically inserted.
RST 7.5 ~~ Highest Priority
RST 6.5
RST 5.5 o Lowest Priority
The priority of these interrupts is ordered as shown above. These interrupts have a
higher priority than the INTR.
TRAP (Input)
RESET IN (Input)
Reset sets the Program Counter to zero and resets the Interrupt Enable and HLDA
flipflops. None of the other flags or registers (except the instruction register) are
affected The CPU is held in the reset condition as long as Reset is applied.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
X1, X2 (Input)
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
Crystal or R/C network connections to set the internal clock generator X1 can also be
an external clock input instead of a crystal. The input frequency is divided by 2 to
give the internal operating frequency.
CLK (Output)
Clock Output for use as a system clock when a crystal or R/ C network is used as an
input to the CPU. The period of CLK is twice the X1, X2 input period.
IO/M (Output)
IO/M indicates whether the Read/Write is to memory or l/O Tristated during Hold and
Halt modes.
SID (Input)
Serial input data line The data on this line is loaded into accumulator bit 7 whenever a
RIM instruction is executed.
SOD (output)
Serial output data line. The output SOD is set or reset as specified by the SIM
instruction.
Vcc
+5 volt supply.
Vss
Ground Reference.
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
The 8085A is a complete 8 bit parallel central processor. It requires a single +5 volt
supply. Its basic clock speed is 3 MHz thus improving on the present 8080's
performance with higher system speed. Also it is designed to fit into a minimum
system of three IC's: The CPU, a RAM/ IO, and a ROM or PROM/IO chip.
The 8085A uses a multiplexed Data Bus. The address is split between the higher 8bit
Address Bus and the lower 8bit Address/Data Bus. During the first cycle the address
is sent out. The lower 8bits are latched into the peripherals by the Address Latch
Enable (ALE). During the rest of the machine cycle the Data Bus is used for memory
or l/O data.
The 8085A provides RD, WR, and lO/Memory signals for bus control. An Interrupt
Acknowledge signal (INTA) is also provided. Hold, Ready, and all Interrupts are
synchronized. The 8085A also provides serial input data (SID) and serial output data
(SOD) lines for simple serial interface.
In addition to these features, the 8085A has three maskable, restart interrupts and one
non-maskable trap interrupt. The 8085A provides RD, WR and IO/M signals for Bus
control.
Status Information
Status information is directly available from the 8085A. ALE serves as a status strobe.
The status is partially encoded, and provides the user with advanced timing of the
type of bus transfer being done. IO/M cycle status signal is provided directly also.
Decoded So, S1 Carries the following status information:
S1 can be interpreted as R/W in all bus transfers. In the 8085A the 8 LSB of address
are multiplexed with the data instead of status. The ALE line is used as a strobe to
enter the lower half of the address into the memory or peripheral address latch. This
also frees extra pins for expanded interrupt capability.
The8085A has5 interrupt inputs: INTR, RST5.5, RST6.5, RST 7.5, and TRAP. INTR
is identical in function to the 8080 INT. Each of the three RESTART inputs, 5.5, 6.5.
7.5, has a programmable mask. TRAP is also a RESTART interrupt except it is nonmaskable.
The three RESTART interrupts cause the internal execution of RST (saving the
program counter in the stack and branching to the RESTART address) if the interrupts
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
are enabled and if the interrupt mask is not set. The non-maskable TRAP causes the
internal execution of a RST independent of the state of the interrupt enable or masks.
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
The interrupts are arranged in a fixed priority that determines which interrupt is to be
recognized if more than one is pending as follows: TRAP highest priority, RST 7.5,
RST 6.5, RST 5.5, INTR lowest priority This priority scheme does not take into
account the priority of a routine that was started by a higher priority interrupt. RST
5.5 can interrupt a RST 7.5 routine if the interrupts were re-enabled before the end of
the RST 7.5 routine. The TRAP interrupt is useful for catastrophic errors such as
power failure or bus error. The TRAP input is recognized just as any other interrupt
but has the highest priority. It is not affected by any flag or mask. The TRAP input is
both edge and level sensitive.
The 8085A has a multiplexed Data Bus. ALE is used as a strobe to sample the lower
8bits of address on the Data Bus. Figure 2 shows an instruction fetch, memory read
and l/ O write cycle (OUT). Note that during the l/O write and read cycle that the l/O
port address is copied on both the upper and lower half of the address. As in the 8080,
the READY line is used to extend the read and write pulse lengths so that the 8085A
can be used with slow memory. Hold causes the CPU to relingkuish the bus when it is
through with it by floating the Address and Data Buses.
System Interface
8085A family includes memory components, which are directly compatible to the
8085A CPU. For example, a system consisting of the three chips, 8085A, 8156, and
8355 will have the following features:
2K Bytes ROM
256 Bytes RAM
1 Timer/Counter
4 8bit l/O Ports
1 6bit l/O Port
4 Interrupt Levels
Serial In/Serial Out Ports
In addition to standard l/O, the memory mapped I/O offers an efficient l/O addressing
technique. With this technique, an area of memory address space is assigned for l/O
address, thereby, using the memory address for I/O manipulation. The 8085A CPU
can also interface with the standard memory that does not have the multiplexed
address/data bus.
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
The 8085 programming model includes six registers, one accumulator, and one flag
register, as shown in Figure. In addition, it has two 16-bit registers: the stack pointer
and the program counter. They are described briefly as follows.
ACCUMULATOR A
(8)
FLAG REGISTER
(8)
(8)
(8)
(8)
(8)
(8)
(16)
(16)
Data Bus
Address Bus
8 Lines Bidirectional
16 Lines unidirectional
Registers
The 8085 has six general-purpose registers to store 8-bit data; these are identified as
B,C,D,E,H, and L as shown in the figure. They can be combined as register pairs BC, DE, and HL - to perform some 16-bit operations. The programmer can use these
registers to store or copy data into the registers by using data copy instructions.
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.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Flags
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
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; 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.
D7
D6
D5
D4
AC
D3
D2
D1
D0
CY
For example, after an addition of two numbers, if the sum in the accumulator id larger
than eight bits, the flip-flop uses to indicate a carry -- called the Carry flag (CY) -- is
set to one. When an arithmetic operation results in zero, the flip-flop called the
Zero(Z) flag is set to one. The first Figure shows an 8-bit register, called the flag
register, adjacent to the accumulator. However, it is not used as a register; five bit
positions out of eight are used to store the outputs of the five flip-flops. The flags are
stored in the 8-bit register so that the programmer can examine these flags (data
conditions) by accessing the register through an instruction.
These flags have critical importance in the decision-making process of the microprocessor. The conditions (set or reset) of the flags are tested through the software
instructions. For example, the instruction JC (Jump on Carry) is implemented to
change the sequence of a program when CY flag is set. The thorough understanding
of flag is essential in writing assembly language programs.
This 16-bit register deals with sequencing the execution of instructions. This register
is a memory pointer. Memory locations have 16-bit addresses, and that is why this is a
16-bit register.
The microprocessor uses this register to sequence the execution of the instructions.
The function of the program counter is to point to the memory address from which the
next byte is to be fetched. When a byte (machine code) is being fetched, the program
counter is incremented by one to point to the next memory location
The stack pointer is also a 16-bit register used as a memory pointer. It points to a
memory location in R/W memory, called the stack. The beginning of the stack is
defined by loading 16-bit address in the stack pointer.
This programming model will be used in subsequent tutorials to examine how these
registers are affected after the execution of an instruction.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
1. Immediate addressing.
2. Register addressing.
3. Direct addressing.
4. Indirect addressing.
Immediate addressing
Data is present in the instruction. Load the immediate data to the destination provided.
Example: MVI R,data
Register addressing
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
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.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
This group of instructions copy data from a location called a source to another
location called a destination, without modifying the contents of the source. In
technical manuals, the term data transfer is used for this copying function. However,
the term transfer is misleading; it creates the impression that the contents of the
source are destroyed when, in fact, the contents are retained without any modification.
The various types of data transfer (copy) are listed below together with examples of
each type:
Types
1. Between Registers.
Examples
2. Specific data byte to a register or a 2. Load register B with the data byte 32H.
memory location.
input
keyboard
to
the
Arithmetic Operations
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
Logical Operations
These instructions perform various logical operations with the contents of the
accumulator.
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
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ARCHITECTURE OF 8086
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The 8086 has a total of fourteen 16-bit registers including a 16 bit register called the
status register, with 9 of bits implemented for status and control flags.
Most of the registers contain data/instruction offsets within 64 KB memory segment.
There are four different 64 KB segments for instructions, stack, data and extra data. To
specify where in 1 MB of processor memory these 4 segments are located the processor
uses four segment registers:
Code segment (CS) is a 16-bit register containing address of 64 KB segment with
processor instructions. The processor uses CS segment for all accesses to instructions
referenced by instruction pointer (IP) register. CS register cannot be changed directly.
The CS register is automatically updated during far jump, far call and far return
instructions.
Stack segment (SS) is a 16-bit register containing address of 64KB segment with
program stack. By default, the processor assumes that all data referenced by the stack
pointer (SP) and base pointer (BP) registers is located in the stack segment. SS register
can be changed directly using POP instruction.
Data segment (DS) is a 16-bit register containing address of 64KB segment with
program data. By default, the processor assumes that all data referenced by general
registers (AX, BX, CX, DX) and index register (SI, DI) is located in the data segment.
DS register can be changed directly using POP and LDS instructions.
Accumulator register consists of two 8-bit registers AL and AH, which can be
combined together and used as a 16-bit register AX. AL in this case contains the loworder byte of the word, and AH contains the high-order byte. Accumulator can be used
for I/O operations and string manipulation.
Base register consists of two 8-bit registers BL and BH, which can be combined together
and used as a 16-bit register BX. BL in this case contains the low-order byte of the word,
and BH contains the high-order byte. BX register usually contains a data pointer used for
based, based indexed or register indirect addressing.
Count register consists of two 8-bit registers CL and CH, which can be combined
together and used as a 16-bit register CX. When combined, CL register contains the loworder byte of the word, and CH contains the high-order byte. Count register can be used
in Loop, shift/rotate instructions and as a counter in string manipulation,.
Data register consists of two 8-bit registers DL and DH, which can be combined
together and used as a 16-bit register DX. When combined, DL register contains the loworder byte of the word, and DH contains the high-order byte. Data register can be used as
a port number in I/O operations. In integer 32-bit multiply and divide instruction the DX
register contains high-order word of the initial or resulting number.
The following registers are both general and index registers:
Stack Pointer (SP) is a 16-bit register pointing to program stack.
Base Pointer (BP) is a 16-bit register pointing to data in stack segment. BP register is
usually used for based, based indexed or register indirect addressing.
Source Index (SI) is a 16-bit register. SI is used for indexed, based indexed and register
indirect addressing, as well as a source data address in string manipulation instructions.
Destination Index (DI) is a 16-bit register. DI is used for indexed, based indexed and
register indirect addressing, as well as a destination data address in string manipulation
instructions.
Other registers:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Addressing Modes
Implied - the data value/data address is implicitly associated with the instruction.
Register - references the data in a register or in a register pair.
Immediate - the data is provided in the instruction.
Direct - the instruction operand specifies the memory address where data is located.
Register indirect - instruction specifies a register containing an address, where data is
located. This addressing mode works with SI, DI, BX and BP registers.
Based :- 8-bit or 16-bit instruction operand is added to the contents of a base register
(BX or BP), the resulting value is a pointer to location where data resides.
Indexed :- 8-bit or 16-bit instruction operand is added to the contents of an index
register (SI or DI), the resulting value is a pointer to location where data resides.
Based Indexed :- the contents of a base register (BX or BP) is added to the contents of
an index register (SI or DI), the resulting value is a pointer to location where data resides.
Based Indexed with displacement :- 8-bit or 16-bit instruction operand is added to the
contents of a base register (BX or BP) and index register (SI or DI), the resulting value is
a pointer to location where data resides.
Memory
Program, data and stack memories occupy the same memory space. As the most of the
processor instructions use 16-bit pointers the processor can effectively address only 64
KB of memory.
To access memory outside of 64 KB the CPU uses special segment registers to specify
where the code, stack and data 64 KB segments are positioned within 1 MB of memory
(see the "Registers" section below).
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Interrupts
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Processor exceptions: Divide Error (Type 0), Unused Opcode (type 6) and Escape
opcode (type 7).
Software interrupt processing is the same as for the hardware interrupts.
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
FLAGS REGISTER
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Flags Register - determines the current state of the processor. They are modified
automatically by CPU after mathematical operations, this allows to determine the type of
the result, and to determine conditions to transfer control to other parts of the program.
Generally you cannot access these registers directly.
1. Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For
example when you add bytes 255 + 1 (result is not in range 0...255). When there is
no overflow this flag is set to 0.
2. Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in
result, and to 0 when there is odd number of one bits.
3. Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow for low nibble (4
bits).
4. Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to
0.
5. Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to
0. (This flag takes the value of the most significant bit.)
6. Trap Flag (TF) - Used for on-chip debugging.
7. Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from
external devices.
8. Direction Flag (DF) - this flag is used by some instructions to process data chains,
when this flag is set to 0 - the processing is done forward, when this flag is set to 1
the processing is done backward.
9. Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when
you add bytes 100 + 50 (result is not in range -128...127).
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Notes:
When two operands are required for an instruction they are separated by comma. For example:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
REG, memory
When there are two operands, both operands must have the same size (except shift and rotate instructions).
For example:
AL, DL
DX, AX
m1 DB ?
AL, m1
m2 DW ?
AX, m2
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Operands
Description
AL = AL + 6
AH = AH + 1
AF = 1
CF = 1
AF = 0
CF = 0
else
AAA
No operands
in both cases:
clear the high nibble of AL.
Example:
MOV AX, 15 ; AH = 00, AL = 0Fh
AAA
; AH = 01, AL = 05
RET
C Z S O P A
r ? ? ? ? r
AAD
No operands
Algorithm:
AL = (AH * 10) + AL
AH = 0
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
MOV AX, 0105h ; AH = 01, AL = 05
AAD
; AH = 00, AL = 0Fh (15)
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
? r r ? r ?
AAM
AH = AL / 10
AL = remainder
No operands
Example:
MOV AL, 15 ; AL = 0Fh
AAM
; AH = 01, AL = 05
RET
C Z S O P A
? r r ? r ?
AAS
No operands
AL = AL - 6
AH = AH - 1
AF = 1
CF = 1
AF = 0
CF = 0
else
in both cases:
clear the high nibble of AL.
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
MOV AX, 02FFh ; AH = 02, AL = 0FFh
AAS
; AH = 01, AL = 09
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
r ? ? ? ? r
ADC
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
Algorithm:
r r r r r r
Add.
ADD
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
AND
Algorithm:
r r r r r r
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
Logical AND between all bits of two operands. Result is stored in operand1.
These rules apply:
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
MOV AL, 'a'
; AL = 01100001b
AND AL, 11011111b ; AL = 01000001b ('A')
RET
C Z S O P
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0 r r 0 r
CALL
procedure
name
label
4-byte
address
CALL p1
ADD AX, 1
RET
; return to OS.
unchanged
CBW
No operands
AH = 255 (0FFh)
AH = 0
else
Example:
MOV AX, 0 ; AH = 0, AL = 0
MOV AL, -5 ; AX = 000FBh (251)
CBW
; AX = 0FFFBh (-5)
RET
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
C Z S O P A
unchanged
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Algorithm:
CLC
No operands
CF = 0
C
CLD
No operands
DF = 0
D
CLI
No operands
IF = 0
I
CMC
No operands
if CF = 1 then CF = 0
if CF = 0 then CF = 1
C
r
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Compare.
Algorithm:
operand1 - operand2
result is not stored anywhere, flags are set (OF, SF, ZF, AF, PF, CF) according to
result.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
CMP
Example:
MOV AL, 5
MOV BL, 5
CMP AL, BL ; AL = 5, ZF = 1 (so equal!)
RET
C Z S O P A
r r r r r r
CMPSB
DS:[SI] - ES:[DI]
set flags according to result:
OF, SF, ZF, AF, PF, CF
if DF = 0 then
o SI = SI + 1
o DI = DI + 1
else
No operands
o
o
o
SI = SI - 1
DI = DI 1
DS:[SI] - ES:[DI]
C Z S O P A
r r r r r r
CMPSW
No operands
DS:[SI] - ES:[DI]
set flags according to result:
OF, SF, ZF, AF, PF, CF
if DF = 0 then
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
o
o
SI = SI + 2
DI = DI + 2
o
o
SI = SI - 2
DI = DI - 2
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
else
C Z S O P A
r r r r r r
DX = 65535 (0FFFFh)
DX = 0
else
CWD
No operands
Example:
MOV DX, 0 ; DX = 0
MOV AX, 0 ; AX = 0
MOV AX, -5 ; DX AX = 00000h:0FFFBh
CWD
; DX AX = 0FFFFh:0FFFBh
RET
C Z S O P A
unchanged
DAA
No operands
AL = AL + 6
AF = 1
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
AL = AL + 60h
CF = 1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Example:
MOV AL, 0Fh ; AL = 0Fh (15)
DAA
; AL = 15h
RET
C Z S O P A
r r r r r r
AL = AL - 6
AF = 1
DAS
No operands
AL = AL - 60h
CF = 1
Example:
MOV AL, 0FFh ; AL = 0FFh (-1)
DAS
; AL = 99h, CF = 1
RET
C Z S O P A
r r r r r r
Decrement.
Algorithm:
DEC
REG
memory
operand = operand - 1
Example:
MOV AL, 255 ; AL = 0FFh (255 or -1)
DEC AL
; AL = 0FEh (254 or -2)
RET
Z S O P A
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
r r r r r
CF - unchanged!
Unsigned divide.
Algorithm:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
DIV
REG
memory
Example:
MOV AX, 203 ; AX = 00CBh
MOV BL, 4
DIV BL
; AL = 50 (32h), AH = 3
RET
C Z S O P A
? ? ? ? ? ?
HLT
No operands
Example:
MOV AX, 5
HLT
C Z S O P A
unchanged
Signed divide.
Algorithm:
IDIV
REG
memory
Example:
MOV AX, -203 ; AX = 0FF35h
MOV BL, 4
IDIV BL
; AL = -50 (0CEh), AH = -3 (0FDh)
RET
C Z S O P A
? ? ? ? ? ?
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Signed multiply.
Algorithm:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
IMUL
REG
memory
Example:
MOV AL, -2
MOV BL, -4
IMUL BL
; AX = 8
RET
C Z S O P A
r ? ? r ? ?
IN
AL, im.byte
AL, DX
AX, im.byte
AX, DX
unchanged
Increment.
Algorithm:
operand = operand + 1
INC
REG
memory
Example:
MOV AL, 4
INC AL
; AL = 5
RET
Z S O P A
r r r r r
CF - unchanged!
immediate
byte
Algorithm:
Push to stack:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
o flags register
o CS
o IP
IF = 0
Transfer control to interrupt procedure
Example:
MOV AH, 0Eh ; teletype.
MOV AL, 'A'
INT 10h
; BIOS interrupt.
RET
C Z S O P A I
unchanged
if OF = 1 then INT 4
INTO
No operands
Example:
; -5 - 127 = -132 (not in -128..127)
; the result of SUB is wrong (124),
; so OF = 1 is set:
MOV AL, -5
SUB AL, 127 ; AL = 7Ch (124)
INTO
; process error.
RET
Interrupt Return.
Algorithm:
IRET
No operands
IP
CS
flags register
C Z S O P A
popped
JA
label
Short Jump if first operand is Above second operand (as set by CMP instruction).
Unsigned.
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Algorithm:
if (CF = 0) and (ZF = 0) then jump
Example:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, 250
CMP AL, 5
JA label1
PRINT 'AL is not above 5'
JMP exit
label1:
PRINT 'AL is above 5'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Above or Equal to second operand (as set by CMP
instruction). Unsigned.
Algorithm:
if CF = 0 then jump
Example:
label
JAE
ORG 100h
MOV AL, 5
CMP AL, 5
JAE label1
PRINT 'AL is not above or equal to 5'
JMP exit
label1:
PRINT 'AL is above or equal to 5'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Below second operand (as set by CMP instruction).
Unsigned.
JB
label
Algorithm:
if CF = 1 then jump
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, 1
CMP AL, 5
JB label1
PRINT 'AL is not below 5'
JMP exit
label1:
PRINT 'AL is below 5'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Below or Equal to second operand (as set by CMP
instruction). Unsigned.
Algorithm:
if CF = 1 or ZF = 1 then jump
Example:
JBE
label
ORG 100h
MOV AL, 5
CMP AL, 5
JBE label1
PRINT 'AL is not below or equal to 5'
JMP exit
label1:
PRINT 'AL is below or equal to 5'
exit:
RET
C Z S O P A
unchanged
JC
label
if CF = 1 then jump
Example:
ORG 100h
MOV AL, 255
ADD AL, 1
JC label1
PRINT 'no carry.'
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
JMP exit
label1:
PRINT 'has carry.'
exit:
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
unchanged
if CX = 0 then jump
Example:
JCXZ
label
ORG 100h
MOV CX, 0
JCXZ label1
PRINT 'CX is not zero.'
JMP exit
label1:
PRINT 'CX is zero.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Equal to second operand (as set by CMP instruction).
Signed/Unsigned.
Algorithm:
JE
if ZF = 1 then jump
Example:
label
ORG 100h
MOV AL, 5
CMP AL, 5
JE label1
PRINT 'AL is not equal to 5.'
JMP exit
label1:
PRINT 'AL is equal to 5.'
exit:
RET
C Z S O P A
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
unchanged
Short Jump if first operand is Greater then second operand (as set by CMP
instruction). Signed.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Algorithm:
if (ZF = 0) and (SF = OF) then jump
Example:
JG
label
ORG 100h
MOV AL, 5
CMP AL, -5
JG label1
PRINT 'AL is not greater -5.'
JMP exit
label1:
PRINT 'AL is greater -5.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Greater or Equal to second operand (as set by CMP
instruction). Signed.
Algorithm:
if SF = OF then jump
Example:
JGE
label
ORG 100h
MOV AL, 2
CMP AL, -5
JGE label1
PRINT 'AL < -5'
JMP exit
label1:
PRINT 'AL >= -5'
exit:
RET
C Z S O P A
unchanged
JL
label
Short Jump if first operand is Less then second operand (as set by CMP
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
instruction). Signed.
Algorithm:
if SF <> OF then jump
Example:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, -2
CMP AL, 5
JL label1
PRINT 'AL >= 5.'
JMP exit
label1:
PRINT 'AL < 5.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Less or Equal to second operand (as set by CMP
instruction). Signed.
Algorithm:
label
JLE
ORG 100h
MOV AL, -2
CMP AL, 5
JLE label1
PRINT 'AL > 5.'
JMP exit
label1:
PRINT 'AL <= 5.'
exit:
RET
C Z S O P A
unchanged
JMP
label
4-byte
address
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Algorithm:
always jump
Example:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, 5
JMP label1 ; jump over 2 lines!
PRINT 'Not Jumped!'
MOV AL, 0
label1:
PRINT 'Got Here!'
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Above second operand (as set by CMP
instruction). Unsigned.
Algorithm:
if CF = 1 or ZF = 1 then jump
Example:
JNA
label
ORG 100h
MOV AL, 2
CMP AL, 5
JNA label1
PRINT 'AL is above 5.'
JMP exit
label1:
PRINT 'AL is not above 5.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Above and Not Equal to second operand (as set
by CMP instruction). Unsigned.
Algorithm:
JNAE
label
if CF = 1 then jump
Example:
ORG 100h
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV AL, 2
CMP AL, 5
JNAE label1
PRINT 'AL >= 5.'
JMP exit
label1:
PRINT 'AL < 5.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Below second operand (as set by CMP
instruction). Unsigned.
Algorithm:
if CF = 0 then jump
Example:
JNB
label
ORG 100h
MOV AL, 7
CMP AL, 5
JNB label1
PRINT 'AL < 5.'
JMP exit
label1:
PRINT 'AL >= 5.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Below and Not Equal to second operand (as set
by CMP instruction). Unsigned.
JNBE
Algorithm:
label
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
label1:
PRINT 'AL > 5.'
exit:
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
unchanged
if CF = 0 then jump
Example:
JNC
label
ORG 100h
MOV AL, 2
ADD AL, 3
JNC label1
PRINT 'has carry.'
JMP exit
label1:
PRINT 'no carry.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Equal to second operand (as set by CMP
instruction). Signed/Unsigned.
Algorithm:
JNE
if ZF = 0 then jump
Example:
label
ORG 100h
MOV AL, 2
CMP AL, 3
JNE label1
PRINT 'AL = 3.'
JMP exit
label1:
PRINT 'Al <> 3.'
exit:
RET
C Z S O P A
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
unchanged
Short Jump if first operand is Not Greater then second operand (as set by CMP
instruction). Signed.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Algorithm:
if (ZF = 1) and (SF <> OF) then jump
Example:
JNG
label
ORG 100h
MOV AL, 2
CMP AL, 3
JNG label1
PRINT 'AL > 3.'
JMP exit
label1:
PRINT 'Al <= 3.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Greater and Not Equal to second operand (as set
by CMP instruction). Signed.
Algorithm:
JNGE
label
ORG 100h
MOV AL, 2
CMP AL, 3
JNGE label1
PRINT 'AL >= 3.'
JMP exit
label1:
PRINT 'Al < 3.'
exit:
RET
C Z S O P A
unchanged
JNL
label
Short Jump if first operand is Not Less then second operand (as set by CMP
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
instruction). Signed.
Algorithm:
if SF = OF then jump
Example:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, 2
CMP AL, -3
JNL label1
PRINT 'AL < -3.'
JMP exit
label1:
PRINT 'Al >= -3.'
exit:
RET
C Z S O P A
unchanged
Short Jump if first operand is Not Less and Not Equal to second operand (as set by
CMP instruction). Signed.
Algorithm:
label
JNLE
ORG 100h
MOV AL, 2
CMP AL, -3
JNLE label1
PRINT 'AL <= -3.'
JMP exit
label1:
PRINT 'Al > -3.'
exit:
RET
C Z S O P A
unchanged
label
Algorithm:
if OF = 0 then jump
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
; -5 - 2 = -7 (inside -128..127)
; the result of SUB is correct,
; so OF = 0:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, -5
SUB AL, 2 ; AL = 0F9h (-7)
JNO label1
PRINT 'overflow!'
JMP exit
label1:
PRINT 'no overflow.'
exit:
RET
C Z S O P A
unchanged
Short Jump if No Parity (odd). Only 8 low bits of result are checked. Set by CMP,
SUB, ADD, TEST, AND, OR, XOR instructions.
Algorithm:
if PF = 0 then jump
Example:
label
JNP
ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0
; just set flags.
JNP label1
PRINT 'parity even.'
JMP exit
label1:
PRINT 'parity odd.'
exit:
RET
C Z S O P A
unchanged
Short Jump if Not Signed (if positive). Set by CMP, SUB, ADD, TEST, AND, OR,
XOR instructions.
JNS
label
Algorithm:
if SF = 0 then jump
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0
; just set flags.
JNS label1
PRINT 'signed.'
JMP exit
label1:
PRINT 'not signed.'
exit:
RET
C Z S O P A
unchanged
Short Jump if Not Zero (not equal). Set by CMP, SUB, ADD, TEST, AND, OR,
XOR instructions.
Algorithm:
if ZF = 0 then jump
Example:
JNZ
label
ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0
; just set flags.
JNZ label1
PRINT 'zero.'
JMP exit
label1:
PRINT 'not zero.'
exit:
RET
C Z S O P A
unchanged
JO
label
if OF = 1 then jump
Example:
; -5 - 127 = -132 (not in -128..127)
; the result of SUB is wrong (124),
; so OF = 1 is set:
org 100h
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV AL, -5
SUB AL, 127 ; AL = 7Ch (124)
JO label1
PRINT 'no overflow.'
JMP exit
label1:
PRINT 'overflow!'
exit:
RET
C Z S O P A
unchanged
Short Jump if Parity (even). Only 8 low bits of result are checked. Set by CMP,
SUB, ADD, TEST, AND, OR, XOR instructions.
Algorithm:
if PF = 1 then jump
Example:
JP
label
ORG 100h
MOV AL, 00000101b ; AL = 5
OR AL, 0
; just set flags.
JP label1
PRINT 'parity odd.'
JMP exit
label1:
PRINT 'parity even.'
exit:
RET
C Z S O P A
unchanged
Short Jump if Parity Even. Only 8 low bits of result are checked. Set by CMP,
SUB, ADD, TEST, AND, OR, XOR instructions.
JPE
Algorithm:
label
if PF = 1 then jump
Example:
ORG 100h
MOV AL, 00000101b ; AL = 5
OR AL, 0
; just set flags.
JPE label1
PRINT 'parity odd.'
JMP exit
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
label1:
PRINT 'parity even.'
exit:
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
unchanged
Short Jump if Parity Odd. Only 8 low bits of result are checked. Set by CMP, SUB,
ADD, TEST, AND, OR, XOR instructions.
Algorithm:
if PF = 0 then jump
Example:
JPO
label
ORG 100h
MOV AL, 00000111b ; AL = 7
OR AL, 0
; just set flags.
JPO label1
PRINT 'parity even.'
JMP exit
label1:
PRINT 'parity odd.'
exit:
RET
C Z S O P A
unchanged
Short Jump if Signed (if negative). Set by CMP, SUB, ADD, TEST, AND, OR,
XOR instructions.
Algorithm:
JS
if SF = 1 then jump
Example:
label
ORG 100h
MOV AL, 10000000b ; AL = -128
OR AL, 0
; just set flags.
JS label1
PRINT 'not signed.'
JMP exit
label1:
PRINT 'signed.'
exit:
RET
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
C Z S O P A
unchanged
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Short Jump if Zero (equal). Set by CMP, SUB, ADD, TEST, AND, OR, XOR
instructions.
Algorithm:
if ZF = 1 then jump
Example:
JZ
label
ORG 100h
MOV AL, 5
CMP AL, 5
JZ label1
PRINT 'AL is not equal to 5.'
JMP exit
label1:
PRINT 'AL is equal to 5.'
exit:
RET
C Z S O P A
unchanged
LAHF
No operands
AH = flags register
AH bit: 7 6 5 4 3 2 1 0
[SF] [ZF] [0] [AF] [0] [PF] [1] [CF]
bits 1, 3, 5 are reserved.
C Z S O P A
unchanged
LDS
REG,
memory
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
ORG 100h
LDS AX, m
RET
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
m DW 1234h
DW 5678h
END
REG,
memory
LEA
Example:
MOV BX, 35h
MOV DI, 12h
LEA SI, [BX+DI] ; SI = 35h + 12h = 47h
Note: The integrated 8086 assembler automatically replaces LEA with a more
efficient MOV where possible. For example:
org 100h
LEA AX, m
; AX = offset of m
RET
m dw 1234h
END
C Z S O P A
unchanged
LES
REG,
memory
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
ORG 100h
LES AX, m
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RET
m DW 1234h
DW 5678h
END
AL = DS:[SI]
if DF = 0 then
o SI = SI + 1
else
SI = SI - 1
Example:
LODSB
No operands
ORG 100h
LEA SI, a1
MOV CX, 5
MOV AH, 0Eh
m: LODSB
INT 10h
LOOP m
RET
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
else
LODSW
No operands
SI = SI - 2
Example:
ORG 100h
LEA SI, a1
MOV CX, 5
unchanged
CX = CX - 1
if CX <> 0 then
o jump
else
LOOP
label
no jump, continue
Example:
ORG 100h
MOV CX, 5
label1:
PRINTN 'loop!'
LOOP label1
RET
C Z S O P A
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
unchanged
Decrease CX, jump to label if CX not zero and Equal (ZF = 1).
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Algorithm:
CX = CX - 1
if (CX <> 0) and (ZF = 1) then
o jump
else
LOOPE
label
no jump, continue
Example:
; Loop until result fits into AL alone,
; or 5 times. The result will be over 255
; on third loop (100+100+100),
; so loop will exit.
ORG 100h
MOV AX, 0
MOV CX, 5
label1:
PUTC '*'
ADD AX, 100
CMP AH, 0
LOOPE label1
RET
C Z S O P A
unchanged
Decrease CX, jump to label if CX not zero and Not Equal (ZF = 0).
Algorithm:
LOOPNE
label
CX = CX - 1
if (CX <> 0) and (ZF = 0) then
o jump
else
o
no jump, continue
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ORG 100h
MOV SI, 0
MOV CX, 5
label1:
PUTC '*'
MOV AL, v1[SI]
INC SI
; next byte (SI=SI+1).
CMP AL, 7
LOOPNE label1
RET
v1 db 9, 8, 7, 6, 5
C Z S O P A
unchanged
CX = CX - 1
if (CX <> 0) and (ZF = 0) then
o jump
else
LOOPNZ
label
no jump, continue
Example:
; Loop until '7' is found,
; or 5 times.
ORG 100h
MOV SI, 0
MOV CX, 5
label1:
PUTC '*'
MOV AL, v1[SI]
INC SI
; next byte (SI=SI+1).
CMP AL, 7
LOOPNZ label1
RET
v1 db 9, 8, 7, 6, 5
C Z S O P A
unchanged
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
else
LOOPZ
label
no jump, continue
Example:
; Loop until result fits into AL alone,
; or 5 times. The result will be over 255
; on third loop (100+100+100),
; so loop will exit.
ORG 100h
MOV AX, 0
MOV CX, 5
label1:
PUTC '*'
ADD AX, 100
CMP AH, 0
LOOPZ label1
RET
C Z S O P A
unchanged
MOV
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
SREG,
memory
memory,
SREG
REG, SREG
SREG, REG
Algorithm:
operand1 = operand2
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
ORG 100h
MOV AX, 0B800h ; set AX = B800h (VGA memory).
MOV DS, AX
; copy value of AX to DS.
MOV CL, 'A'
; CL = 41h (ASCII code).
MOV CH, 01011111b ; CL = color attribute.
MOV BX, 15Eh
; BX = position on screen.
MOV [BX], CX
; w.[0B800h:015Eh] = CX.
RET
; returns to operating system.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
C Z S O P A
unchanged
ES:[DI] = DS:[SI]
if DF = 0 then
o SI = SI + 1
o DI = DI + 1
else
o
o
MOVSB
No operands
SI = SI - 1
DI = DI - 1
Example:
ORG 100h
CLD
LEA SI, a1
LEA DI, a2
MOV CX, 5
REP MOVSB
RET
a1 DB 1,2,3,4,5
a2 DB 5 DUP(0)
C Z S O P A
unchanged
MOVSW
No operands
ES:[DI] = DS:[SI]
if DF = 0 then
o SI = SI + 2
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
DI = DI + 2
o
o
SI = SI - 2
DI = DI - 2
else
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Example:
ORG 100h
CLD
LEA SI, a1
LEA DI, a2
MOV CX, 5
REP MOVSW
RET
a1 DW 1,2,3,4,5
a2 DW 5 DUP(0)
C Z S O P A
unchanged
Unsigned multiply.
Algorithm:
REG
memory
Example:
MOV AL, 200 ; AL = 0C8h
MOV BL, 4
MUL BL
; AX = 0320h (800)
RET
C Z S O P A
MUL
r ? ? r ? ?
NEG
REG
memory
Algorithm:
Example:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
r r r r r r
No Operation.
Algorithm:
NOP
No operands
Do nothing
Example:
; do nothing, 3 times:
NOP
NOP
NOP
RET
C Z S O P A
unchanged
REG
memory
OR
if bit is 1 turn it to 0.
if bit is 0 turn it to 1.
Example:
MOV AL, 00011011b
NOT AL ; AL = 11100100b
RET
C Z S O P A
NOT
unchanged
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
Logical OR between all bits of two operands. Result is stored in first operand.
These rules apply:
1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
MOV AL, 'A'
; AL = 01000001b
OR AL, 00100000b ; AL = 01100001b ('a')
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0 r r 0 r ?
OUT
im.byte, AL
im.byte, AX
DX, AL
DX, AX
Example:
MOV AX, 0FFFh ; Turn on all
OUT 4, AX ; traffic lights.
unchanged
REG
SREG
memory
Example:
MOV AX, 1234h
PUSH AX
POP DX ; DX = 1234h
RET
C Z S O P A
POP
unchanged
Pop all general purpose registers DI, SI, BP, SP, BX, DX, CX, AX from the stack.
SP value is ignored, it is Popped but not set to SP register).
POPA
No operands
POP DI
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
POP SI
POP BP
POP xx (SP value ignored)
POP BX
POP DX
POP CX
POP AX
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
C Z S O P A
unchanged
POPF
No operands
C Z S O P A
popped
PUSH
REG
SREG
memory
immediate
SP = SP - 2
SS:[SP] (top of the stack) = operand
Example:
MOV AX, 1234h
PUSH AX
POP DX ; DX = 1234h
RET
C Z S O P A
unchanged
PUSHA
No operands
Push all general purpose registers AX, CX, DX, BX, SP, BP, SI, DI in the stack.
Original value of SP register (before PUSHA) is used.
Note: this instruction works only on 80186 CPU and later!
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Algorithm:
PUSH AX
PUSH CX
PUSH DX
PUSH BX
PUSH SP
PUSH BP
PUSH SI
PUSH DI
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
C Z S O P A
unchanged
PUSHF
No operands
SP = SP - 2
SS:[SP] (top of the stack) = flags
C Z S O P A
unchanged
Rotate operand1 left through Carry Flag. The number of rotates is set by operand2.
When immediate is greater then 1, assembler generates several RCL xx,
1instructions because 8086 has machine code only for this instruction (the same
principle works for all other shift/rotate instructions).
RCL
memory,
immediate
REG,
immediate
memory, CL
REG, CL
Algorithm:
shift all bits left, the bit that goes off is set to CF and previous value of CF
is inserted to the right-most position.
Example:
STC
; set carry (CF=1).
MOV AL, 1Ch
; AL = 00011100b
RCL AL, 1
; AL = 00111001b, CF=0.
RET
C O
r r
RCR
memory,
immediate
REG,
Rotate operand1 right through Carry Flag. The number of rotates is set by
operand2.
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
immediate
Algorithm:
memory, CL
REG, CL
shift all bits right, the bit that goes off is set to CF and previous value of
CF is inserted to the left-most position.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Example:
STC
; set carry (CF=1).
MOV AL, 1Ch
; AL = 00011100b
RCR AL, 1
; AL = 10001110b, CF=0.
RET
C O
r r
if CX <> 0 then
REP
chain
instruction
else
Z
r
REPE
chain
instruction
if CX <> 0 then
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
else
o
else
exit from REPE cycle
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Example:
see cmpsb.asm in c:\emu8086\examples\.
Z
r
if CX <> 0 then
REPNE
chain
instruction
else
Z
r
REPNZ
chain
instruction
Algorithm:
check_cx:
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
if CX <> 0 then
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
else
else
Z
r
if CX <> 0 then
REPZ
chain
instruction
else
Z
r
RET
No operands
or even
immediate
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Algorithm:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Example:
ORG 100h ; for COM file.
CALL p1
ADD AX, 1
RET
; return to OS.
RETF
No operands
or even
immediate
C Z S O P A
unchanged
ROL
Algorithm:
memory,
immediate
REG,
immediate
memory, CL
REG, CL
shift all bits left, the bit that goes off is set to CF and the same bit is
inserted to the right-most position.
Example:
MOV AL, 1Ch
; AL = 00011100b
ROL AL, 1
; AL = 00111000b, CF=0.
RET
C O
r r
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ROR
memory,
immediate
REG,
immediate
memory, CL
REG, CL
C O
r r
SAHF
No operands
flags register = AH
AH bit: 7 6 5 4 3 2 1 0
[SF] [ZF] [0] [AF] [0] [PF] [1] [CF]
bits 1, 3, 5 are reserved.
C Z S O P A
r r r r r r
SAL
memory,
immediate
REG,
immediate
memory, CL
REG, CL
Shift all bits left, the bit that goes off is set to CF.
Zero bit is inserted to the right-most position.
Example:
MOV AL, 0E0h
; AL = 11100000b
SAL AL, 1
; AL = 11000000b, CF=1.
RET
C O
r r
SAR
memory,
immediate
REG,
immediate
memory, CL
REG, CL
Shift all bits right, the bit that goes off is set to CF.
The sign bit that is inserted to the left-most position has the same value as
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
before shift.
Example:
MOV AL, 0E0h
; AL = 11100000b
SAR AL, 1
; AL = 11110000b, CF=0.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
C O
r r
SBB
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
C Z S O P A
r r r r r r
SCASB
No operands
ES:[DI] - AL
set flags according to result:
OF, SF, ZF, AF, PF, CF
if DF = 0 then
o DI = DI + 1
else
DI = DI - 1
C Z S O P A
r r r r r r
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ES:[DI] - AX
set flags according to result:
OF, SF, ZF, AF, PF, CF
if DF = 0 then
o DI = DI + 2
SCASW
No operands
else
DI = DI - 2
C Z S O P A
r r r r r r
SHL
memory,
immediate
REG,
immediate
memory, CL
REG, CL
Shift all bits left, the bit that goes off is set to CF.
Zero bit is inserted to the right-most position.
Example:
MOV AL, 11100000b
SHL AL, 1
; AL = 11000000b, CF=1.
RET
C O
r r
SHR
Algorithm:
memory,
immediate
REG,
immediate
memory, CL
REG, CL
Shift all bits right, the bit that goes off is set to CF.
Zero bit is inserted to the left-most position.
Example:
MOV AL, 00000111b
SHR AL, 1
; AL = 00000011b, CF=1.
RET
C O
r r
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
CF = 1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
STC
STD
No operands
DF = 1
D
STI
No operands
IF = 1
I
STOSB
Algorithm:
No operands
ES:[DI] = AL
if DF = 0 then
o DI = DI + 1
else
DI = DI - 1
Example:
ORG 100h
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
LEA DI, a1
MOV AL, 12h
MOV CX, 5
REP STOSB
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RET
a1 DB 5 dup(0)
C Z S O P A
unchanged
ES:[DI] = AX
if DF = 0 then
o DI = DI + 2
else
STOSW
No operands
DI = DI - 2
Example:
ORG 100h
LEA DI, a1
MOV AX, 1234h
MOV CX, 5
REP STOSW
RET
a1 DW 5 dup(0)
SUB
C Z S O P A
unchanged
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
Subtract.
Algorithm:
operand1 = operand1 - operand2
Example:
MOV AL, 5
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
immediate
SUB AL, 1
; AL = 4
RET
C Z S O P A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
r r r r r r
Logical AND between all bits of two operands for flags only. These flags are
effected: ZF, SF, PF. Result is not stored anywhere.
These rules apply:
TEST
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
Example:
MOV AL, 00000101b
TEST AL, 1
; ZF = 0.
TEST AL, 10b
; ZF = 1.
RET
C Z S O P
0 r r 0 r
XCHG
REG,
memory
memory,
REG
REG, REG
Example:
MOV AL, 5
MOV AH, 2
XCHG AL, AH ; AL = 2, AH = 5
XCHG AL, AH ; AL = 5, AH = 2
RET
C Z S O P A
unchanged
No operands
Algorithm:
AL = DS:[BX + unsigned AL]
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
ORG 100h
LEA BX, dat
MOV AL, 2
XLATB ; AL = 33h
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RET
dat DB 11h, 22h, 33h, 44h, 55h
C Z S O P A
unchanged
Logical XOR (Exclusive OR) between all bits of two operands. Result is stored in
first operand.
These rules apply:
XOR
REG,
memory
memory,
REG
REG, REG
memory,
immediate
REG,
immediate
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 1 = 1
0 XOR 0 = 0
Example:
MOV AL, 00000111b
XOR AL, 00000010b ; AL = 00000101b
RET
C Z S O P A
0 r r 0 r ?
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Variables
Variable is a memory location. For a programmer it is much easier to have some value be kept in a variable named
"var1" then at the address 5A73:235B, especially when you have 10 or more variables.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
name DW value
name - can be any letter or digit combination, though it should start with a letter. It's possible to declare unnamed
variables by not specifying the name (this variable will have an address but no name).
value - can be any numeric value in any supported numbering system (hexadecimal, binary, or decimal), or "?"
symbol for variables that are not initialized.
As you probably know from part 2 of this tutorial, MOV instruction is used to copy values from source to
destination.
Let's see another example with MOV instruction:
ORG 100h
VAR1 DB 7
var2 DW 1234h
Copy the above code to emu8086 source editor, and press F5 key to compile and load it in the emulator. You should
get something like:
As you see this looks a lot like our example, except that variables are replaced with actual memory locations. When
compiler makes machine code, it automatically replaces all variable names with their offsets. By default segment is
loaded in DS register (when COM files is loaded the value of DS register is set to the same value as CS register code segment).
In memory list first row is an offset, second row is a hexadecimal value, third row is decimal value, and last row is
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
You can see that there are some other instructions after the RET instruction, this happens because disassembler has
no idea about where the data starts, it just processes the values in memory and it understands them as valid 8086
instructions (we will learn them later).
You can even write the same program using DB directive only:
ORG 100h ; just a directive to make a simple .com file
(expands into no code).
DB 0A0h
DB 08h
DB 01h
DB 8Bh
DB 1Eh
DB 09h
DB 01h
DB 0C3h
DB 7
DB 34h
DB 12h
Copy the above code to emu8086 source editor, and press F5 key to compile and load it in the emulator. You should
get the same disassembled code, and the same functionality!
As you may guess, the compiler just converts the program source to the set of bytes, this set is called machine code,
processor understands the machine code and executes it.
ORG 100h is a compiler directive (it tells compiler how to handle the source code). This directive is very important
when you work with variables. It tells compiler that the executable file will be loaded at the offset of 100h (256
bytes), so compiler should calculate the correct address for all variables when it replaces the variable names with
their offsets. Directives are never converted to any real machine code.
Why executable file is loaded at offset of 100h? Operating system keeps some data about the program in the first
256 bytes of the CS (code segment), such as command line parameters and etc.
Though this is true for COM files only, EXE files are loaded at offset of 0000, and generally use special segment
for variables. Maybe we'll talk more about EXE files later.
Arrays
Arrays can be seen as chains of variables. A text string is an example of a byte array, each character is presented as
an ASCII code value (0..255).
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
b is an exact copy of the a array, when compiler sees a string inside quotes it automatically converts it to set of
bytes. This chart shows a part of the memory where these arrays are declared:
You can access the value of any element in array using square brackets, for example:
MOV AL, a[3]
You can also use any of the memory index registers BX, SI, DI, BP, for example:
MOV SI, 3
MOV AL, a[SI]
If you need to declare a large array you can use DUP operator.
The syntax for DUP:
Of course, you can use DW instead of DB if it's required to keep values larger then 255, or smaller then 128. DW cannot be used to declare strings.
There is LEA (Load Effective Address) instruction and alternative OFFSET operator. Both OFFSETand LEA can
be used to get the offset address of the variable.
LEA is more powerful because it also allows you to get the address of an indexed variables. Getting the address of
the variable can be very useful in some situations, for example when you need to pass parameters to a procedure.
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Reminder:
In order to tell the compiler about data type,
these prefixes should be used:
BYTE PTR - for byte.
WORD PTR - for word (two bytes).
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
For example:
BYTE PTR [BX] ; byte access.
or
WORD PTR [BX] ; word access.
emu8086 supports shorter prefixes as well:
in certain cases the assembler can calculate the data type automatically.
BX, VAR1
RET
VAR1 DB 22h
END
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
VAR1 DB 22h
END
These lines:
LEA BX, VAR1
MOV BX, OFFSET VAR1
are even compiled into the same machine code: MOV BX, num
num is a 16 bit value of the variable offset.
Please note that only these registers can be used inside square brackets (as memory pointers):BX, SI, DI, BP!
(see previous part of the tutorial).
Constants
Constants are just like variables, but they exist only until your program is compiled (assembled). After definition of
a constant its value cannot be changed. To define constants EQU directive is used:
name EQU < any expression >
For example:
k EQU 5
MOV AX, k
You can view variables while your program executes by selecting "Variables" from the "View" menu of emulator.
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
To view arrays you should click on a variable and set Elements property to array size. In assembly language there
are not strict data types, so any variable can be presented as an array.
Variable can be viewed in any numbering system:
HEX - hexadecimal (base 16).
BIN - binary (base 2).
OCT - octal (base 8).
SIGNED - signed decimal (base 10).
UNSIGNED - unsigned decimal (base 10).
CHAR - ASCII char code (there are 256 symbols, some symbols are invisible).
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
You can edit a variable's value when your program is running, simply double click it, or select it and
click Edit button.
It is possible to enter numbers in any system, hexadecimal numbers should have "h" suffix, binary "b" suffix, octal
"o" suffix, decimal numbers require no suffix. String can be entered this way:
'hello world', 0
(this string is zero terminated).
Arrays may be entered this way:
1, 2, 3, 4, 5
(the array can be array of bytes or words, it depends whether BYTE or WORD is selected for edited variable).
G.Vijaya Santhi,Asst.Prof.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
a) Ascii addition:
Simple Programs
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num1 dw 0039h
num2 db 35h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov bl,num2
add ax,bl
aaa
add ax,3030h
mov result,ax
hlt
code ends
end start
b) Ascii Subtraction:
data segment
num1 dw 0039h
num2 db 35h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov bl,num2
sub ax,bl
aas
add ax,3030h
mov result,ax
hlt
code ends
end start
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
c) Ascii Multiplication:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num1 dw 3436h
num2 db 37h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov bl,num2
and ax,0f0fh
and bl,0fh
div bl
aad
add ax,3030h
mov result,ax
hlt
code ends
end start
d) Ascii Division:
data segment
num1 dw 3436h
num2 db 37h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov bl,num2
and ax,0f0fh
and bl,0fh
aad
div bl
add ax,3030h
mov result,ax
hlt
code ends
end start
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num1 dw 1234h
num2 dw 4321h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
add ax,bx
mov result,ax
hlt
code ends
end start
result: Location
0000h
0001h
0002h
0003h
0004h
0005h
data
34h
12h
21h
43h
55h
55h
b) Subtraction:
data segment
num1 dw 4321h
num2 dw 1111h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov bx,num2
sub ax,bx
mov result,ax
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
hlt
code ends
end start
result: Location
21h
43h
11h
11h
10h
32h
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0000h
0001h
0002h
0003h
0004h
0005h
data
c) Multiplication:
data segment
num1 dw 1111h
num2 dw 1111h
result dw 04 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov dx,num2
mul bx
mov result,ax
mov result+2,dx
hlt
code ends
end start
result: Location
0000h
0001h
0002h
0003h
0004h
0005h
0006h
0007h
data
11h
11h
11h
11h
10h
32h
34h
12h
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
d) Division:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num1 dw 3210h
num2 dw 1234h
num3 dw 1111h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:mov ax,data
mov ds,ax
mov ax,num1
mov dx,num2
mov bx,num3
div bx
mov result,ax
mov result+2,dx
hlt
code ends
end start
result: Location
0000h
0001h
0002h
0003h
0004h
0005h
0006h
0007h
0008h
0009h
data
10h
32h
34h
12h
11h
11h
11h
11h
00h
00h
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
a) Ascending Order
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num db 09h,06h,07h
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov dl,02h
step3:mov cl,dl
mov si,offset num
step2:mov al,[si]
cmp al,[si+1]
ja step1
xchg al,[si+1]
mov [si],al
step1:inc si
dec cl
jnz step2
dec dl
jnz step3
hlt
code ends
end start
result: Location
Input: 0000h
0001h
0002h
Output 0000h
0001h
0002h
data
09h
06h
07h
06h
07h
09h
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
b) Descending order:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num db 09h,06h,07h
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov dl,02h
step3:mov cl,dl
mov si,offset num
step2:mov al,[si]
cmp al,[si+1]
jb step1
xchg al,[si+1]
mov [si],al
step1:inc si
dec cl
jnz step2
dec dl
jnz step3
hlt
code ends
end start
data
Input :0000h
0001h
0002h
Output:0000h
0001h
0002h
06h
07h
09h
09h
06h
07h
result: Location
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num db 32h,30h,29h,25h
num2 db 04 dup(0)
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov es,ax
mov si,offset num
mov di,offset num2
mov cl,04h
rep movsb
hlt
code ends
end start
result: Location
data
Input: 0000h
0001h
0002h
0003h
Output 0004h
0005h
0006h
0007h
32h
30h
29h
25h
32h
30h
29h
25h
b) Block Transfer:
data segment
num db 32h,30h,29h,25h
num2 db 04 dup(0)
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
mov es,ax
mov si,offset num
mov di,offset num2
mov bx,0004h
step:
dec bx
lodsb
mov [bx][di],al
jnz step
hlt
code ends
end start
result: Location
data
Input: 0000h
0001h
0002h
0003h
Output 0004h
0005h
0006h
0007h
32h
30h
29h
25h
25h
29h
30h
32h
c) Insertion of a string:
data segment
num1 db 32h,30h,29h,25h
num2 db 26h,31h
place dw 0001h
length1 db 04h
length2 db 02h
result db 07 dup(0)
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov es,ax
mov si,offset num1
mov bx,offset num2
mov di,offset result
mov cl,length1
mov ch,length2
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
back:
cmp si,place
je li
here:
lodsb
stosb
dec cl
jnz back
hlt
li:
mov al,[bx]
mov [di],al
inc di
inc bx
dec ch
jnz li
jmp here
code ends
end start
data
Input: 0000h
0001h
0002h
0003h
0004h
0005h
0006h
0007h
0008h
0009h
Output:000Ah
000Bh
000Ch
000Dh
000Eh
000Fh
32h
30h
29h
25h
26h
31h
01h
00h
04h
02h
32h
30h
26h
31h
29h
25h
result: Location
d) Deletion of a string:
data segment
giv db 32h,30h,29h,25h
place dw 0000h
lgiv dw 0004h
ldel dw 0002h
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
result db 06 dup(0)
data ends
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov es,ax
mov si,offset giv
mov di,offset result
mov cx,0000h
back:
cmp si,place
je li
lodsb
stosb
inc cx
here:
cmp cx,lgiv
jb back
hlt
li:
add cx,ldel
add si,ldel
jmp here
code ends
end start
data
Input: 0000h
0001h
0002h
0003h
0004h
0005h
0006h
0007h
0008h
0009h
Output:000Ah
000Bh
32h
30h
29h
25h
00h
00h
04h
00h
02h
00h
29h
25h
result: Location
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Programs on Conversions
a)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data segment
num1 db 32h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov al,num1
mov bl,num1
mov cl,04h
and al,0f0h
and bl,0fh
shr al,cl
mov ch,0ah
mul ch
add al,bl
mov result,al
hlt
code ends
end start
b)
data segment
num1 db 22h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov al,num1
mov ah,00h
mov bl,0ah
div bl
xchg al,ah
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
add ax,3030h
mov result,ax
hlt
code ends
end start
Packed to unpacked BCD:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
c)
data segment
num1 db 32h
result dw 01 dup(0)
data ends
code segment
assume ds:data,cs:code
start:
mov ax,data
mov ds,ax
mov al,num1
mov bl,num1
and al,0fh
and bl,0f0h
mov cl,04h
shr bl,cl
mov ah,bl
add ax,3030h
mov result,ax
hlt
code ends
end start
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The Microprocessor 8086 is a 16-bit CPU available in different clock rates and packaged
in a 40 pin CERDIP or plastic package.
The 8086 operates in single processor or multiprocessor configuration to achieve high
performance. The pins serve a particular function in minimum mode (single processor
mode ) and other function in maximum mode configuration (multiprocessor mode ).
The 8086 signals can be categorised in three groups. The first are the signal having
common functions in minimum as well as maximum mode.
The second are the signals which have special functions for minimum mode and third
are the signals having special functions for maximum mode.
The following signal descriptions are common for both modes.
AD15-AD0 : These are the time multiplexed memory I/O address and data lines.
Address remains on the lines during T1 state, while the data is available on the data bus
during T2, T3, Tw and T4.
These lines are active high and float to a tristate during interrupt acknowledge and local
bus hold acknowledge cycles.
A19/S6,A18/S5,A17/S4,A16/S3 : These are the time multiplexed address and status lines.
During T1 these are the most significant address lines for memory operations.
During I/O operations, these lines are low. During memory or I/O operations, status
information is available on those lines for T2,T3,Tw and T4.
The status of the interrupt enable flag bit is updated at the beginning of each clock
cycle.
The S4 and S3 combinedly indicate which segment register is presently being used for
memory accesses as in below fig.
These lines float to tri-state off during the local bus hold acknowledge. The status line S6
is always low .
The address bit are separated from the status bit using latches controlled by the ALE
signal.
S4
S3
0
0
1
1
0
1
0
1
Indication
Alternate Data
Stack
Code or none
Data
G.Vijaya Santhi,Asst.prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
BHE/S7 : The bus high enable is used to indicate the transfer of data over the higher
order ( D15-D8 ) data bus as shown in table. It goes low for the data transfer over D15-D8
and is used to derive chip selects of odd address memory bank or peripherals. BHE is low
during T1 for read, write and interrupt acknowledge cycles, whenever a byte is to be
transferred on higher byte of data bus. The status information is available during T2, T3
and T4. The signal is active low and tristated during hold. It is low during T1 for the first
pulse of the interrupt acknowledge cycle.
0
0
1
0
1
0
Whole word
Upper byte from or to even
address
odd address
Lower byte from or to even address
RD Read : This signal on low indicates the peripheral that the processor is performing
s memory or I/O read operation. RD is active low and shows the state for T2, T3, Tw of
any read cycle. The signal remains tristated during the hold acknowledge.
READY : This is the acknowledgement from the slow device or memory that they have
completed the data transfer. The signal made available by the devices is synchronized by
the 8284A clock generator to provide ready input to the 8086. the signal is active high.
INTR-Interrupt Request : This is a triggered input. This is sampled during the last
clock cycles of each instruction to determine the availability of the request. If any
interrupt request is pending, the processor enters the interrupt acknowledge cycle.
This can be internally masked by resulting the interrupt enable flag. This signal is active
high and internally synchronized.
TEST : This input is examined by a WAIT instruction. If the TEST pin goes low,
execution will continue, else the processor remains in an idle state. The input is
synchronized internally during each clock cycle on leading edge of clock.
CLK- Clock Input : The clock input provides the basic timing for processor operation
and bus control activity. Its an asymmetric square wave with 33% duty cycle.
MN/MX : The logic level at this pin decides whether the processor is to operate in either
minimum or maximum mode.
The following pin functions are for the minimum mode operation of 8086.
G.Vijaya Santhi,Asst.prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
the previous T4 and remains active till final T4 of the current cycle. It is tristated during
local bus hold acknowledge .
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INTA Interrupt Acknowledge : This signal is used as a read strobe for interrupt
acknowledge cycles. i.e. when it goes low, the processor has accepted the interrupt.
ALE Address Latch Enable : This output signal indicates the availability of the valid
address on the address/data lines, and is connected to latch enable input of latches. This
signal is active high and is never tristated.
DT/R Data Transmit/Receive: This output is used to decide the direction of data flow
through the transreceivers (bidirectional buffers). When the processor sends out data, this
signal is high and when the processor is receiving data, this signal is low.
DEN Data Enable : This signal indicates the availability of valid data over the
address/data lines. It is used to enable the transreceivers ( bidirectional buffers ) to
separate the data from the multiplexed address/data signal. It is active from the middle of
T2 until the middle of T4. This is tristated during hold acknowledge cycle.
HOLD, HLDA- Acknowledge : When the HOLD line goes high, it indicates to the
processor that another master is requesting the bus access.
The processor, after receiving the HOLD request, issues the hold acknowledge signal on
HLDA pin, in the middle of the next clock cycle after completing the current bus cycle.
At the same time, the processor floats the local bus and control lines. When the
processor detects the HOLD line low, it lowers the HLDA signal. HOLD is an
asynchronous input, and is should be externally synchronized.
If the DMA request is made while the CPU is performing a memory or I/O cycle, it will
release the local bus during T4 provided :
1.The request occurs on or before T2 state of the current cycle.
2.The current cycle is not operating over the lower byte of a word.
3.The current cycle is not the first acknowledge of an interrupt acknowledge sequence.
4. A Lock instruction is not being executed.
The following pin function are applicable for maximum mode operation of 8086.
S2, S1, S0 Status Lines : These are the status lines which reflect the type of operation,
being carried out by the processor. These become activity during T4 of the previous cycle
and active during T1 and T2 of the current bus cycles.
G.Vijaya Santhi,Asst.prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
S1
0
0
1
1
0
0
1
1
S0
0
1
0
1
0
1
0
1
Indication
Interrupt Acknowledge
Read I/O port
Write I/O port
Halt
Code Access
Read memory
Write memory
Passive
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
S2
0
0
0
0
1
1
1
1
LOCK : This output pin indicates that other system bus master will be prevented from
gaining the system bus, while the LOCK signal is low.
The LOCK signal is activated by the LOCK prefix instruction and remains active until
the completion of the next instruction. When the CPU is executing a critical instruction
which requires the system bus, the LOCK prefix instruction ensures that other processors
connected in the system will not gain the control of the bus.
The 8086, while executing the prefixed instruction, asserts the bus lock signal output,
which may be connected to an external bus controller.
G.Vijaya Santhi,Asst.prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
The fetch operation of the next instruction is overlapped with the execution of the
current instruction. As in the architecture, there are two separate units, namely Execution
unit and Bus interface unit.
While the execution unit is busy in executing an instruction, after it is completely
decoded, the bus interface unit may be fetching the bytes of the next instruction from
memory, depending upon the queue status.
QS0
Indication
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
QS1
0
0
1
1
0
1
0
1
No operation
First byte of the opcode from the queue
Empty queue
Subsequent byte from the queue
RQ/GT0, RQ/GT1 Request/Grant : These pins are used by the other local bus master
in maximum mode, to force the processor to release the local bus at the end of the
processor current bus cycle.
Each of the pin is bidirectional with RQ/GT0 having higher priority than RQ/GT1.
RQ/GT pins have internal pull-up resistors and may be left unconnected.
Request/Grant sequence is as follows:
1.A pulse of one clock wide from another bus master requests the bus access to 8086.
2.During T4(current) or T1(next) clock cycle, a pulse one clock wide from 8086 to the
requesting master, indicates that the 8086 has allowed the local bus to float and that it
will enter the hold acknowledge state at next cycle. The CPU bus interface unit is likely
to be disconnected from the local bus of the system.
3.A one clock wide pulse from the another master indicates to the 8086 that the hold
request is about to end and the 8086 may regain control of the local bus at the next clock
cycle. Thus each master to master exchange of the local bus is a sequence of 3 pulses.
There must be at least one dead clock cycle after each bus exchange.
The request and grant pulses are active low.
For the bus request those are received while 8086 is performing memory or I/O cycle,
the granting of the bus is governed by the rules as in case of HOLD and HLDA in
minimum mode.
The 8086 has a combined address and data bus commonly referred as a time multiplexed
address and data bus.
G.Vijaya Santhi,Asst.prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The remaining components in the system are latches, transreceivers, clock generator,
memory and I/O devices. Some type of chip selection logic may be required for selecting
memory or I/O devices, depending upon the address map of the system.
Latches are generally buffered output D-type flip-flops like 74LS373 or 8282. They are
used for separating the valid address from the multiplexed address/data signals and are
controlled by the ALE signal generated by 8086.
Transreceivers are the bidirectional buffers and some times they are called as data
amplifiers. They are required to separate the valid data from the time multiplexed
address/data signals.
They are controlled by two signals namely, DEN and DT/R.
The DEN signal indicates the direction of data, i.e. from or to the processor. The system
contains memory for the monitor and users program storage.
Usually, EPROM are used for monitor storage, while RAM for users program storage. A
system may contain I/O devices.
The working of the minimum mode configuration system can be better described in
terms of the timing diagrams rather than qualitatively describing the operations.
The opcode fetch and read cycles are similar. Hence the timing diagram can be
categorized in two parts, the first is the timing diagram for read cycle and the second is
the timing diagram for write cycle.
The read cycle begins in T1 with the assertion of address latch enable (ALE) signal and
also M / IO signal. During the negative going edge of this signal, the valid address is
latched on the local bus.
The BHE and A0 signals address low, high or both bytes. From T1 to T4 , the M/IO
signal indicates a memory or I/O operation.
At T2, the address is removed from the local bus and is sent to the output. The bus is
then tristated. The read (RD) control signal is also activated in T2.
The read (RD) signal causes the address device to enable its data bus drivers. After RD
goes low, the valid data is available on the data bus.
The addressed device will drive the READY line high. When the processor returns the
read signal to high level, the addressed device will again tristate its bus drivers.
A write cycle also begins with the assertion of ALE and the emission of the address. The
M/IO signal is again asserted to indicate a memory or I/O operation. In T2, after sending
the address in T1, the processor sends the data to be written to the addressed location.
The data remains on the bus until middle of T4 state. The WR becomes active at the
beginning of T2 (unlike RD is somewhat delayed in T2 to provide time for floating).
The BHE and A0 signals are used to select the proper byte or bytes of memory or I/O
word to be read or write.
The M/IO, RD and WR signals indicate the type of data transfer as specified in table
below.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
T1
T2
T3
TW
T4
T1
Clk
ALE
BHE
A19 A16
S7 S3
ADD / DATA
A15 A0
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ADD / STATUS
WR
DEN
DT / R
Hold Response sequence: The HOLD pin is checked at leading edge of each clock
pulse. If it is received active by the processor before T4 of the previous cycle or during T1
state of the current cycle, the CPU activates HLDA in the next clock cycle and for
succeeding bus cycles, the bus will be given to another requesting master.
The control of the bus is not regained by the processor until the requesting master does
not drop the HOLD pin low. When the request is dropped by the requesting master, the
HLDA is dropped by the processor at the trailing edge of the next clock.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Clk
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
HOLD
HLDA
In the maximum mode, the 8086 is operated by strapping the MN/MX pin to ground.
In this mode, the processor derives the status signal S2, S1, S0. Another chip called bus
controller derives the control signal using this status information .
In the maximum mode, there may be more than one microprocessor in the system
configuration.
The components in the system are same as in the minimum mode system.
The basic function of the bus controller chip IC8288, is to derive control signals like RD
and WR ( for memory and I/O devices), DEN, DT/R, ALE etc. using the information by
the processor on the status lines.
The bus controller chip has input lines S2, S1, S0 and CLK. These inputs to 8288 are
driven by CPU.
It derives the outputs ALE, DEN, DT/R, MRDC, MWTC, AMWC, IORC, IOWC and
AIOWC. The AEN, IOB and CEN pins are specially useful for multiprocessor systems.
AEN and IOB are generally grounded. CEN pin is usually tied to +5V. The significance
of the MCE/PDEN output depends upon the status of the IOB pin.
If IOB is grounded, it acts as master cascade enable to control cascade 8259A, else it
acts as peripheral data enable used in the multiple bus configurations.
INTA pin used to issue two interrupt acknowledge pulses to the interrupt controller or to
an interrupting device.
IORC, IOWC are I/O read command and I/O write command signals respectively .
These signals enable an IO interface to read or write the data from or to the address port.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The MRDC, MWTC are memory read command and memory write command signals
respectively and may be used as memory read or write signals.
All these command signals instructs the memory to accept or send data from or to the
bus.
For both of these write command signals, the advanced signals namely AIOWC and
AMWTC are available.
Here the only difference between in timing diagram between minimum mode and
maximum mode is the status signals used and the available control and advanced
command signals.
DEN
DT/ R
S1
IORC
8288
IOWT
S2
MWTC
AEN
IOB
CEN AL MRDC
Clk
S0
Reset
Clk
Generator
RDY 8284
S0
S1
S2
Reset
Clk
Ready
+ 5V
8086
AD6-AD15
A16-A19
CLK
A/D
Latches
DT/R
DEN
Control bus
DIR
Data
buffer
Address bus
BHE A0
A
dd
bu
CS0H CS0L RD
WR
Memory
CS WR RD
Peripheral
Data bus
R0, S1, S2 are set at the beginning of bus cycle.8288 bus controller will output a pulse as
on the ALE and apply a required signal to its DT / R pin during T1.
In T2, 8288 will set DEN=1 thus enabling transceivers, and for an input it will activate
MRDC or IORC. These signals are activated until T4. For an output, the AMWC or
AIOWC is activated from T2 to T4 and MWTC or IOWC is activated from T3 to T4.
The status bit S0 to S2 remains active until T3 and become passive during T3 and T4.
If reader input is not activated before T3, wait state will be inserted between T3 and T4.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
T1
T2
T1
Clk
ALE
S2 S0
Add/Status
Add/Data
Inactive
Active
A15 A0
Active
S7 S3
D15 D0
MRDC
DT / R
DEN
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
T1
T2
T1
Clk
ALE
S2 S0
Active
ADD/STATUS
BHE
ADD/DATA
A15-A0
Inactive
Active
S7 S3
AMWC or AIOWC
MWTC or IOWC
DT / R
high
DEN
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Clk
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RQ / GT
Another master
request bus access
Master releases
When the Minimum mode operation is selected, the 8086 provides all control signals
needed to implement the memory and I/O interface.
The minimum mode signal can be divided into the following basic groups : address/data
bus, status, control, interrupt and DMA.
Address/Data Bus : these lines serve two functions. As an address bus is 20 bits long
and consists of signal lines A0 through A19. A19 represents the MSB and A0 LSB. A 20bit
address gives the 8086 a 1Mbyte memory address space. More over it has an independent
I/O address space which is 64K bytes in length.
The 16 data bus lines D0 through D15 are actually multiplexed with address lines A0
through A15 respectively. By multiplexed we mean that the bus work as an address bus
during first machine cycle and as a data bus during next machine cycles. D15 is the MSB
and D0 LSB.
When acting as a data bus, they carry read/write data for memory, input/output data for
I/O devices, and interrupt type codes from an interrupt controller.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Vcc
GND
INTR
A0-A15,A16/S3 A19/S6
INTA
Interrupt
interface
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D0 D15
NMI
8086
MPU
RESET
ALE
BHE / S7
M / IO
HOLD
DMA
interface
Memory I/O
controls
DT / R
RD
HLDA
WR
Vcc
DEN
Mode select
READY
MN / MX
CLK clock
Status signal:
The four most significant address lines A19 through A16 are also multiplexed but in this
case with status signals S6 through S3. These status bits are output on the bus at the same
time that data are transferred over the other bus lines.
Bit S4 and S3 together from a 2 bit binary code that identifies which of the 8086 internal
segment registers are used to generate the physical address that was output on the address
bus during the current bus cycle.
Code S4S3 = 00 identifies a register known as extra segment register as the source of the
segment address.
Status line S5 reflects the status of another internal characteristic of the 8086. It is the
logic level of the internal enable flag. The last status bit S6 is always at the logic 0 level.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
S3
Segment Register
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
S4
Extra
Stack
Code / none
Data
Control Signals :
The control signals are provided to support the 8086 memory I/O interfaces. They
control functions such as when the bus is to carry a valid address in which direction data
are to be transferred over the bus, when valid write data are on the bus and when to put
read data on the system bus.
ALE is a pulse to logic 1 that signals external circuitry when a valid address word is on
the bus. This address must be latched in external circuitry on the 1-to-0 edge of the pulse
at ALE.
Another control signal that is produced during the bus cycle is BHE bank high enable.
Logic 0 on this used as a memory enable signal for the most significant byte half of the
data bus D8 through D1. These lines also serves a second function, which is as the S7
status line.
Using the M/IO and DT/R lines, the 8086 signals which type of bus cycle is in progress
and in which direction data are to be transferred over the bus.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The logic level of M/IO tells external circuitry whether a memory or I/O transfer is
taking place over the bus. Logic 1 at this output signals a memory operation and logic 0
an I/O operation.
The direction of data transfer over the bus is signaled by the logic level output at DT/R.
When this line is logic 1 during the data transfer part of a bus cycle, the bus is in the
transmit mode. Therefore, data are either written into memory or output to an I/O device.
On the other hand, logic 0 at DT/R signals that the bus is in the receive mode. This
corresponds to reading data from memory or input of data from an input port.
The signal read RD and write WR indicates that a read bus cycle or a write bus cycle is
in progress. The 8086 switches WR to logic 0 to signal external device that valid write or
output data are on the bus.
On the other hand, RD indicates that the 8086 is performing a read of data of the bus.
During read operations, one other control signal is also supplied. This is DEN ( data
enable) and it signals external devices when they should put data on the bus.
There is one other control signal that is involved with the memory and I/O interface.
This is the READY signal.
READY signal is used to insert wait states into the bus cycle such that it is extended by
a number of clock periods. This signal is provided by an external clock generator device
and can be supplied by the memory or I/O sub-system to signal the 8086 when they are
ready to permit the data transfer to be completed.
Interrupt signals : The key interrupt interface signals are interrupt request (INTR) and
interrupt acknowledge ( INTA).
INTR is an input to the 8086 that can be used by an external device to signal that it need
to be serviced.
Logic 1 at INTR represents an active interrupt request. When an interrupt request has
been recognized by the 8086, it indicates this fact to external circuit with pulse to logic 0
at the INTA output.
The TEST input is also related to the external interrupt interface. Execution of a WAIT
instruction causes the 8086 to check the logic level at the TEST input.
If the logic 1 is found, the MPU suspend operation and goes into the idle state. The 8086
no longer executes instructions, instead it repeatedly checks the logic level of the TEST
input waiting for its transition back to logic 0.
As TEST switches to 0, execution resume with the next instruction in the program. This
feature can be used to synchronize the operation of the 8086 to an event in external
hardware.
There are two more inputs in the interrupt interface: the nonmaskable interrupt NMI and
the reset interrupt RESET.
On the 0-to-1 transition of NMI control is passed to a nonmaskable interrupt service
routine. The RESET input is used to provide a hardware reset for the 8086. Switching
RESET to logic 0 initializes the internal register of the 8086 and initiates a reset service
routine.
DMA Interface signals :The direct memory access DMA interface of the 8086
minimum mode consist of the HOLD and HLDA signals.
When an external device wants to take control of the system bus, it signals to the 8086
by switching HOLD to the logic 1 level. At the completion of the current bus cycle, the
8086 enters the hold state. In the hold state, signal lines AD0 through AD15, A16/S3
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
through A19/S6, BHE, M/IO, DT/R, RD, WR, DEN and INTR are all in the high Z state.
The 8086 signals external device that it is in this state by switching its HLDA output to
logic 1 level.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
When the 8086 is set for the maximum-mode configuration, it provides signals for
implementing a multiprocessor / coprocessor system environment.
By multiprocessor environment we mean that one microprocessor exists in the system
and that each processor is executing its own program.
Usually in this type of system environment, there are some system resources that are
common to all processors.
They are called as global resources. There are also other resources that are assigned to
specific processors. These are known as local or private resources.
Coprocessor also means that there is a second processor in the system. In this two
processor does not access the bus at the same time.
One passes the control of the system bus to the other and then may suspend its operation.
In the maximum-mode 8086 system, facilities are provided for implementing allocation
of global resources and passing bus control to other microprocessor or coprocessor.
INIT
S0
S1
S2
LOCK
CLK
INTR
TEST
NMI
CRQLCK
RESB
SYSB/RESB
ANYREQ
AEN
Vcc GND
LOCK
CLK
S0
S2
RESET
8289
Bus
MN/MX
BPRN
BCLK
IOB
DEN
DT/ R
ALE
8086 MPU
Multi Bus
BREQ
S1
BUSY
CBRQ
BPRO
MRDC
AMWC
MWTC
IORC
IOWC
AIOWC
INTA
MCE / PDEN
DEN
DT / R
ALE
A0-A15,
A16/S3-A19/S6
D0 D15
BHE
RD
READY
QS1, QS0
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Status Inputs
CPU Cycles
S2
S1
S0
0
0
0
0
0
0
1
1
0
1
0
1
Interrupt Acknowledge
Instruction Fetch
Read Memory
1
1
Write Memory
Passive
8288
Command
INTA
IORC
IOWC, AIOWC
None
MRDC
MRDC
MWTC, AMWC
None
The 8288 produces one or two of these eight command signals for each bus cycles. For
instance, when the 8086 outputs the code S2S1S0 equals 001, it indicates that an I/O read
cycle is to be performed.
In the code 111 is output by the 8086, it is signaling that no bus activity is to take place.
The control outputs produced by the 8288 are DEN, DT/R and ALE. These 3 signals
provide the same functions as those described for the minimum system mode. This set of
bus commands and control signals is compatible with the Multibus and industry standard
for interfacing microprocessor systems.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
QS1
QS0
Queue Status
0 (low)
First Byte. The byte taken from the queue was the first byte
of the instruction.
1 (high)
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
- The 20-bit
( 5 Hex digit)
physical address
supplied by the
addressbus (A0-A19) is
used to select the
memory location
required to be
accessed via
data-bus (D0-D7)
Physical
addressH
00000
Memory
spaces
3
4
00001 H
5 AH
00002 H
Address
Bus
A0 A19
.
.
.
.
.
FFFFE H
FFFFF H
1-MByte
bytewide
Main
memory
storage in
8088
system
D0 - D7
Data
Bus
8 CH
A 6H
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
- The 8086 systems have two 0.5 Mega X 8 bit memory banks
Inverter
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
- These signals disable the Low bank and enable the High bank
to transfer (in/out) data through D8 to D15 of the data-bus.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
- Note that during this bus-cycle, all 16-bit data is transferred via
D0 to D15 of the data bus.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Direct Memory Access (DMA) is a method of allowing data to be moved from one location to
another in a computer without intervention from the central processor (CPU).
The way that the DMA function is implemented varies between computer architectures, so this
discussion will limit itself to the implementation and workings of the DMA subsystem on the
IBM Personal Computer (PC), the IBM PC/AT and all of its successors and clones.
The PC DMA subsystem is based on the Intel 8237 DMA controller. The 8237 contains four
DMA channels that can be programmed independently and any one of the channels may be
active at any moment. These channels are numbered 0, 1, 2 and 3. Starting with the PC/AT, IBM
added a second 8237 chip, and numbered those channels 4, 5, 6 and 7.
The original DMA controller (0, 1, 2 and 3) moves one byte in each transfer. The second DMA
controller (4, 5, 6, and 7) moves 16-bits from two adjacent memory locations in each transfer,
with the first byte always coming from an even-numbered address. The two controllers are
identical components and the difference in transfer size is caused by the way the second
controller is wired into the system.
The 8237 has two electrical signals for each channel, named DRQ and -DACK. There are
additional signals with the names HRQ (Hold Request), HLDA (Hold Acknowledge), -EOP (End
of Process), and the bus control signals -MEMR (Memory Read), -MEMW (Memory Write), IOR (I/O Read), and -IOW (I/O Write).
The 8237 DMA is known as a fly-by DMA controller. This means that the data being moved
from one location to another does not pass through the DMA chip and is not stored in the DMA
chip. Subsequently, the DMA can only transfer data between an I/O port and a memory address,
but not between two I/O ports or two memory locations.
Note: The 8237 does allow two channels to be connected together to allow memory-to-memory
DMA operations in a non-fly-by mode, but nobody in the PC industry uses this scarce resource
this way since it is faster to move data between memory locations using the CPU.
In the PC architecture, each DMA channel is normally activated only when the hardware that
uses a given DMA channel requests a transfer by asserting the DRQ line for that channel.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
it in memory at location 0x00123456. The process begins by the FDC asserting the DRQ2 signal
(the DRQ line for DMA channel 2) to alert the DMA controller.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The DMA controller will note that the DRQ2 signal is asserted. The DMA controller will then
make sure that DMA channel 2 has been programmed and is unmasked (enabled). The DMA
controller also makes sure that none of the other DMA channels are active or want to be active
and have a higher priority. Once these checks are complete, the DMA asks the CPU to release
the bus so that the DMA may use the bus. The DMA requests the bus by asserting the HRQ
signal which goes to the CPU.
The CPU detects the HRQ signal, and will complete executing the current instruction. Once the
processor has reached a state where it can release the bus, it will. Now all of the signals normally
generated by the CPU (-MEMR, -MEMW, -IOR, -IOW and a few others) are placed in a tristated condition (neither high or low) and then the CPU asserts the HLDA signal which tells the
DMA controller that it is now in charge of the bus.
Depending on the processor, the CPU may be able to execute a few additional instructions now
that it no longer has the bus, but the CPU will eventually have to wait when it reaches an
instruction that must read something from memory that is not in the internal processor cache or
pipeline.
Now that the DMA is in charge, the DMA activates its -MEMR, -MEMW, -IOR, -IOW output
signals, and the address outputs from the DMA are set to 0x3456, which will be used to direct
the byte that is about to transferred to a specific memory location.
The DMA will then let the device that requested the DMA transfer know that the transfer is
commencing. This is done by asserting the -DACK signal, or in the case of the floppy disk
controller, -DACK2 is asserted.
The floppy disk controller is now responsible for placing the byte to be transferred on the bus
Data lines. Unless the floppy controller needs more time to get the data byte on the bus (and if
the peripheral does need more time it alerts the DMA via the READY signal), the DMA will
wait one DMA clock, and then de-assert the -MEMW and -IOR signals so that the memory will
latch and store the byte that was on the bus, and the FDC will know that the byte has been
transferred.
Since the DMA cycle only transfers a single byte at a time, the FDC now drops the DRQ2 signal,
so the DMA knows that it is no longer needed. The DMA will de-assert the -DACK2 signal, so
that the FDC knows it must stop placing data on the bus.
The DMA will now check to see if any of the other DMA channels have any work to do. If none
of the channels have their DRQ lines asserted, the DMA controller has completed its work and
will now tri-state the -MEMR, -MEMW, -IOR, -IOW and address signals.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Finally, the DMA will de-assert the HRQ signal. The CPU sees this, and de-asserts the HOLDA
signal. Now the CPU activates its -MEMR, -MEMW, -IOR, -IOW and address lines, and it
resumes executing instructions and accessing main memory and the peripherals.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
For a typical floppy disk sector, the above process is repeated 512 times, once for each byte.
Each time a byte is transferred, the address register in the DMA is incremented and the counter
in the DMA that shows how many bytes are to be transferred is decremented.
When the counter reaches zero, the DMA asserts the EOP signal, which indicates that the
counter has reached zero and no more data will be transferred until the DMA controller is
reprogrammed by the CPU. This event is also called the Terminal Count (TC). There is only one
EOP signal, and since only one DMA channel can be active at any instant, the DMA channel that
is currently active must be the DMA channel that just completed its task.
If a peripheral wants to generate an interrupt when the transfer of a buffer is complete, it can test
for its -DACKn signal and the EOP signal both being asserted at the same time. When that
happens, it means the DMA will not transfer any more information for that peripheral without
intervention by the CPU. The peripheral can then assert one of the interrupt signals to get the
processors' attention. In the PC architecture, the DMA chip itself is not capable of generating an
interrupt. The peripheral and its associated hardware is responsible for generating any interrupt
that occurs. Subsequently, it is possible to have a peripheral that uses DMA but does not use
interrupts.
It is important to understand that although the CPU always releases the bus to the DMA when
the DMA makes the request, this action is invisible to both applications and the operating
system, except for slight changes in the amount of time the processor takes to execute
instructions when the DMA is active. Subsequently, the processor must poll the peripheral, poll
the registers in the DMA chip, or receive an interrupt from the peripheral to know for certain
when a DMA transfer has completed.
You may have noticed earlier that instead of the DMA setting the address lines to 0x00123456 as
we said earlier, the DMA only set 0x3456. The reason for this takes a bit of explaining.
When the original IBM PC was designed, IBM elected to use both DMA and interrupt controller
chips that were designed for use with the 8085, an 8-bit processor with an address space of 16
bits (64K). Since the IBM PC supported more than 64K of memory, something had to be done to
allow the DMA to read or write memory locations above the 64K mark. What IBM did to solve
this problem was to add an external data latch for each DMA channel that holds the upper bits of
the address to be read to or written from. Whenever a DMA channel is active, the contents of that
latch are written to the address bus and kept there until the DMA operation for the channel ends.
IBM called these latches Page Registers.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
So for our example above, the DMA would put the 0x3456 part of the address on the bus, and
the Page Register for DMA channel 2 would put 0x0012xxxx on the bus. Together, these two
values form the complete address in memory that is to be accessed.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Because the Page Register latch is independent of the DMA chip, the area of memory to be read
or written must not span a 64K physical boundary. For example, if the DMA accesses memory
location 0xffff, after that transfer the DMA will then increment the address register and the DMA
will access the next byte at location 0x0000, not 0x10000. The results of letting this happen are
probably not intended.
Note: Physical 64K boundaries should not be confused with 8086-mode 64K Segments,
which are created by mathematically adding a segment register with an offset register. Page
Registers have no address overlap and are mathematically OR-ed together.
To further complicate matters, the external DMA address latches on the PC/AT hold only eight
bits, so that gives us 8+16=24 bits, which means that the DMA can only point at memory
locations between 0 and 16Meg. For newer computers that allow more than 16Meg of memory,
the standard PC-compatible DMA cannot access memory locations above 16Meg.
To get around this restriction, operating systems will reserve a RAM buffer in an area below
16Meg that also does not span a physical 64K boundary. Then the DMA will be programmed to
transfer data from the peripheral and into that buffer. Once the DMA has moved the data into this
buffer, the operating system will then copy the data from the buffer to the address where the data
is really supposed to be stored.
When writing data from an address above 16Meg to a DMA-based peripheral, the data must be
first copied from where it resides into a buffer located below 16Meg, and then the DMA can
copy the data from the buffer to the hardware. In FreeBSD, these reserved buffers are called
Bounce Buffers. In the MS-DOS world, they are sometimes called Smart Buffers.
Note: A new implementation of the 8237, called the 82374, allows 16 bits of page register to be
specified and enables access to the entire 32 bit address space, without the use of bounce buffers.
The 8237 DMA can be operated in several modes. The main ones are:
Single
A single byte (or word) is transferred. The DMA must release and re-acquire the bus for
each additional byte. This is commonly-used by devices that cannot transfer the entire
block of data immediately. The peripheral will request the DMA each time it is ready for
another transfer.
The standard PC-compatible floppy disk controller (NEC 765) only has a one-byte
buffer, so it uses this mode.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Block/Demand
Once the DMA acquires the system bus, an entire block of data is transferred, up to a
maximum of 64K. If the peripheral needs additional time, it can assert the READY signal
to suspend the transfer briefly. READY should not be used excessively, and for slow
peripheral transfers, the Single Transfer Mode should be used instead.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The difference between Block and Demand is that once a Block transfer is started, it runs
until the transfer count reaches zero. DRQ only needs to be asserted until -DACK is
asserted. Demand Mode will transfer one more bytes until DRQ is de-asserted, at which
point the DMA suspends the transfer and releases the bus back to the CPU. When DRQ
is asserted later, the transfer resumes where it was suspended.
Older hard disk controllers used Demand Mode until CPU speeds increased to the point
that it was more efficient to transfer the data using the CPU, particularly if the memory
locations used in the transfer were above the 16Meg mark.
Cascade
This mechanism allows a DMA channel to request the bus, but then the attached
peripheral device is responsible for placing the addressing information on the bus instead
of the DMA. This is also used to implement a technique known as Bus Mastering.
When a DMA channel in Cascade Mode receives control of the bus, the DMA does not
place addresses and I/O control signals on the bus like the DMA normally does when it is
active. Instead, the DMA only asserts the -DACK signal for the active DMA channel.
At this point it is up to the peripheral connected to that DMA channel to provide address
and bus control signals. The peripheral has complete control over the system bus, and can
do reads and/or writes to any address below 16Meg. When the peripheral is finished with
the bus, it de-asserts the DRQ line, and the DMA controller can then return control to the
CPU or to some other DMA channel.
Cascade Mode can be used to chain multiple DMA controllers together, and this is
exactly what DMA Channel 4 is used for in the PC architecture. When a peripheral
requests the bus on DMA channels 0, 1, 2 or 3, the slave DMA controller asserts
HLDREQ, but this wire is actually connected to DRQ4 on the primary DMA controller
instead of to the CPU. The primary DMA controller, thinking it has work to do on
Channel 4, requests the bus from the CPU using HLDREQ signal. Once the CPU grants
the bus to the primary DMA controller, -DACK4 is asserted, and that wire is actually
connected to the HLDA signal on the slave DMA controller. The slave DMA controller
then transfers data for the DMA channel that requested it (0, 1, 2 or 3), or the slave DMA
may grant the bus to a peripheral that wants to perform its own bus-mastering, such as a
SCSI controller.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Because of this wiring arrangement, only DMA channels 0, 1, 2, 3, 5, 6 and 7 are usable
with peripherals on PC/AT systems.
Note: DMA channel 0 was reserved for refresh operations in early IBM PC
computers, but is generally available for use by peripherals in modern systems.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The Dynamic RAM used in all PCs for main memory must be accessed frequently to
keep the bits stored in the components charged. Dynamic RAM essentially consists of
millions of capacitors with each one holding one bit of data. These capacitors are charged
with power to represent a 1 or drained to represent a 0. Because all capacitors leak, power
must be added at regular intervals to keep the 1 values intact. The RAM chips actually
handle the task of pumping power back into all of the appropriate locations in RAM, but
they must be told when to do it by the rest of the computer so that the refresh activity will
not interfere with the computer wanting to access RAM normally. If the computer is
unable to refresh memory, the contents of memory will become corrupted in just a few
milliseconds.
Since memory read and write cycles count as refresh cycles (a dynamic RAM refresh
cycle is actually an incomplete memory read cycle), as long as the peripheral controller
continues reading or writing data to sequential memory locations, that action will refresh
all of memory.
Bus-mastering is found in some SCSI host interfaces and other high-performance
peripheral controllers.
Autoinitialize
This mode causes the DMA to perform Byte, Block or Demand transfers, but when the
DMA transfer counter reaches zero, the counter and address are set back to where they
were when the DMA channel was originally programmed. This means that as long as the
peripheral requests transfers, they will be granted. It is up to the CPU to move new data
into the fixed buffer ahead of where the DMA is about to transfer it when doing output
operations, and to read new data out of the buffer behind where the DMA is writing when
doing input operations.
This technique is frequently used on audio devices that have small or no hardware
sample buffers. There is additional CPU overhead to manage this circular buffer, but
in some cases this may be the only way to eliminate the latency that occurs when the
DMA counter reaches zero and the DMA stops transfers until it is reprogrammed.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
The DMA channel that is to be programmed should always be masked before loading any
settings. This is because the hardware might unexpectedly assert the DRQ for that channel, and
the DMA might respond, even though not all of the parameters have been loaded or updated.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Once masked, the host must specify the direction of the transfer (memory-to-I/O or I/O-tomemory), what mode of DMA operation is to be used for the transfer (Single, Block, Demand,
Cascade, etc), and finally the address and length of the transfer are loaded. The length that is
loaded is one less than the amount you expect the DMA to transfer. The LSB and MSB of the
address and length are written to the same 8-bit I/O port, so another port must be written to first
to guarantee that the DMA accepts the first byte as the LSB and the second byte as the MSB of
the length and address.
Then, be sure to update the Page Register, which is external to the DMA and is accessed through
a different set of I/O ports.
Once all the settings are ready, the DMA channel can be un-masked. That DMA channel is now
considered to be armed, and will respond when the DRQ line for that channel is asserted.
Refer to a hardware data book for precise programming details for the 8237. You will also need
to refer to the I/O port map for the PC system, which describes where the DMA and Page
Register ports are located. A complete port map table is located below.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
write
read
write
read
write
read
write
read
write
read
write
read
write
read
write
read
0x08
0x08
0x09
0x09
0x0a
0x0a
0x0b
0x0b
0x0c
0x0c
0x0d
write
read
write
read
write
read
write
read
write
read
write
Command Register
Status Register
Request Register
Single Mask Register Bit
Mode Register
Clear LSB/MSB Flip-Flop
Master Clear/Reset
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
0x0d
0x0e
0x0e
0x0f
0x0f
read
write
read
write
read
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
write
read
write
read
write
read
write
read
write
read
write
read
write
read
write
read
0xd0
0xd0
0xd2
0xd2
0xd4
0xd4
0xd6
0xd6
0xd8
0xd8
0xda
write
read
write
read
write
read
write
read
write
read
write
Command Register
Status Register
Request Register
Single Mask Register Bit
Mode Register
Clear LSB/MSB Flip-Flop
Master Clear/Reset
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
0xda
0xdc
0xdc
0xde
0xdf
read
write
read
write
read
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The Intel 82374 EISA System Component (ESC) was introduced in early 1996 and includes a
DMA controller that provides a superset of 8237 functionality as well as other PC-compatible
core peripheral components in a single package. This chip is targeted at both EISA and PCI
platforms, and provides modern DMA features like scatter-gather, ring buffers as well as direct
access by the system DMA to all 32 bits of address space.
If these features are used, code should also be included to provide similar functionality in the
previous 16 years worth of PC-compatible computers. For compatibility reasons, some of the
82374 registers must be programmed after programming the traditional 8237 registers for each
transfer. Writing to a traditional 8237 register forces the contents of some of the 82374 enhanced
registers to zero to provide backward software compatibility.
0x401
0x403
0x405
0x407
0x4c6
0x4ca
0x4ce
0x487
0x483
0x481
0x482
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
r/w
write
read
write
read
read
write
write
write
write
write
write
write
read
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0x48b
0x489
0x48a
0x48f
0x4e0
0x4e1
0x4e2
0x4e4
0x4e5
0x4e6
0x4e8
0x4e9
0x4ea
0x4ec
0x4ed
0x4ee
0x4f4
0x4f5
0x4f6
0x4f8
0x4f9
0x4fa
0x4fc
0x4fd
0x4fe
0x40a
0x40a
0x4d4
0x4d4
0x40c
0x410
0x411
0x412
0x413
0x415
0x416
0x417
0x418
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
read
read
read
read
read
read
r/w
r/w
r/w
r/w
r/w
r/w
r/w
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0x419
0x41a
0x41b
0x41d
0x41e
0x41f
0x420-0x423
0x424-0x427
0x428-0x42b
0x42c-0x42f
0x434-0x437
0x438-0x43b
0x43c-0x43f
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
PIO 8255
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Both the port C are assigned the same address. Thus one may have either three 8bit I/O ports or two 8-bit and two 4-bit ports from 8255. All of these ports can
function independently either as input or as output ports. This can be achieved by
programming the bits of an internal register of 8255 called as control word
register ( CWR ).
The internal block diagram and the pin configuration of 8255 are shown in fig.
The 8-bit data bus buffer is controlled by the read/write control logic. The
read/write control logic manages all of the internal and external transfers of both
data and control words.
RD, WR, A1, A0 and RESET are the inputs provided by the microprocessor to
the READ/ WRITE control logic of 8255. The 8-bit, 3-state bidirectional buffer is
used to interface the 8255 internal data bus with the external system data bus.
This buffer receives or transmits data upon the execution of input or output
instructions by the microprocessor. The control words or status information is also
transferred through the buffer.
The signal description of 8255 are briefly presented as follows :
PA7-PA0: These are eight port A lines that acts as either latched output or
buffered input lines depending upon the control word loaded into the control word
register.
PC7-PC4 : Upper nibble of port C lines. They may act as either output latches or
input buffers lines.
This port also can be used for generation of handshake lines in mode 1 or mode
2.
PC3-PC0 : These are the lower port C lines, other details are the same as PC7PC4 lines.
PB0-PB7 : These are the eight port B lines which are used as latched output lines
or buffered input lines in the same way as port A.
RD : This is the input line driven by the microprocessor and should be low to
indicate read operation to 8255.
WR : This is an input line driven by the microprocessor. A low on this line
indicates write operation.
CS : This is a chip select line. If this line goes low, it enables the 8255 to respond
to RD and WR signals, otherwise RD and WR signal are neglected.
A1-A0 : These are the address input lines and are driven by the microprocessor.
These lines A1-A0 with RD, WR and CS from the following operations for 8255.
These address lines are used for addressing any one of the four registers, i.e. three
ports and a control word register as given in table below.
In case of 8086 systems, if the 8255 is to be interfaced with lower order data bus,
the A0 and A1 pins of 8255 are connected with A1 and A2 respectively.
D0-D7 : These are the data bus lines those carry data or control word to/from the
microprocessor.
RESET : A logic high on this line clears the control word register of 8255. All
ports are set as input ports by default after reset.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
WR
1
1
1
1
CS
0
0
0
0
A1
0
0
1
1
A0
0
1
0
1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RD
0
0
0
0
RD
1
1
1
1
WR
0
0
0
0
CS
0
0
0
0
A1
0
0
1
1
A0
0
1
0
1
RD
X
1
WR
X
1
CS
1
0
A1
X
X
A0
X
X
Function
Data bus tristated
Data bus tristated
1.
2.
3.
4.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
b) RD (Read) A low on this pin enables the CPU to read the data in the ports or the
status word through data bus buffer.
c) WR ( Write ) : A low on this pin, the CPU can write data on to the ports or on to
the control register through the data bus buffer.
d) RESET: A high on this pin clears the control register and all ports are set to the
input mode
e) A0 and A1 ( Address pins ): These pins in conjunction with RD and WR pins
control the selection of one of the 3 ports.
Group A and Group B controls : These block receive control from the CPU and
issues commands to their respective ports.
Group A - PA and PCU ( PC7 PC4)
Group B - PCL ( PC3 PC0)
Control word register can only be written into no read operation of the CW
register is allowed.
a) Port A: This has an 8 bit latched/buffered O/P and 8 bit input latch. It can be
programmed in 3 modes mode 0, mode 1, mode 2.
b) Port B: This has an 8 bit latched / buffered O/P and 8 bit input latch. It can be
programmed in mode 0, mode1.
c) Port C : This has an 8 bit latched input buffer and 8 bit out put latched/buffer.
This port can be divided into two 4 bit ports and can be used as control signals for port A
and port B. it can be programmed in mode 0.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
D2
D1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D3
8
2
5
5
PA
PA6 PA7
PCU
PC4 PC7
PCL
PC0-PC3
PB
PB0 PB7
8
2
5
5
PA
PCU
PCL
PB
PC
PB0 PB7
All Output
PA
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
PA3
PA2
PA1
PA0
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
PA4
PA5
PA6
PA7
WR
Reset
D0
D1
D2
D3
D4
D5
D6
D7
Vcc
PB7
PB6
PB5
PB4
PB3
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RD
CS
GND
A1
A0
PC7
PC6
PC5
PC4
PC0
PC1
PC2
PC3
PB0
PB1
PB2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
8255A
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
PA0-PA7
D0-D7
CS
PC4-PC7
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RESET
8255A
PC0-PC3
A0
PB0-PB7
A1
RD
Vcc
WR
GND
Signals of 8255
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Group A
control
PA0-PA7
Group A
Port A(8)
1
Data
bus
Group A
Port C
upper(4)
PC7-PC4
Group B
Port C
Lower(4)
PC0-PC3
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D0-D7
RD
WR
READ/
WRITE
Control
Logic
A0
A1
RESET
Group B
control
Group B
Port B(8)
PB7-PB0
CS
D7
D6
D5
Mode for
Port A
D4
D3
PA
PC U
D2
Mode
for PB
D1
PB
D0
PC L
Group - A
1 Input
PC u
0 Output
1 Input
PA
0 Output
00
mode 0
Mode
01 mode 1
Select
of PA
10 mode 2
Group - B
PCL
PB
Mode
Select
1 Input
0 Output
1 Input
0 Output
0 mode- 0
1 mode- 1
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
D2
D1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D3
8
2
5
5
PA
PA6 PA7
PCU
PC4 PC7
PCL
PC0-PC3
PB
PB0 PB7
PA
8
2
5
5
PA
PCU
PCL
PB
PC
PB0 PB7
All Output
Mode 0
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0- Reset
1- Set
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
b) Mode 1: ( Strobed input/output mode ) In this mode the handshaking control the input
and output action of the specified port. Port C lines PC0-PC2, provide strobe or
handshake lines for port B. This group which includes port B and PC0-PC2 is called as
group B for Strobed data input/output. Port C lines PC3-PC5 provide strobe lines for port
A. This group including port A and PC3-PC5 from group A. Thus port C is utilized for
generating handshake signals. The salient features of mode 1 are listed as follows:
1. Two groups group A and group B are available for strobed data transfer.
2. Each group contains one 8-bit data I/O port and one 4-bit control/data port.
3. The 8-bit data port can be either used as input and output port. The inputs and
outputs both are latched.
4. Out of 8-bit port C, PC0-PC2 are used to generate control signals for port B and
PC3-PC5 are used to generate control signals for port A. the lines PC6, PC7 may
be used as independent data lines.
The control signals for both the groups in input and output modes are explained as
follows:
Input control signal definitions (mode 1 ):
STB( Strobe input ) If this lines falls to logic low level, the data available at 8bit input port is loaded into input latches.
IBF ( Input buffer full ) If this signal rises to logic 1, it indicates that data has
been loaded into latches, i.e. it works as an acknowledgement. IBF is set by a low
on STB and is reset by the rising edge of RD input.
INTR ( Interrupt request ) This active high output signal can be used to
interrupt the CPU whenever an input device requests the service. INTR is set by a
high STB pin and a high at IBF pin. INTE is an internal flag that can be controlled
by the bit set/reset mode of either PC4(INTEA) or PC2(INTEB) as shown in fig.
INTR is reset by a falling edge of RD input. Thus an external input device can be
request the service of the processor by putting the data on the bus and sending the
strobe signal.
Output control signal definitions (mode 1) :
OBF (Output buffer full ) This status signal, whenever falls to low, indicates
that CPU has written data to the specified output port. The OBF flip-flop will be
set by a rising edge of WR signal and reset by a low going edge at the ACK input.
ACK ( Acknowledge input ) ACK signal acts as an acknowledgement to be
given by an output device. ACK signal, whenever low, informs the CPU that the
data transferred by the CPU to the output device through the port is received by
the output device.
INTR ( Interrupt request ) Thus an output signal that can be used to interrupt
the CPU when an output device acknowledges the data received from the CPU.
INTR is set when ACK, OBF and INTE are 1. It is reset by a falling edge on WR
input. The INTEA and INTEB flags are controlled by the bit set-reset mode of
PC6 and PC2 respectively.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
1/0 X X X
1 X
D7 D6 D5 D4 D3 D2 D1 D0
X X
X 1
D7 D6 D5 D4 D3 D2 D1 D0
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
1 - Input
0 - Output
For PC6 PC7
PB0 PB7
PA0 PA7
INTEA
PC4
PC5
PC3
RD
INTEB
STBA
IBFA
PC6 PC7
STBB
PC0
INTR
IBFB
I/O
RD
Mode 1 Control Word Group B
I/P
INTRA
PC2
PC1
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
STB
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
IBF
INTR
RD
DATA
from
WR
OBF
INTR
ACK
Data OP to
Port
Mode 1 Strobed Data Output
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
1/0 X X X
1 X
D7 D6 D5 D4 D3 D2 D1 D0
X X
X 1
D7 D6 D5 D4 D3 D2 D1 D0
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
1 - Input
0 - Output
For PC4 PC5
PA0 PA7
INTEA
PC7
PC6
PC3
WR
OBF
A
ACK
A
INTRA
PC4 PC5
1.
2.
3.
4.
5.
INTEB
PB0
PB7
PC1
PC2
OBF
PC0
INTRB
ACKB
I/O
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
WR
OBF
INTR
ACK
STB
IBF
Data bus
Data towards
8255
RD
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
peripheral device, in terms of the control signals, using the normal I/O
instructions.
D6
D5
D4
D3
D2
D1
D0
1/0
1/0
1/0
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D7
1/0 mode
Port A
mode 2
Port B mode
0-mode 0
1- mode 1
PC2 PC0
1 - Input
0 - Output
Port B
1- I/P
0-O/P
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
PC3
INTR
PA0-PA7
INTE 1
INTE 2
RD
PC7
PC6
OBF
PC4
STB
PC5
IBF
ACK
WR
I/O
Mode 2 pins
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
1.
When you press a key on your computer, you are activating a switch. There are
many different ways of making these switches. An overview of the construction
and operation of some of the most common types.
Mechanical key switches: In mechanical-switch keys, two pieces of metal are
pushed together when you press the key. The actual switch elements are often
made of a phosphor-bronze alloy with gold platting on the contact areas. The key
switch usually contains a spring to return the key to the nonpressed position and
perhaps a small piece of foam to help damp out bouncing.
Some mechanical key switches now consist of a molded silicon dome with a
small piece of conductive rubber foam short two trace on the printed-circuit board
to produce the key pressed signal.
Mechanical switches are relatively inexpensive but they have several
disadvantages. First, they suffer from contact bounce. A pressed key may make
and break contact several times before it makes solid contact.
Second, the contacts may become oxidized or dirty with age so they no longer
make a dependable connection.
Higher-quality mechanical switches typically have a rated life time of about 1
million keystrokes. The silicone dome type typically last 25 million keystrokes.
Membrane key switches: These switches are really a special type of mechanical
switches. They consist of a three-layer plastic or rubber sandwich.
The top layer has a conductive line of silver ink running under each key position.
The bottom layer has a conductive line of silver ink running under each column of
keys.
When u press a key, you push the top ink line through the hole to contact the
bottom ink line.
The advantages of membrane keyboards is that they can be made as very thin,
sealed units.
They are often used on cash registers in fast food restaurants. The lifetime of
membrane keyboards varies over a wide range.
Capacitive key switches: A capacitive keyswitch has two small metal plates on
the printed circuit board and another metal plate on the bottom of a piece of foam.
When u press the key, the movable plate is pushed closer to fixed plate. This
changes the capacitance between the fixed plates. Sense amplifier circuitry detects
this change in capacitance and produce a logic level signal that indicates a key has
been pressed.
The big advantages of a capacitive switch is that it has no mechanical contacts to
become oxidized or dirty.
A small disadvantage is the specified circuitry needed to detect the change in
capacitance.
Capacitive keyswitches typically have a rated lifetime of about 20 million
keystrokes.
Hall effect keyswitches: This is another type of switch which has no mechanical
contact. It takes advantage of the deflection of a moving charge by a magnetic
field.
2.
3.
4.
2.
3.
4.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Key
Motion
HALL
VOLTAGE
Reference
Current
Magnetic Field
HALL EFFECT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
KEYBOARD
ZERO TO ALL
ROWS
OUTPUT ZERO
TO ONE ROW
D
E
READ
COLUMNS
E
N
C
O
D
E
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
READ
COLUMNS
NO
ALL
KEYS
OPEN ?
YES
READ
COLUMNS
NO
KEY
PRESSE
D?
YES
WAIT 20ms
D
E
T
E
C
T
READ
COLUMNS
NO
B
O
U
N
C
E
KEY
PRESSED
?
YES
NO
KEY
FOUND
?
YES
CONVERT TO
HEX
RETURN
FLOW CHART
Once the columns are found to be all high, the program enters another loop, which
waits until a low appears on one of the columns, indicating that a key has been
pressed. This second loop does the detect task for us. A simple 20-ms delay
procedure then does the debounce task.
After the debounce time, another check is made to see if the key is still pressed. If
the columns are now all high, then no key is pressed and the initial detection was
caused by a noise pulse or a light brushing past a key. If any of the columns are
still low, then the assumption is made that it was a valid keypress.
The final task is to determine the row and column of the pressed key and convert
this row and column information to the hex code for the pressed key. To get the
row and column information, a low is output to one row and the column are read.
If none of the columns is low, the pressed key is not in that row. So the low is
rotated to the next row and the column are checked again. The process is repeated
until a low on a row produces a low on one of the column.
The pressed key then is in the row which is low at that time.
The connection fig shows the byte read in from the input port will contain a 4-bit
code which represents the row of the pressed key and a 4-bit code which represent
the column of the pressed key.
Error trapping: The concept of detecting some error condition such as no match
found is called error trapping. Error trapping is a very important part of real
programs. Even in simple programs, think what might happen with no error trap if
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
two keys in the same row were pressed at exactly at the same time and a column
code with two lows in it was produced.
This code would not match any of the row-column codes in the table, so after all
the values in the table were checked, assigned register in program would be
decremented from 0000H to FFFFH. The compare decrement cycle would
continue through 65,536 memory locations until, by change the value in a
memory location matched the row-column code. The contents of the lower byte
register at hat point would be passed back to the calling routine. The changes are
1 in 256 that would be the correct value for one of the pressed keys. You should
keep an error trap in a program whenever there is a chance for it.
2. Keyboard Interfacing with Hardware: For the system where the CPU is too
busy to be bothered doing these tasks in software, an external device is used to do
them.
One of a MOS device which can be do this is the General Instruments AY5-2376
which can be connected to the rows and columns of a keyboard switch matrix.
The AY5-2376 independently detects a keypress by cycling a low down through
the rows and checking the columns. When it finds a key pressed, it waits a
debounce time.
If the key is still pressed after the debounce time, the AY5-2376 produces the 8bit code for the pressed key and send it out to microcomputer port on 8 parallel
lines. The microcomputer knows that a valid ASCII code is on the data lines, the
AY5-2376 outputs a strobe pulse.
The microcomputer can detect this strobe pulse and read in ASCII code on a
polled basis or it can detect the strobe pulse on an interrupt basis.
With the interrupt method the microcomputer doesnt have to pay any attention to
the keyboard until it receives an interrupt signal.
So this method uses very little of the microcomputer time. The AY5-2376 has a
feature called two-key rollover. This means that if two keys are pressed at nearly
the same time, each key will be detected, debounced and converted to ASCII.
The ASCII code for the first key and a strobe signal for it will be sent out then the
ASCII code for the second key and a strobe signal for it will be sent out and
compare this with two-key lockout.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
+ 5V
Output port 01
D0
E
A
F
B
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D1
D2
D3
10K
Input port
D7
02
D
7 6
D
6 5
D
5 4
D
4 3
D
3 2
D
2 1
D0
Example
Interface a 4 * 4 keyboard with 8086 using 8255 an write an ALP for detecting a
key closure and return the key code in AL. The debounce period for a key is
10ms. Use software debouncing technique. DEBOUNCE is an available 10ms
delay routine.
Solution: Port A is used as output port for selecting a row of keys while Port B is
used as an input port for sensing a closed key. Thus the keyboard lines are
selected one by one through port A and the port B lines are polled continuously
till a key closure is sensed. The routine DEBOUNCE is called for key
debouncing. The key code is depending upon the selected row and a low sensed
column.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
+ 5V
10
K
RESET
LOWR
IORD
PA3
PA2
PA1
10
K
E
A
10K
10K
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
D0-D7
10
K
10
K
8255
A15
A12
A13
A14
A0
A2
A1
A1
A0
CS
PA0
10K
10K
PB3
PB2
PB1
PB0
Interfacing 4 * 4 Keyboard
The higher order lines of port A and port B are left unused. The address of port A
and port B will respectively 8000H and 8002H while address of CWR will be
8006H. The flow chart of the complete program is as given. The control word for
this problem will be 82H. Code segment CS is used for storing the program code.
Key Debounce : Whenever a mechanical push-button is pressed or released once,
the mechanical components of the key do not change the position smoothly, rather
it generates a transient response .
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
START
Initialise 8255 row,
column counter and key
code reg.
Key
Closed
Yes
Wait for Debounce
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
No
row
Counter =0 ?
No
No
column
counter=0?
Flow chart
These transient variations may be interpreted as the multiple key pressure and
responded accordingly by the microprocessor system.
To avoid this problem, two schemes are suggested: the first one utilizes a bistable
multivibrator at the output of the key to debounce .
The other scheme suggests that the microprocessor should be made to wait for the
transient period ( usually 10ms ), so that the transient response settles down and
reaches a steady state.
A logic 0 will be read by the microprocessor when the key is pressed.
In a number of high precision applications, a designer may have two options- the
first is to have more than one 8-bit port, read (write) the port one by one and then
from the multibyte data, the second option allows forming 16-bit ports using two
8-bit ports and use 16-bit read or write operations.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Logic 1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
+5V
V0
Logic 0
Key pressed
Key released
Response
A Mechanical Key
Logic 0
Key released
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The first problem is power consumption. For worst-case calculations, assume that
all 8 digits are displaying the digit 8, so all 7 segments are all lit. Seven segment
time 20mA per segment gives a current of 140mA per digit. Multiplying this by 8
digits gives a total current of 1120mA or 1.12A for 8 digits.
A second problem of the static approach is that each display digit requires a
separate 7447 decoder, each of which uses of another 13mA. The current required
by the decoders and the LED displays might be several times the current required
by the reset of the circuitry in the instrument.
To solve the problem of the static display approach, we use a multiplex method,
example for an explanation of the multiplexing.
The fig shows a circuit you can add to a couple of microcomputer ports to drive
some common anode LED displays in a multiplexed manner. The circuit has only
one 7447 and that the segment outputs of the 7447 are bused in parallel to the
segment inputs of all the digits.
The question that may occur to you on first seeing this is: Arent all the digits
going to display the same number? The answer is that they would if all the digits
were turned on at the same time. The tricky of multiplexing displays is that only
one display digit is turned on at a time.
The PNP transistor is series with the common anode of each digit acts as on/off
switch for that digit. Heres how the multiplexing process works.
The BCD code for digit 1 is first output from port B to the 7447. the 7447 outputs
the corresponding 7-segment code on the segment bus lines. The transistor
connected to digit 1 is then turned on by outputting a low to the appropriate bit of
port A. All the rest of the bits of port A are made high to make sure no other digits
are turned on. After 1 or 2 ms, digit 1 is turned off by outputting all highs to port
A.
The BCD code for digit 2 is then output to the 7447 on port B, and a word to turn
on digit 2 is output on port A.
After 1 or 2 ms, digit 2 is turned off and the process is repeated for digit 3. the
process is continued until all the digits have had a turn. Then digit 1 and the
following digits are lit again in turn.
A procedure which is called on an interrupt basis every 2ms to keep these displays
refreshed wit some values stored in a table. With 8 digits and 2ms per digit, you
get back to digit 1 every 16ms or about 60 times a second.
This refresh rate is fast enough so that the digits will each appear to be lit all time.
Refresh rates of 40 to 200 times a second are acceptable.
The immediately obvious advantages of multiplexing the displays are that only
one 7447 is required, and only one digit is lit at a time. We usually increase the
current per segment to between 40 and 60 mA for multiplexed displays so that
they will appear as bright as they would if they were not multiplexed. Even with
this increased segment current, multiplexing gives a large saving in power and
parts.
The software-multiplexed approach we have just described can also be used to
drive 18-segment LED devices and dot-matrix LED device. For these devices,
however you replace the 7447 in fig with ROM which generates the required
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
segment codes when the ASCII code for a character is applied to the address
inputs of the ROM.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
+5V
150
Each
+5V
13 12
a
b
Vcc
11 10
c
d
9 15 14
e
f
g
BI 5
7447
RBI 4
GND
+5V
B
1
C
2
D
6
LT 3
BCD INPUTS
Circuit for driving single 7-segment LED display with 7447
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
D0
D1
D2
D3
D4
D5
D6
R1
R2
Q1
R3
R5
R4
Q2
Q3
Q5
Q4
R7
R6
Q6
Q7
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
OUTPUT
PORT
A
+ 5V
MSD
+5V
OUTPUT
PORT
B
D0
D1
D2
D3
150
150
150
Vcc
GND
150
150
150
LSD
150
7447
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Field-effect types use polarization to absorb light where the electric field is
present. This produces dark characters on a silver- gray background.
Most LCDs require a voltage of 2 or 3 V between the backplane and a segment to
turn on the segment.
We cannot just connect the backplane to ground and drive the segment with the
outputs of a TTL decoder. The reason for this is a steady dc voltage of more than
about 50mV is applied between a segment and the backplane.
To prevent a dc buildup on the segments, the segment-drive signals for LCD must
be square waves with a frequency of 30 to 150 Hz.
Even if you pulse the TTL decoder, it still will not work because the output low
voltage of TTL devices is greater than 50mV.
CMOS gates are often used to drive LCDs.
The Following fig shows how two CMOS gate outputs can be connected to drive
an LCD segment and backplane.
The off segment receives the same drive signal as the backplane. There is never
any voltage between them, so no electric field is produced. The waveform for the
on segment is 180 out of phase with the backplane signal, so the voltage between
this segment and the backplane will always be +V.
The logic for this signal, a square wave and its complement. To the driving gates,
the segment-backplane sandwich appears as a somewhat leaky capacitor.
The CMOS gates can be easily supply the current required to charge and
discharge this small capacitance.
Older inexpensive LCD displays turn on and off too slowly to be multiplexed the
way we do LED display.
At 0c some LCD may require as mush as 0.5s to turn on or off. To interface to
those types we use a nonmultiplexed driver device.
More expensive LCD can turn on and off faster, so they are often multiplexed
using a variety of techniques.
In the following section we show you how to interface a nonmultiplexed LCD to a
microprocessor such as SDK-86.
Intersil ICM7211M can be connected to drive a 4-digit, nonmultiplexed, 7segment LCD display.
The 7211M input can be connected to port pins or directly to microcomputer bus.
We have connected the CS inputs to the Y2 output of the 74LS138 port decoder.
According to the truth table the device will then be addressable as ports with a
base address of FF10H. SDK-86 system address lines A2 is connected to the
digit-select input (DS2) and system address lines A1 is connected to the DS1
input. This gives digit 4 a system address of FF10H.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
A8-A15 A5-A7
0
0
0
0
0
0
0
0
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
A2 A1 A0 M/IO
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
0
0
0
0
1
1
1
1
0
0
0
0
0
0
0
0
Y Output
Selected
00
1
2
3
4
5
6
7
System Base
Address
F F 0
0
F F 0
8
F F 1
0
F F 1
8
F F 0
1
F F 0
9
F F 1
1
F F 1
9
Device
8259A #1
8259A #2
8254
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
1
1
1
1
1
1
1
1
A4 A3
NONE
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
D4
Segment Outputs
ICM7211M
D3
D2
Segment Outputs
Segment Outputs
D1
Segment Outputs
7 Wide Driver
7 Wide Driver
7 Wide Driver
7 Wide Driver
7 Wide Latch
EN
7 Wide Latch
EN
7 Wide Latch
EN
7 Wide Latch
EN
Programmable
4 to 7 Decoder
Programmable
4 to 7 Decoder
Programmable
4 to 7 Decoder
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Programmable
4 to 7 Decoder
AD0
AD1
AD2
AD3
A1
A2
Data
4 bit
latch
Enable
DS1
DS2
2to4
Decoder
2 bit
Latch
Enable
Enable
74LS138 CS1
Y2
CS2
One
Shot
Oscillator
16KHz Free
Running
/ 128
Back
Plane
Driver
Enable
Back Plane
Output
+5 V OSC Enable
Enable Detector
Fig : Circuit for interfacing four LCD digits to an SDK-86 bus using ICM7211M
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The pin diagram of AD7523 is shown in fig the supply range is from +5V to
+15V, while Vref may be any where between -10V to +10V. The maximum
analog output voltage will be any where between -10V to +10V, when all the
digital inputs are at logic high state.
Usually a zener is connected between OUT1 and OUT2 to save the DAC from
negative transients. An operational amplifier is used as a current to voltage
converter at the output of AD to convert the current out put of AD to a
proportional output voltage.
G.VIjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
It also offers additional drive capability to the DAC output. An external feedback
resistor acts to control the gain. One may not connect any external feedback
resistor, if no gain control is required.
EXAMPLE: Interfacing DAC AD7523 with an 8086 CPU running at 8MHZ and
write an assembly language program to generate a sawtooth waveform of period
1ms with Vmax 5V.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Solution: Fig shows the interfacing circuit of AD 74523 with 8086 using 8255.
program gives an ALP to generate a sawtooth waveform using circuit.
ASSUME
CS:CODE
CODE SEGMENT
START
:MOV AL,80h
OUT CW, AL
AGAIN
:MOV AL,00h
BACK :
OUT PA, AL
INC AL
CMP AL, 0FFh
JB
BACK
JMP AGAIN
CODE ENDS
END
START
G.VIjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
+5V
+10V
15
14
16
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RFB
PA7
MSB
OUT1 1
8255A
PA0
LSB
OUT2
11
VZ
V0
AD7523
CS
GND
In the above program, port A is initialized as the output port for sending the
digital data as input to DAC. The ramp starts from the 0V (analog), hence AL
starts with 00H. To increment the ramp, the content of AL is increased during
each execution of loop till it reaches F2H.
After that the saw tooth wave again starts from 00H, i.e. 0V(analog) and the
procedure is repeated. The ramp period given by this program is precisely
1.000625 ms. Here the count F2H has been calculated by dividing the required
delay of 1ms by the time required for the execution of the loop once. The ramp
slope can be controlled by calling a controllable delay after the OUT instruction.
G.VIjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
In most of the cases, the PIO 8255 is used for interfacing the analog to digital
converters with microprocessor.
We have already studied 8255 interfacing with 8086 as an I/O port, in previous
section. This section we will only emphasize the interfacing techniques of analog
to digital converters with 8255.
The analog to digital converters is treaded as an input device by the
microprocessor, that sends an initialising signal to the ADC to start the analogy to
digital data conversation process. The start of conversation signal is a pulse of a
specific duration.
The process of analog to digital conversion is a slow process, and the
microprocessor has to wait for the digital data till the conversion is over. After the
conversion is over, the ADC sends end of conversion EOC signal to inform the
microprocessor that the conversion is over and the result is ready at the output
buffer of the ADC. These tasks of issuing an SOC pulse to ADC, reading EOC
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
signal from the ADC and reading the digital output of the ADC are carried out by
the CPU using 8255 I/O ports.
The time taken by the ADC from the active edge of SOC pulse till the active
edge of EOC signal is called as the conversion delay of the ADC.
It may range any where from a few microseconds in case of fast ADC to even a
few hundred milliseconds in case of slow ADCs.
The available ADC in the market use different conversion techniques for
conversion of analog signal to digitals. Successive approximation techniques and
dual slope integration techniques are the most popular techniques used in the
integrated ADC chip.
General algorithm for ADC interfacing contains the following steps:
1. Ensure the stability of analog input, applied to the ADC.
2. Issue start of conversion pulse to ADC
3. Read end of conversion signal to mark the end of conversion processes.
4. Read digital data output of the ADC as equivalent digital output.
5. Analog input voltage must be constant at the input of the ADC right from the start
of conversion till the end of the conversion to get correct results. This may be
ensured by a sample and hold circuit which samples the analog signal and holds it
constant for a specific time duration. The microprocessor may issue a hold signal
to the sample and hold circuit.
6. If the applied input changes before the complete conversion process is over, the
digital equivalent of the analog input calculated by the ADC may not be correct.
ADC 0808/0809 :
The analog to digital converter chips 0808 and 0809 are 8-bit CMOS, successive
approximation converters. This technique is one of the fast techniques for analog
to digital conversion. The conversion delay is 100s at a clock frequency of 640
KHz, which is quite low as compared to other converters. These converters do not
need any external zero or full scale adjustments as they are already taken care of
by internal circuits. These converters internally have a 3:8 analog multiplexer so
that at a time eight different analog conversion by using address lines ADD A, ADD B, ADD C. Using these address inputs, multichannel data acquisition
system can be designed using a single ADC. The CPU may drive these lines using output
port lines in case of multichannel applications. In case of single input applications, these
may be hardwired to select the proper input.
There are unipolar analog to digital converters, i.e. they are able to convert only
positive analog input voltage to their digital equivalent. These chips do no contain
any internal sample and hold circuit.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Analog /P
selecte
Address lines
B
I/P0
I/P1
I/P2
I/P3
I/P4
I/P5
I/P6
I/P7
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
If one needs a sample and hold circuit for the conversion of fast signal into
equivalent digital quantities, it has to be externally connected at each of the
analog inputs.
Vcc
GND
Vref +
Vref _
I/P0 I/P7
ADD A,B,C
O7 O0
SOC
EOC
OE
CLK
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
SOC
I/P 0
CLOCK
EOC
I/P 1
Control and
Timing unit
and .A.R.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
I/P2
I/P3
8 Channel
Analog
Multiplexer
I/P4
256 R
Register
ladder and
Switch tree
I/P5
I/P6
I/P7
V ref +
C B
Address
V ref _
8-bit
O/P
O/P
Latch
O/P
Enable
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
CLOCK
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
START
ALE
EO C
OE
O/P
Example: Interfacing ADC 0808 with 8086 using 8255 ports. Use port A of 8255
for transferring digital data output of ADC to the CPU and port C for control
signals. Assume that an analog input is present at I/P2 of the ADC and a clock
input of suitable frequency is available for ADC.
Solution: The analog input I/P2 is used and therefore address pins A,B,C should
be 0,1,0 respectively to select I/P2. The OE and ALE pins are already kept at +5V
to select the ADC and enable the outputs. Port C upper acts as the input port to
receive the EOC signal while port C lower acts as the output port to send SOC to
the ADC.
Port A acts as a 8-bit input data port to receive the digital data output from the
ADC. The 8255 control word is written as follows:
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 1 1 0 0 0
The required ALP is as follows:
MOV AL, 98h
;initialise 8255 as
OUT CWR, AL
;discussed above.
MOV AL, 02h
;Select I/P2 as analog
OUT Port B, AL
;input.
MOV AL, 00h
;Give start of conversion
OUT Port C, AL
; pulse to the ADC
MOV AL, 01h
OUT Port C, AL
MOV AL, 00h
OUT Port C, AL
WAIT: IN
AL, Port C
;Check for EOC by
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
RCR
JNC WAIT
IN
AL, Port A
HLT
Vref +
+5V
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
CS
+5V
PA7 PA0
D0 D 7
A2
Clock up
O7 O0
PC7
EOC
PC0
SOC
A1
Vcc
OE
Reset
IORD
IOWR
8255
+5V
Analog
I/P
Voltage
ADC
0808
ALE
A
GND
PB0
PB1
PB2
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Stepper motor is a device used to obtain an accurate position control of rotating shafts. A stepper
motor employs rotation of its shaft in terms of steps, rather than continuous rotation as in case of
AC or DC motor. To rotate the shaft of the stepper motor, a sequence of pulses is needed to be
applied to the windings of the stepper motor, in proper sequence. The numbers of pulses required
for complete rotation of the shaft of the stepper motor are equal to the number of internal teeth
on its rotor. The stator teeth and the rotor teeth lock with each other to fix a position of the shaft.
With a pulse applied to the winding input, the rotor rotates by one teeth position or an angle x.
the angle x may be calculated as: x = 360 / no. of rotor teeth .After the rotation of the shaft
through angle x, the rotor locks it self with the next tooth in the sequence on the internal surface
of the stator. The typical schematic of a typical stepper motor with four windings is as shown
below.
The stepper motors have been designed to work with digital circuits. Binary level pulses of 0-5V
are required at its winding inputs to obtain the rotation of the shafts. The sequence of the pulses
can be decided, depending upon the required motion of the shaft. By suitable sequence of the
pulses the motor can be used in three modes of operation.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
WORKING:8255 is interfaced with 8086 in I/O mapped I/O. port C (PC0, PC1, PC2, PC3) is used to give
pulse sequence to stepper motor. The 8255 provides very less current which will not be able to
drive stepper motor coils so each of the winding of a stepper motor needs to be interfaced using
high speed switching Darlington transistors with max 1A, 80V rating with heat sink, with the
output port of 8255. Output the sequence in correct order to have the desired direction to rotate
the motor.
Assembly Language Program to rotate Stepper Motor in Clockwise direction
MODEL SMALL
.STACK 100
.DATA
PORTA EQU FFC0H ; PORTA ADDRESS
PORTB EQU FFC2H ; PORTB ADDRESS
PORTC EQU FFC4H ; PORTC ADDRESS
CWR EQU FFC6H ; CONTROL PORT ADDRESS
PHASEC EQU 03H
PHASEB EQU 06H ; SEQUENCE IN SERIES TO ROTATE MOTOR
PHASED EQU 0CH ; IN CLOCKWISE DIRECTION
PHASEA EQU 09H
.CODE
START:
MOV AL,@DATA
MOV DX,CTL
OUT DX,AL
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
AGAIN:
MOV AL,PHASEC
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP:
LOOP UP
MOV AL,PHASEB
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP1:
LOOP UP1
MOV AL,PHASED
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP2:
LOOP UP2
MOV AL,PHASEA
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP3:
LOOP UP3
JMP AGAIN ; REPEATE OUTPUT SEQUENCE
INT 03H
END START
MODEL SMALL
.STACK 100
.DATA
PORTA EQU FFC0H ; PORTA ADDRESS
PORTB EQU FFC2H ; PORTB ADDRESS
PORTC EQU FFC4H ; PORTC ADDRESS
CWR EQU FFC6H ; CONTROL PORT ADDRESS
PHASEC EQU 03H
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
.CODE
START:
MOV AL,@DATA
MOV DX,CTL
OUT DX,AL
AGAIN:
MOV AL,PHASEC
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP:
LOOP UP
MOV AL,PHASEA
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP1:
LOOP UP1
MOV AL,PHASED
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP2:
LOOP UP2
MOV AL,PHASEB
MOV DX,PORTC
OUT DX,AL
MOV CX,0FFFFH
UP3:
LOOP UP3
JMP AGAIN ; REPEATE OUTPUT SEQUENCE
INT 03H
END START
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV Instruction - The MOV instruction copies a word or a byte of data from a specified
source to a specified destination .
MOV op1, op2
Example:
MOV CX, 037AH
; MOV 037AH into the CX.
MOV AX, BX
;Copy the contents of register BX to AX
MOV DL,[BX]
;Copy byte from memory at BX
;to DL , BX contains the offset of byte in DS.
PUSH Instruction - PUSH source
PUSH Instruction - PUSH instruction decrements the stack pointer by 2 and copies a word
from a specified source to the location in the stack segment where the stack pointer pointes.
Example:
PUSH BX ;Decrement SP by 2 and copy BX to stack
PUSH DS ;Decrement SP by 2 and copy DS to stack
PUSH TABLE[BX] ;Decrement SP by 2 and copy word
;from memory in DS at
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
POP Instruction - POP instruction copies the word at the current top of the stack to the operand
specified by op then increments the stack pointer to point to the next stack.
Example:
POP DX
;Copy a word from top of the stack to
; DX and increments SP by 2.
POP DS
; Copy a word from top of the stack to
; DS and increments SP by 2.
POP TABLE [BX]
;Copy a word from top of stack to memory in DS with
;EA = TABLE + [BX].
XCHG Instruction - Exchange XCHG destination, source
XCHG Instruction - The Exchange instruction exchanges the contents of the register with the
contents of another register (or) the contents of the register with the contents of the memory
location. Direct memory to memory exchange are not supported.
XCHG op1, op2
The both operands must be the same size and one of the operand must always be a
register .
Example:
XCHG AX, DX
;Exchange word in AX with word in DX
XCHG BL, CH
;Exchange byte in BL with byte in CH
XCHG AL, Money [BX]
;Exchange byte in AL with byte
;in memory at EA.
XLAT/
XLATB Instruction - Translate a byte in AL
Example:
MOV BX,0000H
MOV AL,CODE
XLAT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
OUT Instruction - The OUT instruction copies a byte from AL or a word from AX or a double
from the accumulator to I/O port specified by op. Two forms of OUT instruction are available :
(1) Port number is specified by an immediate byte constant, ( 0- 255 ).It is also called as fixed
port form. (2) Port number is provided in the DX register( 0 65535 )
Example:
(1)
OUT 3BH, AL
Copy the contents of the AL to port 3Bh
OUT 2CH,AX
;Copy the contents of the AX to port 2Ch
(2)
MOV DX, 0FFF8H ;Load desired port address in DX
OUT DX, AL
; Copy the contents of AL to
;FFF8h
OUT DX, AX
;Copy content of AX to port
;FFF8H
LDS Instruction - Load register and Ds with words from memory LDS register, memory
address of first word
LDS Instruction - This instruction loads a far pointer from the memory address specified by
op2 into the DS segment register and the op1 to the register.
LDS op1, op2
Example:
LDS BX, [4326]
; copy the contents of the memory at
displacement 4326H in DS to BL, contents of the 4327H
to BH. Copy contents of
4328H and 4329H in DS to DS register.
LEA Instruction - Load effective address-LEA register, source
LEA Instruction - This instruction indicates the offset of the variable or memory location
named as the source and put this offset in the indicated 16 bit register.
Example:
LEA BX, PRICE
;Load BX with offset of PRICE
;in DS
LEA BP, SS:STAK ;Load BP with offset of STACK
;in SS
LEA CX, [BX][DI] ;Load CX with EA=BX + DI
LES Instruction - Load register and ES with words from memory LES register, memory
address of first word.
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
provided to make conversion of assembly language programs written for 8080 and 8085 to 8086
easier.
SAHF Instruction Copy AH register to low byte of flag register
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
SAHF Instruction - SAHF copies the value of bits 7, 6, 4, 2, 0 of the AH register into the SF,
ZF, AF, PF, and CF respectively. This instruction was provided to make easier conversion of
assembly language program written for 8080 and 8085 to 8086.
PUSHF Instruction - This instruction decrements the SP by 2 and copies the word in flag
register to the memory location pointed to by SP.
POPF Instruction - This instruction copies a word from the two memory location at the top of
the stack to flag register and increments the stack pointer by 2.
G.Vijaya Santhi,Asst.Prof
file:///D|/notes/8086inst.html
file:///D|/notes/8086inst.html
8086 Instruction
Set Summary
ASCII adjust
for addition,
subtraction,
division
Visit
our site
& get updates (POSTS) to your Email | TWITTER
| Mobile
| Face
book
| multiplication,
ORKUT
@(ASCII
FREE *
AAA, AAS, AAM,
codes 30-39)
AAD
Data Transfer Instructions
DAA, DAS
Transfer Instructions
MOV
IN, OUT
LEA
LDS, LES
JMP Unconditional jump (short ?127/8, near ?32K, far between segments)
Conditional jumps:
PUSH, POP Push word onto stack, pop word off stack
XCHG
XLAT
JA (JNBE) Jump if above (not below or equal)? +127, -128 range only
JAE (JNB) Jump if above or equal(not below)? +127, -128 range only
Logical Instructions
JB (JNAE) Jump if below (not above or equal)? +127, -128 range only
JBE (JNA) Jump if below or equal (not above)? +127, -128 range only
NOT Logical NOT of byte or word (one's complement)
JE (JZ)
JG (JNLE) Jump if greater (not less or equal)? +127, -128 range only
OR
JGE (JNL) Jump if greater or equal (not less)? +127, -128 range only
JL (JNGE) Jump if less (not greater nor equal)? +127, -128 range only
JLE (JNG) Jump if less or equal (not greater)? +127, -128 range only
JC, JNC
Jump if carry set, carry not set? +127, -128 range only
JO, JNO
JS, JNS
w
Ad w.
y
m o
in ur
: N sw
.R w
aj 8.t
ee k
v
JNP (JPO) Jump if no parity (parity odd)? +127, -128 range only
JP (JPE)
Loop control:
Arithmetic Instructions
LOOP
ADD, SUB
LOOPE (LOOPZ)
ADC, SBB
LOOPNE (LOOPNZ) Loop if not equal (not zero), count in CX, short jump to target address
INC, DEC
JCXZ
NEG
CMP
MUL, DIV
CALL, RET Call, return from procedure (inside or outside current segment)
CBW, CWD Convert byte to word, word to double word (useful before multiply/divide)
String Instructions
1 of 3
9/4/01 5:04 PM
2 of 3
9/4/01 5:04 PM
file:///D|/notes/8086inst.html
MOVS
SCAS
LODS, STOS
REP
Repeat
REPE, REPZ
STI, CLI
LAHF, SAHF
PUSHF, POPF
ESC
NOP No operation
WAIT Wait for TEST pin activity
HLT
Halt processor
9/4/01 5:04 PM
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
8259A
If we are working with an 8086, we have a problem here because the 8086 has
only two interrupt inputs, NMI and INTR.
If we save NMI for a power failure interrupt, this leaves only one interrupt for all
the other applications. For applications where we have interrupts from multiple
source, we use an external device called a priority interrupt controller ( PIC ) to
the interrupt signals into a single interrupt input on the processor.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INTA
D0-D7
Control Logic
Data Bus
Buffer
RD
WR
A0
Read/
Write
Logic
IN Service
Register
ISR
CS
CAS0
CAS1
CAS2
INT
Cascade
Buffer/
Comparator
SP / EN
Priority
Resolver
Interrupt
Request
Register
IRR
IR0
IR1
IR7
Internal Bus
Fig:1
Priority Resolver : This unit determines the priorities of the interrupt requests
appearing simultaneously. The highest priority is selected and stored into the
corresponding bit of ISR during INTA pulse. The IR0 has the highest priority
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
while the IR7 has the lowest one, normally in fixed priority mode. The priorities
however may be altered by programming the 8259A in rotating priority mode.
Interrupt Mask Register (IMR) : This register stores the bits required to mask
the interrupt inputs. IMR operates on IRR at the direction of the Priority Resolver.
Interrupt Control Logic: This block manages the interrupt and interrupt
acknowledge signals to be sent to the CPU for serving one of the eight interrupt
requests. This also accepts the interrupt acknowledge (INTA) signal from CPU
that causes the 8259A to release vector address on to the data bus.
Data Bus Buffer : This tristate bidirectional buffer interfaces internal 8259A bus
to the microprocessor system data bus. Control words, status and vector
information pass through data buffer during read or write operations.
Read/Write Control Logic: This circuit accepts and decodes commands from the
CPU. This block also allows the status of the 8259A to be transferred on to the
data bus.
Cascade Buffer/Comparator: This block stores and compares the IDs all the
8259A used in system. The three I/O pins CASO-2 are outputs when the 8259A is
used as a master. The same pins act as inputs when the 8259A is in slave mode.
The 8259A in master mode sends the ID of the interrupting slave device on these
lines. The slave thus selected, will send its preprogrammed vector address on the
data bus during the next INTA pulse.
CS: This is an active-low chip select signal for enabling RD and WR operations
of 8259A. INTA function is independent of CS.
WR : This pin is an active-low write enable input to 8259A. This enables it to
accept command words from CPU.
RD : This is an active-low read enable input to 8259A. A low on this line enables
8259A to release status onto the data bus of CPU.
D0-D7 : These pins from a bidirectional data bus that carries 8-bit data either to
control word or from status word registers. This also carries interrupt vector
information.
CAS0 CAS2 Cascade Lines : A signal 8259A provides eight vectored
interrupts. If more interrupts are required, the 8259A is used in cascade mode. In
cascade mode, a master 8259A along with eight slaves 8259A can provide upto
64 vectored interrupt lines. These three lines act as select lines for addressing the
slave 8259A.
PS/EN : This pin is a dual purpose pin. When the chip is used in buffered mode, it
can be used as buffered enable to control buffer transreceivers. If this is not used
in buffered mode then the pin is used as input to designate whether the chip is
used as a master (SP =1) or slave (EN = 0).
INT : This pin goes high whenever a valid interrupt request is asserted. This is
used to interrupt the CPU and is connected to the interrupt input of CPU.
IR0 IR7 (Interrupt requests) :These pins act as inputs to accept interrupt
request to the CPU. In edge triggered mode, an interrupt service is requested by
raising an IR pin from a low to a high state and holding it high until it is
acknowledged, and just by latching it to high level, if used in level triggered
mode.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
28
27
26
25
24
23
22
21
20
19
18
17
16
Vcc
A0
INTA
IR7
IR6
IR5
IR4
IR3
IR2
IR1
IR0
INT
SP / EN
CAS2
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
CS
WR
RD
D7
D6
D5
D4
D3
D2
D1
D0
CAS0
CAS1
GND
8259A
15
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
In the interrupt driven method, the CPU performs the main processing task till it
is interrupted by a service requesting peripheral device.
The net processing speed of these type of systems is high because the CPU serves
the peripheral only if it receives the interrupt request.
If more than one interrupt requests are received at a time, all the requesting
peripherals are served one by one on priority basis.
This method of interfacing may require additional hardware if number of
peripherals to be interfaced is more than the interrupt pins available with the CPU.
1.
2.
3.
4.
1.
2.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
ICW1
ICW2
A : IN CASCADE MODE ?
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
NO (SINGLE =1)
ICW3
NO (IC4 =0)
B : IS ICW4 NEEDED ?
YES (IC4 = 1)
ICW4
Ready to Accept
Interrupt Request
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
A0
0
D7
A7
D6
A6
D5
A5
A7-A5 of Interrupt
vector address MCs
80/85 mode only
D4
1
D3
D2
LTIM ADI
ICW1
D1
D0
SNGL IC4
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
1 = ICW4 Needed
0 = No ICW4
1 Single
0 - Cascaded
1 Level Triggered
0 Edge Triggered
ICW2
A0
1
D7
T7
D6
D5
D4
D3
T6
T5
T4
T3
D2
A10
A8
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
A0
D7
S7
S6
S5
S4
S3
D2
S2
D1
S1
D0
S0
A0
D7
D6
D5
D4
D3
D2
D1
D0
ID2
ID1
ID0
A0
D7
D6
ICW4
D5
D4
0
D3
SFNM BUF
D2
M/S
D1
D0
AEOI PM
ICW4: The use of this command word depends on the IC4 bit of ICW1. If IC4=1,
IC4 is used, otherwise it is neglected. The bit functions of ICW4 are described as
follow:
SFNM: If BUF = 1, the buffered mode is selected. In the buffered mode, SP/EN
acts as enable output and the master/slave is determined using the M/S bit of
ICW4.
M/S: If M/S = 1, 8259A is a master. If M/S =0, 8259A is slave. If BUF = 0, M/S
is to be neglected.
AEOI: If AEOI = 1, the automatic end of interrupt mode is selected.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
A0
D7
M7
D6
D5
D4
M6
M5
M4
D3
M3
D2
D1
D0
M2
M1
M0
1 Mask Set
0 Mask Reset
A0
0
Reset Special 0
1
Mask
Set Special
1
Mask
No
D7
D6
D5
ESMM SMM
D4
0
D3
D2
D1
D0
RR
RIS
Fig (b) :
0
1
0
1
1 Poll
Command
0 No Poll
Command
0
0
1
1
0
1
0
1
No Action
Read IRR on
next RD pulse
Read IRR on
next RD pulse
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
D7
R
D6
D5
D4
SL
EOI
D3
0
D2
D1
D0
L1
L2
1
1
0
0
2
0
1
0
3
0
1
0
4
0
0
1
5
1
0
1
6
0
1
1
7
1
1
1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0
0
0
0
L0
END OF
INTERRUPT
AUTOMATIC
ROTATION
SPECIFIC
ROTATION
0
0
1
1
0
1
1
0
0
1
0
0
0
1
1
1
1
1
1
0
0
1
0
0
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
When a mode that may disturb the fully nested structure is used, the 8259A is no
longer able to determine the last level acknowledged. In this case a specific EOI
command is issued to reset a particular ISR bit. An ISR bit that is masked by the
corresponding IMR bit, will not be cleared by non-specific EOI of 8259A, if it is
in special mask mode.
Automatic Rotation : This is used in the applications where all the interrupting
devices are of equal priority.
In this mode, an interrupt request IR level receives priority after it is served while
the next device to be served gets the highest priority in sequence. Once all the
device are served like this, the first device again receives highest priority.
Automatic EOI Mode : Till AEOI=1 in ICW4, the 8259A operates in AEOI
mode. In this mode, the 8259A performs a non-specific EOI operation at the
trailing edge of the last INTA pulse automatically. This mode should be used only
when a nested multilevel interrupt structure is not required with a single 8259A.
Specific Rotation : In this mode a bottom priority level can be selected, using L2,
L1 and L0 in OCW2 and R=1, SL=1, EOI=0.
The selected bottom priority fixes other priorities. If IR5 is selected as a bottom
priority, then IR5 will have least priority and IR4 will have a next higher priority.
Thus IR6 will have the highest priority.
These priorities can be changed during an EOI command by programming the
rotate on specific EOI command in OCW2.
Specific Mask Mode: In specific mask mode, when a mask bit is set in OCW1, it
inhibits further interrupts at that level and enables interrupt from other levels,
which are not masked.
Edge and Level Triggered Mode : This mode decides whether the interrupt
should be edge triggered or level triggered. If bit LTIM of ICW1 =0 they are edge
triggered, otherwise the interrupts are level triggered.
Reading 8259 Status : The status of the internal registers of 8259A can be read
using this mode. The OCW3 is used to read IRR and ISR while OCW1 is used to
read IMR. Reading is possible only in no polled mode.
Poll Command : In polled mode of operation, the INT output of 8259A is
neglected, though it functions normally, by not connecting INT output or by
masking INT input of the microprocessor. The poll mode is entered by setting
P=1 in OCW3.
The 8259A is polled by using software execution by microprocessor instead of the
requests on INT input. The 8259A treats the next RD pulse to the 8259A as an
interrupt acknowledge. An appropriate ISR bit is set, if there is a request. The
priority level is read and a data word is placed on to data bus, after RD is
activated. A poll command may give more than 64 priority levels.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
D7
D6
D5
D4
D3
D2
w2
w1
D0
w0
Binary code of
highest priority
level
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
If = 1, there is an interrupt
D1
Special Fully Nested Mode : This mode is used in more complicated system,
where cascading is used and the priority has to be programmed in the master
using ICW4. this is somewhat similar to the normal nested mode.
In this mode, when an interrupt request from a certain slave is in service, this
slave can further send request to the master, if the requesting device connected to
the slave has higher priority than the one being currently served. In this mode, the
master interrupt the CPU only when the interrupting device has a higher or the
same priority than the one current being served. In normal mode, other requests
than the one being served are masked out.
When entering the interrupt service routine the software has to check whether this
is the only request from the slave. This is done by sending a non-specific EOI can
be sent to the master, otherwise no EOI should be sent. This mode is important,
since in the absence of this mode, the slave would interrupt the master only once
and hence the priorities of the slave inputs would have been disturbed.
Buffered Mode: When the 83259A is used in the systems where bus driving
buffers are used on data buses. The problem of enabling the buffers exists. The
8259A sends buffer enable signal on SP/ EN pin, whenever data is placed on the
bus.
Cascade Mode : The 8259A can be connected in a system containing one master
and eight slaves (maximum) to handle upto 64 priority levels. The master controls
the slaves using CAS0-CAS2 which act as chip select inputs (encoded) for slaves.
In this mode, the slave INT outputs are connected with master IR inputs. When a
slave request line is activated and acknowledged, the master will enable the slave
to release the vector address during second pulse of INTA sequence.
The cascade lines are normally low and contain slave address codes from the
trailing edge of the first INTA pulse to the trailing edge of the second INTA
pulse. Each 8259A in the system must be separately initialized and programmed
to work in different modes. The EOI command must be issued twice, one for
master and the other for the slave.
A separate address decoder is used to activate the chip select line of each 8259A.
Following Fig shows the details of the circuit connections of 8259A in cascade
scheme.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
ADDRESS BUS
A1
A1
A1
CONTROL BUS
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
DATA BUS
INT
CAS0-CAS2
A0
CS A0 D0-D7 INT
Master
SP/E
M7 M6 M5 M4 M3 M2 M1 M0
Vcc
CS A0 D0-D7 INT
SP/E
Slave 0
IR7
IR0
INT
CS
INT
D0-D7
Slave 7
IR7
IR0
INT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 13,15 - Read DASD Type (XT BIOS from 1/10/86 & newer)
INT 13,16 - Change of Disk Status (XT BIOS from 1/10/86 & newer)
INT 13,17 - Set DASD Type for Format (XT BIOS from 1/10/86 & newer)
INT 13,18 - Set Media Type for Format (BIOS date specific)
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 14,5 - Extended Communication Port Control (PS/2 & later systems)
INT 15 - System BIOS Services
INT 15,21 - Power On Self Test (POST) Error Log (PS/2 except 30)
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 15,C1 - Return Extended BIOS Data Area Segment (PS/2 only)
INT 15,C2 - Pointing Device BIOS Interface (PS/2 only)
INT 15,C3 - Enable/Disable Watchdog Timer (PS/2)
INT 15,C4 - Programmable Option Select (PS/2)
INT 16 - Keyboard BIOS Services
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
INT 16,10 - Extended Wait for Keypress and Read Character (AT+)
INT 16,11 - Extended Get Keyboard Status (AT+)
INT 16,12 - Extended Get Keyboard Status (AT+)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 1A,2 - Read Time From Real Time Clock (XT 286,AT,PS/2)
INT 1A,3 - Set Time on Real Time Clock (XT 286,AT,PS/2)
INT 1A,4 - Read Real Time Clock Date (XT 286,AT,PS/2)
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 33,C - Set Mouse User Defined Subroutine and Input Mask
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 33,24 - Get Driver Version, Mouse Type & IRQ Number
INT 67,44 - Map Logical Page Into Physical Page Window (LIM EMS)
INT 67,45 - Release Handle and Memory Pages (LIM EMS)
INT 67,46 - Get EMM Version (LIM EMS)
INT 67,4D - Get Page Count for All Handles (LIM EMS)
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INT 67,5C - Prepare Expanded Memory for Warm Boot (LIM EMS 4.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Serial transmission is often preferred over parallel transmission, even though it has a lower
transfer rate, due to its simplicity, low cost and ease of use. Many peripherals also do not require
the high data rates of a parallel interface.
Baud rate
The number of changes/symbols transmitted, per second. When there are only two states, this is
equal to the Bit rate.
Bit rate
The rate at which meaningful information is sent - the bit rate less the overhead of start and stop
bits.
Asynchronous Serial Data Transmission
The asynchronous serial interface is so called because the transmitted and received data are not
synchronised over any extended period of time and therefore no special means of synchronising
the clocks at the transmitter and receiver is necessary. The fundamental problem lies in how to
split the data stream into individual bits and how to then reconstruct the original data. The format
of the data on a serial data link is in fact simple, and is shown in Figure below. Data is grouped
and transferred in characters, where one character is a unit comprising 7 or 8 bits of information
plus 2 to 4 control bits. The idle state is referred to as the mark level and traditionally
corresponds to a logical 1 level. A character is transmitted by placing the line in the space
level (logical 0) for one period T, then the information is sent bit by bit, with each bit T seconds
long, then the transmitter calculates the parity bit and transmits it and finally one or two stop bits
are sent by returning the line to mark level.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The data word length may be 7 or 8 bits with odd, even, or no parity bits plus either 1 or 2 stop
bits. This allows for 12 different possible formats for serial transmission. Also, there are at least
7 different commonly used values for the bit period T. Thus, connecting two devices via a serial
link may be difficult due to all the available options.
At the receiving end, the receiver monitors the link, looking for the start bit, and once detected,
the receiver waits until the end of the start bit and then samples the next N bits at their centres
using a locally generated clock. Once the character has been assembled from the received bits,
the parity is checked, and if the calculated parity does not agree with the received parity bit, a
parity error flag is set to indicate a transmission error. The most critical aspect is the receiver
timing. The falling edge of the start bit triggers the receiver's local clock, which samples each
incoming bit at its nominal centre. Suppose the receiver clock waits T/2 seconds from the falling
edge of a start bit and samples the incoming data every T seconds thereafter until the stop bit has
been sampled. Let us assume that the receiver clock is running slow, so that a sample is taken
every T+dt seconds. The first bit of the data is thus sampled at (T+dt)/2 + (T+dt) seconds after
the falling edge of the start bit. The stop bit is thus sampled at time (T+dt)/2 + N(T+dt), where N
is the number of bits in the character following the start bit. The total accumulated error in
sampling is thus (T+dt)/2 + N(T+dt) - (T/2+NT), or (2N+1)dt/2 seconds. This situation is shown
in Figure below.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
For correct operation, the stop bit is sampled within T/2 seconds of its centre.
Thus, if N=9 for a 7-bit character with one stop bit and one parity bit, the maximum permissible
error is 100/19 = 5%. Fortunately, today's clocks are all crystal controlled and the error between
two clocks of the same frequency is often less than a fraction of a percent.
The most obvious disadvantage of asynchronous serial transfer is the need for start, stop and
parity bits for each transmitted character. If 7-bit characters are used, the overall efficiency is
only 7/(7+3) = 70%. Another problem is when asynchronous transfer is used to, for example,
dump binary data onto a storage device: If the data is arranged in 8-bit bytes and all 256 values
represent valid binary data it is difficult to embed control characters (e.g. tape start or stop)
within the data stream because the same character must be used both for pure data and control
purposes.
The type of asynchronous serial data link described in previous sections is widely used to link
processors to relatively slow peripherals such as printers and terminals. Where information must
be transferred, for example, between individual computers in a network, synchronous serial data
transmission is more popular. In synchronous serial data transmission, the information is
transmitted continuously without gaps between adjacent groups of bits. Note that synchronous
data links are often used to transmit entire blocks of data instead of ASCII-encoded characters.
As this type of link involves long streams of data, the clocks at the receiving and transmitting
end must be permanently synchronised. Of course, one could simply add a clock line to the link
where the transmitter's clock signal is passed to the receiver. However, this requires an additional
line and is thus an unpopular choice. A better solution is to encode the data in such a way that the
synchronising signal is included in the data signal. The figure below shows one of the many
methods which may be used. In this case the data is phase-encoded (or Manchester encoded) by
combining the clock signal with the data signal. A logical one is thus represented by a positive
transition in the centre of the bit and a logical zero by a negative transition. At the receiver, the
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
data signal may easily be split into the clock and pure data components. Integrated circuits that
perform this modulation and demodulation are readily available.
Having divided the incoming data stream into individual data elements (i.e. bits), the next step is
to group the bits into meaningful units. The incoming data must be examined for recognisable bit
groups which signify the beginning of a block of data, the end of it or some other control
character.
Parity
There may well be noise on a communications line, and it is helpful to have some check that the
correct information has arrived. One common test is Parity. Send a parity bit set so that the
number of 1 bits sent (data + parity) is odd.
Parity is normally taken as odd, because a single pulse on the line, taken as a start bit, records as
a bad byte.
The parity check will detect one erroneous bit in each byte. There are more serious methods of
encoding data that can send messages down noisy lines, and recover from erroneous bits.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Receive data
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
8251 (USART)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
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
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.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The 8251 functional configuration is programmed 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.
Control Words
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."
Items set by mode instruction are as follows:
Synchronous/asynchronous mode
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
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.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
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.
Items to be set by command are as follows:
Transmit Enable/Disable
Receive Enable/Disable
DTR, RTS Output of data.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Status Word
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
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)
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
This is bidirectional data bus which receive control words and transmits data from the CPU and
sends status words and received data to CPU.
RESET (Input terminal)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
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 (Input terminal)
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.
C/D (Input terminal)
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 wont be in "standby status"; only setting CS = High.
TXD (output terminal)
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.
TXRDY (output terminal)
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
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
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.
TXEMPTY (Output terminal)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
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)
TXC (Input terminal)
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.
RXD (input terminal)
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.
SYNDET/BD (Input or output terminal)
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.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
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.
DSR (Input terminal)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
This is an input port for MODEM interface. The input status of the terminal can be recognized
by the CPU reading status words.
DTR (Output terminal)
This is an output port for MODEM interface. It is possible to set the status of DTR by a
command.
CTS (Input terminal)
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.
RTS (Output terminal)
This is an output port for MODEM interface. It is possible to set the status RTS by a command.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The *MC1489 (aka 75189) is used as a level translator to invert the positive logic
signals from the UART into NRZi to be transmitted. The data signal from the UART (pin
25) is input on pin 1 of the MC1489 and the output comes from pin 3 of the MC1489. This
output is sent, via an RS-232 cable, to the Receive Data line of the computer (pin 3 of DTE).
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
It would have been more appropriate to use the MC1488, Line Driver, since it is the chip
that is typically used to perform the function of TTL-to-RS232 conversion. I couldn't find
this chip in the lab's supply cabinet, so the MC1489 was used, which still inverts the input
and provides an output that can drive a short RS232 cable.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Electrical signal characteristics such as voltage levels, signaling rate, timing and slewrate of signals, voltage withstand level, short-circuit behavior, and maximum load
capacitance.
Interface mechanical characteristics, pluggable connectors and pin identification.
Functions of each circuit in the interface connector.
Standard subsets of interface circuits for selected telecom applications.
Details of character format and transmission bit rate are controlled by the serial port hardware,
often a single integrated circuit called a UART that converts data from parallel to asynchronous
start-stop serial form. Details of voltage levels, slew rate, and short-circuit behavior are typically
controlled by a line-driver that converts from the UART's logic levels to RS-232 compatible
signal levels, and a receiver that converts from RS-232 compatible signal levels to the UART's
logic levels
Limitations of the standard
Because the application of RS-232 has extended far beyond the original purpose of
interconnecting a terminal with a modem, successor standards have been developed to address
the limitations. Issues with the RS-232 standard include:
The large voltage swings and requirement for positive and negative supplies increases
power consumption of the interface and complicates power supply design. The voltage
swing requirement also limits the upper speed of a compatible interface.
Single-ended signaling referred to a common signal ground limits the noise immunity and
transmission distance.
Multi-drop connection among more than two devices is not defined. While multi-drop
"work-arounds" have been devised, they have limitations in speed and compatibility.
Asymmetrical definitions of the two ends of the link make the assignment of the role of a
newly developed device problematic; the designer must decide on either a DTE-like or
DCE-like interface and which connector pin assignments to use.
The handshaking and control lines of the interface are intended for the setup and
takedown of a dial-up communication circuit; in particular, the use of handshake lines for
flow control is not reliably implemented in many devices.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
No method is specified for sending power to a device. While a small amount of current
can be extracted from the DTR and RTS lines, this is only suitable for low power devices
such as mice.
While the standard recommends a 25-way connector and its pinout, the connector is large
by current standards
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Standard details
In RS-232, user data is sent as a time-series of bits. Both synchronous and asynchronous
transmissions are supported by the standard. In addition to the data circuits, the standard defines
a number of control circuits used to manage the connection between the DTE and DCE. Each
data or control circuit only operates in one direction, that is, signaling from a DTE to the
attached DCE or the reverse. Since transmit data and receive data are separate circuits, the
interface can operate in a full duplex manner, supporting concurrent data flow in both directions.
The standard does not define character framing within the data stream, or character encoding.
Voltage levels
Diagrammatic oscilloscope trace of voltage levels for an uppercase ASCII "K" character (0x4b)
with 1 start bit, 8 data bits, 1 stop bit
The RS-232 standard defines the voltage levels that correspond to logical one and logical zero
levels. Valid signals are plus or minus 3 to 15 volts. The range near zero volts is not a valid RS232 level; logic one is defined as a negative voltage, the signal condition is called marking, and
has the functional significance of OFF. Logic zero is positive, the signal condition is spacing,
and has the function ON. The standard specifies a maximum open-circuit voltage of 25 volts;
signal levels of 5 V,10 V,12 V, and 15 V are all commonly seen depending on the power
supplies available within a device. RS-232 drivers and receivers must be able to withstand
indefinite short circuit to ground or to any voltage level up to 25 volts. The slew rate, or how
fast the signal changes between levels, is also controlled.
Because the voltage levels are higher than logic levels typically used by integrated circuits,
special intervening driver circuits are required to translate logic levels. These also protect the
device's internal circuitry from short circuits or transients that may appear on the RS-232
interface, and provide sufficient current to comply with the slew rate requirements for data
transmission.
Because both ends of the RS-232 circuit depend on the ground pin being zero volts, problems
will occur when connecting machinery and computers where the voltage between the ground pin
on one end, and the ground pin on the other is not zero. This may also cause a hazardous ground
loop.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Unused interface signals terminated to ground will have an undefined logic state. Where it is
necessary to permanently set a control signal to a defined state, it must be connected to a voltage
source that asserts the logic 1 or logic 0 level. Some devices provide test voltages on their
interface connectors for this purpose.
Connectors
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
RS-232 devices may be classified as Data Terminal Equipment (DTE) or Data Communications
Equipment (DCE); this defines at each device which wires will be sending and receiving each
signal. The standard recommended but did not make mandatory the D-subminiature 25 pin
connector. In general and according to the standard, terminals and computers have male
connectors with DTE pin functions, and modems have female connectors with DCE pin
functions. Other devices may have any combination of connector gender and pin definitions.
Many terminals were manufactured with female terminals but were sold with a cable with male
connectors at each end; the terminal with its cable satisfied the recommendations in the standard.
Presence of a 25 pin D-sub connector does not necessarily indicate an RS-232-C compliant
interface. For example, on the original IBM PC, a male D-sub was an RS-232-C DTE port (with
a non-standard current loop interface on reserved pins), but the female D-sub connector was used
for a parallel Centronics printer port. Some personal computers put non-standard voltages or
signals on some pins of their serial ports.
The standard specifies 20 different signal connections. Since most devices use only a few
signals, smaller connectors can often be used. For example, the 9 pin DE-9 connector was used
by most IBM-compatible PCs since the IBM PC AT, and has been standardized as TIA-574.
More recently, modular connectors have been used. Most common are 8P8C connectors.
Standard EIA/TIA 561 specifies a pin assignment, but the "Yost Serial Device Wiring Standard"
invented by Dave Yost (and popularized by the Unix System Administration Handbook) is
common on Unix computers and newer devices from Cisco Systems. Many devices don't use
either of these standards. 10P10C connectors can be found on some devices as well. Digital
Equipment Corporation defined their own DECconnect connection system which was based on
the Modified Modular Jack connector. This is a 6 pin modular jack where the key is offset from
the center position. As with the Yost standard, DECconnect uses a symmetrical pin layout which
enables the direct connection between two DTEs. Another common connector is the DH10
header connector common on motherboards and add-in cards which is usually converted via a
cable to the more standard 9 pin DE-9 connector (and frequently mounted on a free slot plate or
other part of the housing).
Pinouts
The following table lists commonly-used RS-232 signals and pin assignments.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Signal
Name
Origin
Abbrevation DTE DCE
DB-25
DE-9
EIA/TIA 561 Yost
(TIA-574)
Common Ground
Protective Ground
PG
Transmitted Data
TxD
Received Data
RxD
20
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
4,5
DSR
Request To Send
RTS
Clear To Send
CTS
Carrier Detect
DCD
Ring Indicator
RI
22
The signals are named from the standpoint of the DTE. The ground signal is a common return for
the other connections; it appears on two pins in the Yost standard but is the same signal. The
DB-25 connector includes a second "protective ground" on pin 1. Connecting this to pin 7 (signal
reference ground) is a common practice but not recommended.
Use of a common ground is one weakness of RS-232: if the two devices are far enough apart or
on separate power systems, the ground will degrade between them and communications will fail,
which is a difficult condition to trace.
Note that EIA/TIA 561 combines DSR and RI[5][6], and the Yost standard combines DSR and
DCD.
Signals
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Asserted by DCE to acknowledge RTS and allow DTE to transmit. This signaling was
originally used with half-duplex modems and by slave terminals on multidrop lines: The
DTE would raise RTS to indicate that it had data to send, and the modem would raise
CTS to indicate that transmission was possible. For the modern usage of "RTS/CTS
handshaking," see the section of that name.
Data Terminal Ready (DTR)
Asserted by DTE to indicate that it is ready to be connected. If the DCE is a modem, this
may "wake up" the modem, bringing it out of a power saving mode. This behaviour is
seen quite often in modern PSTN and GSM modems. When this signal is de-asserted, the
modem may return to its standby mode, immediately hanging up any calls in progress.
Data Set Ready (DSR)
Asserted by DCE to indicate the DCE is powered on and is ready to receive commands or
data for transmission from the DTE. For example, if the DCE is a modem, DSR is
asserted as soon as the modem is ready to receive dialing or other commands; DSR is not
dependent on the connection to the remote DCE (see Data Carrier Detect for that
function). If the DCE is not a modem (e.g. a null modem cable or other equipment), this
signal should be permanently asserted (set to 0), possibly by a jumper to another signal.
Data Carrier Detect (DCD)
Asserted by DCE when a connection has been established with remote equipment.
Ring Indicator (RI)
Asserted by DCE when it detects a ring signal from the telephone line.
Cables
The standard does not define a maximum cable length but instead defines the maximum
capacitance that a compliant drive circuit must tolerate. A widely-used rule-of-thumb indicates
that cables more than 50 feet (15 metres) long will have too much capacitance, unless special
cables are used. By using low-capacitance cables, full speed communication can be maintained
over larger distances up to about 1,000 feet.[7] For longer distances, other signal standards are
better suited to maintain high speed.
Since the standard definitions are not always correctly applied, it is often necessary to consult
documentation, test connections with a breakout box, or use trial and error to find a cable that
works when interconnecting two devices. Connecting a fully-standard-compliant DCE device
and DTE device would use a cable that connects identical pin numbers in each connector (a socalled "straight cable"). "Gender changers" are available to solve gender mismatches between
cables and connectors. Connecting devices with different types of connectors requires a cable
that connects the corresponding pins according to the table above. Cables with 9 pins on one end
and 25 on the other are common. Manufacturers of equipment with 8P8C connectors usually
provide a cable with either a DB-25 or DE-9 connector (or sometimes interchangeable
connectors so they can work with multiple devices). Poor-quality cables can cause false signals
by crosstalk between data and control lines (such as Ring Indicator).
Conventions
For functional communication through a serial port interface, conventions of bit rate, character
framing, communications protocol, character encoding, data compression, and error detection,
not defined in RS 232, must be agreed to by both sending and receiving equipment. For example,
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
consider the serial ports of the original IBM PC. This implementation used an 8250 UART using
asynchronous start-stop character formatting with 7 or 8 data bits per frame, usually ASCII
character coding, and data rates programmable between 75 bits per second and 115,200 bits per
second. Data rates above 20,000 bits per second are out of the scope of the standard, although
higher data rates are sometimes used by commercially manufactured equipment. In the particular
case of the IBM PC, baud rates were programmable with arbitrary values, so that a PC could be
connected to, for example, MIDI music controllers (31,250 bits per second) or other devices not
using the rates typically used with modems. Since most devices do not have automatic baud rate
detection, users must manually set the baud rate (and all other parameters) at both ends of the
RS-232 connection.
RTS/CTS handshaking
In older versions of the specification, RS-232's use of the RTS and CTS lines is asymmetric: The
DTE asserts RTS to indicate a desire to transmit to the DCE, and the DCE asserts CTS in
response to grant permission. This allows for half-duplex modems that disable their transmitters
when not required, and must transmit a synchronization preamble to the receiver when they are
re-enabled. This scheme is also employed on present-day RS-232 to RS-485 converters, where
the RS-232's RTS signal is used to ask the converter to take control of the RS-485 bus - a
concept that doesn't otherwise exist in RS-232. There is no way for the DTE to indicate that it is
unable to accept data from the DCE.
A non-standard symmetric alternative, commonly called "RTS/CTS handshaking," was
developed by various equipment manufacturers: CTS indicates permission from the DCE for the
DTE to send data to the DCE (and is controlled by the DCE independent of RTS), and RTS
indicates permission from the DTE for the DCE to send data to the DTE. This was eventually
codified in version RS-232-E (actually TIA-232-E by that time) by defining a new signal, "RTR
(Ready to Receive)," which is CCITT V.24 circuit 133. TIA-232-E and the corresponding
international standards were updated to show that circuit 133, when implemented, shares the
same pin as RTS (Request to Send), and that when 133 is in use, RTS is assumed by the DCE to
be ON at all times.[8]
Thus, with this alternative usage, one can think of RTS asserted (logic 0) meaning that the DTE
is indicating it is "ready to receive" from the DCE, rather than requesting permission from the
DCE to send characters to the DCE.
3-wire and 5-wire RS-232
A minimal "3-wire" RS-232 connection consisting only of transmit data, receive data, and
ground, is commonly used when the full facilities of RS-232 are not required. Even a two-wire
connection (data and ground) can be used if the data flow is one way (for example, a digital
postal scale that periodically sends a weight reading, or a GPS receiver that periodically sends
position, if no configuration via RS-232 is necessary). When only hardware flow control is
required in addition to two-way data, the RTS and CTS lines are added in a 5-wire version.
Seldom used features
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
The EIA-232 standard specifies connections for several features that are not used in most
implementations. Their use requires the 25-pin connectors and cables, and of course both the
DTE and DCE must support them.
Signal rate selection
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The DTE or DCE can specify use of a "high" or "low" signaling rate. The rates as well as which
device will select the rate must be configured in both the DTE and DCE. The prearranged device
selects the high rate by setting pin 23 to ON.
Loopback testing
Many DCE devices have a loopback capability used for testing. When enabled, signals are
echoed back to the sender rather than being sent on to the receiver. If supported, the DTE can
signal the local DCE (the one it is connected to) to enter loopback mode by setting pin 18 to ON,
or the remote DCE (the one the local DCE is connected to) to enter loopback mode by setting pin
21 to ON. The latter tests the communications link as well as both DCE's. When the DCE is in
test mode it signals the DTE by setting pin 25 to ON.
A commonly used version of loopback testing doesn't involve any special capability of either
end. A hardware loopback is simply a wire connecting complementary pins together in the same
connector (see loopback).
Loopback testing is often performed with a specialized DTE called a Bit Error Rate Tester (see
Bit Error Rate Test).
Timing signals
Some synchronous devices provide a clock signal to synchronize data transmission, especially at
higher data rates. Two timing signals are provided by the DCE on pins 15 and 17. Pin 15 is the
transmitter clock, or send timing (ST); the DTE puts the next bit on the data line (pin 2) when
this clock transitions from OFF to ON (so it is stable during the ON to OFF transition when the
DCE registers the bit). Pin 17 is the receiver clock, or receive timing (RT); the DTE reads the
next bit from the data line (pin 3) when this clock transitions from ON to OFF.
Alternatively, the DTE can provide a clock signal, called transmitter timing (TT), on pin 24 for
transmitted data. Again, data is changed when the clock transitions from OFF to ON and read
during the ON to OFF transition. TT can be used to overcome the issue where ST must traverse a
cable of unknown length and delay, clock a bit out of the DTE after another unknown delay, and
return it to the DCE over the same unknown cable delay. Since the relation between the
transmitted bit and TT can be fixed in the DTE design, and since both signals traverse the same
cable length, using TT eliminates the issue. TT may be generated by looping ST back with an
appropriate phase change to align it with the transmitted data. ST loop back to TT lets the DTE
use the DCE as the frequency reference, and correct the clock to data timing.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Secondary channel
Data can be sent over a secondary channel (when implemented by the DTE and DCE devices),
which is equivalent to the primary channel. Pin assignments are described in following table:
Signal
7 (same as primary)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Common Ground
Pin
16
13
12
Related standards
Other serial signaling standards may not interoperate with standard-compliant RS-232 ports. For
example, using the TTL levels of near +5 and 0 V puts the mark level in the undefined area of
the standard. Such levels are sometimes used with NMEA 0183-compliant GPS receivers and
depth finders.
A 20 mA current loop uses the absence of 20 mA current for high, and the presence of current in
the loop for low; this signaling method is often used for long-distance and optically isolated
links. Connection of a current-loop device to a compliant RS-232 port requires a level translator.
Current-loop devices can supply voltages in excess of the withstand voltage limits of a compliant
device. The original IBM PC serial port card implemented a 20 mA current-loop interface, which
was never emulated by other suppliers of plug-compatible equipment.
Other serial interfaces similar to RS-232:
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
// MODE WORD //
MOV CX,2
D4:LOOP D4
;and delay
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
// COMMAND WORD//
MOV DX,0FFF2H
TEST2:IN AL,DX
AND AL,00000001B
JZ TEST2
MOV DX,0FFF2H
IN AL,DX
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
ARITHMETIC INSTRUCTIONS
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ADDITION INSTRUCTIONS:
ADD
ADC
INC
AAA
DAA
SUBTRACTION INSTRUCTIONS:
SUB
SBB
DEC
NEG
CMP
AAS
DAS
MULTIPLICATION INSTRUCTIONS:
MUL
IMUL
AAM
DIVISION INSTRUCTIONS:
DIV
IDIV
AAD
CBW
CWD
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ADD Instruction - These instructions add a number from source to a number from some
destination and put the result in the specified destination. The add with carry instruction ADC,
also add the status of the carry flag into the result. The source and destination must be of same
type , means they must be a byte location or a word location.If you want to add a byte to a word,
you must copy the byte to a word location and fill the upper byte of the word with zeroes before
adding.
ADC Instruction - Add with carry.
EXAMPLE:
ADD AL,74H
ADC CL,BL
ADD DX, BX
ADD CL, BL
ADD CL, BL
INC Instruction - INC instruction adds one to the operand and sets the flag according to the
result. INC instruction is treated as an unsigned binary number.
Example:
; AX = 7FFFh
INC AX
;After this instruction AX = 8000h
INC BL
; Add 1 to the contents of BL register
INC CL
; Add 1 to the contents of CX register.
AAA Instruction - AAA converts the result of the addition of two valid unpacked BCD digits
to a valid 2-digit BCD number and takes the AL register as its implicit operand. Two operands of
the addition must have its lower 4 bits contain a number in the range from 0-9.The AAA
instruction then adjust AL so that it contains a correct BCD digit. If the addition produce carry
(AF=1), the AH register is incremented and the carry CF and auxiliary carry AF flags are set to
1. If the addition did not produce a decimal carry, CF and AF are cleared to 0 and AH is not
altered. In both cases the higher 4 bits of AL are cleared to 0.AAA will adjust the result of the
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
two ASCII characters that were in the range from 30h (0) to 39h(9).This is because the
lower 4 bits of those character fall in the range of 0-9.The result of addition is not a ASCII
character but it is a BCD digit.
Example:
;Clear AH for MSD
;BCD 6 in AL
;Add BCD 5 to digit in AL
;AH=1, AL=1 representing BCD 11.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV AH,0
MOV AL,6
ADD AL,5
AAA
SUB CX, BX
SUBB CH, AL
;CX BX . Result in CX
; Subtract contents of AL and
;contents CF from contents of CH .
;Result in CH
SUBB AX, 3427H ;Subtract immediate number
;from AX
Example:
Subtracting unsigned number
; CL = 10011100 = 156 decimal
; BH = 00110111 = 55 decimal
SUB CL, BH
; CL = 01100101 = 101 decimal
; CF, AF, SF, ZF = 0, OF, PF = 1
Subtracting signed number
; CL = 00101110 = + 46 decimal
; BH = 01001010= + 74 decimal
SUB CL, BH ;CL = 11100100 = - 28 decimal
;CF = 1, AF, ZF =0,
;SF = 1 result negative
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
NEG Instruction - NEG performs the twos complement subtraction of the operand from zero
and sets the flags according to the result.
;AX = 2CBh
NEG AX
;after executing NEG result AX =FD35h.
Example:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
NEG AL
;Replace number in AL with its 2s complement
NEG BX
;Replace word in BX with its 2s complement
NEG BYTE PTR[BX]
; Replace byte at offset BX in
; DS with its 2s complement
CMP Instruction-Compares two operands result is not stored anywhere, flags are set (OF, SF,
ZF, AF, PF, CF) according to result.
Example:
MOV AL, 5
MOV BL, 5
CMP AL, BL
; AL = 5, ZF = 1 (so equal!)
AAS Instruction - AAS converts the result of the subtraction of two valid unpacked BCD digits
to a single valid BCD number and takes the AL register as an implicit operand. The two
operands of the subtraction must have its lower 4 bit contain number in the range from 0 to 9
.The AAS instruction then adjust AL so that it contain a correct BCD digit.
MOV AX,0901H
;BCD 91
SUB AL, 9
;Minus 9
AAS
; Give AX =0802 h (BCD 82)
(a)
;AL =0011 1001 =ASCII 9
;BL=0011 0101 =ASCII 5
SUB AL, BL
;(9 - 5) Result :
;AL = 00000100 = BCD 04,CF = 0
AAS
;Result :
;AL=00000100 =BCD 04
;CF = 0 NO Borrow required
(b)
;AL = 0011 0101 =ASCII 5
;BL = 0011 1001 = ASCII 9
SUB AL, BL
;( 5 - 9 ) Result :
;AL = 1111 1100 = - 4
; in 2s complement CF = 1
AAS
;Results :
;AL = 0000 0100 =BCD 04
;CF = 1 borrow needed
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Example:
AAM Instruction - AAM converts the result of the multiplication of two valid unpacked BCD
digits into a valid 2-digit unpacked BCD number and takes AX as an implicit operand.
To give a valid result the digits that have been multiplied must be in the range of 0 9 and the
result should have been placed in the AX register. Because both operands of multiply are
required to be 9 or less, the result must be less than 81 and thus is completely contained in AL.
AAM unpacks the result by dividing AX by 10, placing the quotient (MSD) in AH and the
remainder (LSD) in AL.
Example:
MOV AL, 5
MOV BL, 7
MUL BL
;Multiply AL by BL , result in AX
AAM
;After AAM, AX =0305h (BCD 35)
DIV Instruction - Unsigned divide-Div source
DIV Instruction-When a double word is divided by a word, the most significant word of
the double word must be in DX and the least significant word of the double word must be
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
in AX. After the division AX will contain the 16 bit result (quotient ) and DX will contain a 16
bit remainder. Again , if an attempt is made to divide by zero or quotient is too large to fit in AX
( greater than FFFFH ) the 8086 will do a type of 0 interrupt .
Example:
DIV CX
; (Quotient) AX= (DX:AX)/CX
: (Reminder) DX=(DX:AX)%CX
For DIV the dividend must always be in AX or DX and AX, but
the source of the divisor can be a register or a memory location specified by one of the 24
addressing modes.
If you want to divide a byte by a byte, you must first put the dividend byte in AL and fill AH
with all 0s . The SUB AH,AH instruction is a quick way to do.
If you want to divide a word by a word, put the dividend word in AX and fill DX with all 0s.
The SUB DX,DX instruction does this quickly.
Example:
; AX = 37D7H = 14, 295 decimal
; BH = 97H = 151 decimal
DIV BH ;AX / BH
; AX = Quotient = 5EH = 94 decimal
; AH = Remainder = 65H = 101 decimal
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
CBW Instruction - CBW converts the signed value in the AL register into an equivalent 16 bit
signed value in the AX register by duplicating the sign bit to the left. This instruction copies the
sign of a byte in AL to all the bits in AH. AH is then said to be the sign extension of AL.
Example:
; AX = 00000000 10011011 = - 155 decimal
CBW
; Convert signed byte in AL to signed word in AX.
; Result in AX = 11111111 10011011
; = - 155 decimal
into an equivalent 32 bit signed value in DX: AX register pair by duplicating the sign bit
to the left. The CWD instruction sets all the bits in the DX register to the same sign bit of the AX
register. The effect is to create a 32- bit signed result that has same integer value as the original
16 bit operand.
Example:
Assume AX contains C435h. If the CWD instruction is executed, DX
will contain FFFFh since bit 15 (MSB) of AX was 1. Both the original value of AX
(C435h) and resulting value of DX : AX (FFFFC435h) represents the same signed
number.
Example:
;DX = 00000000 00000000
;AX = 11110000 11000111 = - 3897 decimal
CWD
;Convert signed word in AX to signed double
;word in DX:AX
;Result DX = 11111111 11111111
;AX = 11110000 11000111 = -3897 decimal .
G.Vjaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
LOGICAL INSTRUCTIONS:
NOT
AND
OR
XOR
TEST
SHIFT INSTRUCTIONS:
SHL / SAL
SHR
SAR
ROTATE INSTRUCTIONS:
ROL
ROR
RCL
RCR
NOT Instruction - NOT perform the bitwise complement of op and stores the result back into
op.
NOT op
Example :
NOT BX
;Complement contents of BX register.
;DX =F038h
NOT DX
;after the instruction DX = 0FC7h
AND Instruction - This Performs a bitwise Logical AND of two operands. The result of the
operation is stored in the op1 and used to set the flags.
AND op1, op2
To perform a bitwise AND of the two operands, each bit of the result is set to 1 if and only if the
corresponding bit in both of the operands is 1, otherwise the bit in the result I cleared to 0 .
Example:
AND BH, CL
;AND byte in CL with byte in BH
;result in BH
AND BX,00FFh
;AND word in BX with immediate
;00FFH. Mask upper byte, leave
;lower unchanged
AND CX,[SI]
; AND word at offset [SI] in data
;segment with word in CX
;register . Result in CX register .
;BX = 10110011 01011110
AND BX,00FFh
;Mask out upper 8 bits of BX
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
OR Instruction - OR instruction perform the bit wise logical OR of two operands .Each bit of
the result is cleared to 0 if and only if both corresponding bits in each operand are 0, other wise
the bit in the result is set to 1.
OR op1, op2
Examples :
OR AH, CL
;CL ORed with AH, result in AH.
;CX = 00111110 10100101
OR CX,FF00h
;OR CX with immediate FF00h
;result in CX = 11111111 10100101
;Upper byte are all 1s lower bytes
;are unchanged.
XOR Instruction - XOR performs a bit wise logical XOR of the operands specified by op1 and
op2. The result of the operand is stored in op1 and is used to set the flag.
XOR op1, op2
Example : ( Numerical )
; BX = 00111101 01101001
;CX = 00000000 11111111
XOR BX, CX
;Exclusive OR CX with BX
;Result BX = 00111101 10010110
TEST Instruction - This instruction ANDs the contents of a source byte or word with the
contents of specified destination word. Flags are updated but neither operand is changed . TEST
instruction is often used to set flags before a condition jump instruction
Examples:
TEST AL, BH
;AND BH with AL. no result is
;stored . Update PF, SF, ZF
TEST CX, 0001H ;AND CX with immediate
;number
;no result is stored, Update PF,
;SF
Example :
;AL = 01010001
TEST Al, 80H
;AND immediate 80H with AL to
;test f MSB of AL is 1 or 0
;ZF = 1 if MSB of AL = 0
;AL = 01010001 (unchanged)
;PF = 0 , SF = 0
;ZF = 1 because ANDing produced is 00
SAR Instruction - SAR instruction shifts the bits in the operand specified by op1 towards right
by count specified in op2.As bit is shifted out a copy of old MSB is taken in MSB .MSB position
and LSB is shifted to CF.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Example:
SAR AL, 1
(2)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
SAR BH, 1
SHR Instruction - SHR instruction shifts the bits in op1 to right by the number of times
specified by op2 .
Example:
(1)
SHR BP, 1
; Shift word in BP by 1 bit position to right
; and 0 is kept to MSB
(2)
MOV CL, 03H
;Load desired number of shifts into CL
SHR BYTE PYR[BX] ;Shift bytes in DS at offset BX and
;rotate 3 bits to right and keep 3 0s in MSB
(3)
;SI = 10010011 10101101 , CF = 0
SHR SI, 1
; Result: SI = 01001001 11010110
; CF = 1, OF = 1, SF = 0, ZF = 0
SAL / SHL Instruction - SAL instruction shifts the bits in the operand specified by op1 to its
left by the count specified in op2. As a bit is shifted out of LSB position a 0 is kept in LSB
position. CF will contain MSB bit.
SAL op1,op2
Example:
;CF = 0, BX = 11100101 11010011
SAL BX, 1
;Shift BX register contents by 1 bit
;position towards left
;CF = 1, BX = 11001011 1010011
RCL Instruction - RCL instruction rotates the bits in the operand specified by op1 towards left
by the count specified in op2.The operation is circular, the MSB of operand is rotated into a
carry flag and the bit in the CF is rotated around into the LSB of operand.
RCR op1, op2
Example:
CLC
;put 0 in CF
RCL AX, 1
;save higher-order bit of AX in CF
RCL DX, 1
;save higher-order bit of DX in CF
ADC AX, 0
; set lower order bit if needed.
Example :
;Word in DX of 1 bit is moved to left, and
RCL DX, 1
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
RCL BH, 1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV CL, 2
RCL AX, CL
RCR Instruction - RCR instruction rotates the bits in the operand specified by op1 towards
right by the count specified in op2. RCR op1, op2
Example: ( 1)
RCR BX, 1
( 2)
RCR BL, 1
;CF = 1, BL = 00111000
;Result: BL = 10011100, CF =0
;OF = 1 because MSB is changed to 1.
ROL Instruction - ROL instruction rotates the bits in the operand specified by op1 towards left
by the count specified in op2. ROL moves each bit in the operand to next higher bit position. The
higher order bit is moved to lower order position. Last bit rotated is copied into carry flag.
ROL op1, op2
Example: ( 1 )
ROL AX, 1
;Word in AX is moved to left by 1 bit
;and MSB bit is to LSB, and CF
;CF =0 ,BH =10101110
ROL BH, 1
;Result: CF ,Of =1 , BH = 01011101
Example : ( 2 )
;BX = 01011100 11010011
;CL = 8 bits to rotate
ROL BH, CL
;Rotate BX 8 bits towards left
;CF =0, BX =11010011 01011100
ROR Instruction - ROR instruction rotates the bits in the operand op1 towards right by count
specified in op2. The last bit rotated is copied into CF.
ROR op1, op2
Example:
(1)
ROR BL, 1
;Rotate all bits in BL towards right by 1
;bit position, LSB bit is moved to MSB
;and CF has last rotated bit.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
(2)
ROR BX, 1
Example ( 3 )
;CF = 0, AL = 10110011,
; Load CL
;Rotate all bits of AL towards right
;by 4 bits, CF = 0 ,AL = 00111011
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
STRING INSTRUCTIONS
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
REP
REPE / REPZ
REPNE / REPNZ
MOVS / MOVSB / MOVSW
COMPS / COMPSB / COMPSW
SCAS / SCASB / SCASW
LODS / LODSB / LODSW
STOS / STOSB / STOSW
ES:[DI] = DS:[SI]
if DF = 0 then
o
o
SI = SI + 1or 2
DI = DI + 1 or 2
else
o
o
SI = SI 1 or 2
DI = DI 1 or 2
Example:
LEA SI, a1
LEA DI, a2
MOV CX, 5
REP MOVSB
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
LODS / LODSB / LODSW- Load word or byte at DS:[SI] into AX/AL. Update SI
AX = DS:[SI]
if DF = 0 then
o SI = SI + 2 or 1
else
SI = SI 2 or 1
STOS / STOSB / STOSW - Store word or byte in AX/AL into ES:[DI]. Update DI
ES:[DI] = AX
if DF = 0 then
o DI = DI + 2 or 1
else
DI = DI 2 or 1
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
INTERRUPT INSTRUCTIONS:
INT
INTO
IRET
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
CALL BX ; BX contains the offset of the first instruction of the procedure .Replaces
contents of word of IP with contents of register BX.
CALL WORD PTR[BX] ;Offset of first instruction of procedure is in two memory
addresses in DS .Replaces contents of IP with contents of word memory location in DS
pointed to by BX.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
JA / JNBE - This instruction performs the Jump if above (or) Jump if not below or equal
operations according to the condition, if CF and ZF = 0 .
Example: ( 1 )
CMP AX, 4371H
;Compare by subtracting 4371H
;from AX
JA RUN_PRESS
;Jump to label RUN_PRESS if
;AX above 4371H
(2)
CMP AX, 4371H
;Compare ( AX 4371H)
JNBE RUN_PRESS ;Jump to label RUN_PRESS if
;AX not below or equal to 4371H
JAE / JNB / JNC - This instructions performs the Jump if above or equal,Jump if not below,
Jump if no carry operations according to the condition, if CF = 0.
Examples:
1. CMP AX, 4371H ;Compare ( AX 4371H)
JAE RUN
;Jump to the label RUN if AX is
;above or equal to 4371H .
2. CMP AX, 4371H ;Compare ( AX 4371H)
JNB RUN_1
;Jump to the label RUN_1 if AX
;is not below than 4371H
3. ADD AL, BL
; Add AL, BL. If result is with in JNC OK
;acceptable range, continue
JB/JC/JNAE Instruction - This instruction performs the Jump if below (or) Jump if carry (or)
Jump if not below/ equal operations according to the condition,if CF = 1
Example:
1.CMP AX, 4371H ;Compare ( AX 4371H )
JB RUN_P
;Jump to label RUN_P if AX is
;below 4371H
2.ADD BX, CX
;Add two words and Jump to
JC ERROR
; label ERROR if CF = 1
JBE/JNA Instruction - This instruction performs the Jump if below orequal (or) Jump if not
above operations according to the condition, if CF and ZF = 1
Example:
CMP AX, 4371H
;Compare ( AX 4371H )
JBA RUN
;Jump to label RUN if AX is
;below or equal to 4371H
CMP AX, 4371H
;Compare ( AX 4371H )
JNA RUN_R
;Jump to label RUN_R if AX is
;not above than 4371H
JE/JZ Instruction Instruction - This instruction performs the Jump if equal (or) Jump if zero
operations according to the condition if ZF = 1
Example:
NXT:CMP BX, DX
;Compare ( BX DX )
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
JE DONE
SUB BX, AX
INC CX
JUMP NXT
DONE: MOV AX, CX
Example:
IN AL, 8FH
SUB AL, 30H
JZ STATR
JG/JNLE Instruction - This instruction performs the Jump if greater (or) Jump if not less than
or equal operations according to the condition if ZF =0 and SF = OF
Example:
CMP BL, 39H
;Compare by subtracting
;39H from BL
JG NEXT1
;Jump to label if BL is
;more positive than 39H
CMP BL, 39H
;Compare by subtracting
;39H from BL
JNLE NEXT2
;Jump to label if BL is not
;less than or equal 39H
JGE/JNL Instruction - This instruction performs the Jump if greater than or equal / Jump if
not less than operation according to the condition if SF = OF
Example:
;Compare by the
CMP BL, 39H
;subtracting 39H from BL
JGE NEXT11
;Jump to label if BL is
;more positive than 39H
; or equal to 39H
CMP BL, 39H
;Compare by subtracting
;39H from BL
JNL NEXT22
;Jump to label if BL is not
;less than 39H
JL/JNGE Instruction - This instruction performs the Jump if less than /Jump if not greater than
or equal operation according to the condition, if SF OF
Example:
CMP BL, 39H
;Compare by subtracting 39H
;from BL
JL AGAIN
;Jump to the label if BL is more
;negative than 39H
CMP BL, 39H
;Compare by subtracting 39H
;from BL
JNGE AGAIN1
; Jump to the label if BL is not
;more positive than 39H or
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
JLE/JNG Instruction - This instruction performs the Jump if less than or equal / Jump if not
greater operation according to the condition, if ZF=1 and SF OF
Example:
CMP BL, 39h
; Compare by subtracting 39h
;from BL
JLE NXT1
;Jump to the label if BL is more
;negative than 39h or equal to 39h
CMP BL, 39h
;Compare by subtracting 39h
;from BL
JNG AGAIN2
; Jump to the label if BL is not
;more positive than 39h
JNE/JNZ Instruction - This instruction performs the Jump if not equal / Jump if not zero
operation according to the condition, if ZF=0
Example:
NXT: IN AL, 0F8H
;Read data value from port
CMP AL, 72
;Compare ( AL 72 )
JNE NXT
;Jump to NXT if AL 72
IN AL, 0F9H
;Read next port when AL = 72
MOV BX, 2734H
; Load BX as counter
NXT_1:ADD AX, 0002H ;Add count factor to AX
DEC BX
;Decrement BX
JNZ NXT_1
; Repeat until BX = 0
JNO Instruction This instruction performs the Jump if no overflow operation according to
the condition, if OF=0
Example:
ADD AL, BL
; Add signed bytes in AL and BL
JNO DONE
;Process done if no overflow MOV AL, 00H
;Else load error code in AL
DONE: OUT 24H, AL
; Send result to display
JNP/JPO Instruction This instruction performs the Jump if not parity /Jump if parity odd
operation according to the condition, if PF=0
Example:
IN AL, 0F8H
;Read ASCII char from UART
OR AL, AL
;Set flags
JPO ERROR1
;If even parity executed, if not
;send error message
JNS Instruction - This instruction performs the Jump if not signed (Jump if positive) operation
according to the condition, if SF=0
Example:
;Decrement counter
DEC AL
JNS REDO
; Jump to label REDO if counter has not
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
;decremented to FFH
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
JPE/JP Instruction - This instruction performs the Jump if parity even / Jump if parity
operation according to the condition, if PF=1
Example:
IN AL, 0F8H
;Read ASCII char from UART
OR AL, AL ;Set flags
JPE ERROR2
;odd parity is expected, if not
;send error message
JS Instruction - This instruction performs the Jump if sign operation according to the
condition, if SF=1
Example:
ADD BL, DH
;Add signed bytes DH to BL
JS JJS_S1
;Jump to label if result is
;negative
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
HALT Instruction - The HLT instruction will cause the 8086 to stop fetching and executing
instructions. The 8086 will enter a halt state. The only way to get the processor out of the halt
state are with an interrupt signal on the INTR pin or an interrupt signal on NMI pin or a reset
signal on the RESET input.
WAIT Instruction - When this WAIT instruction executes, the 8086 enters an idle condition.
This will stay in this state until a signal is asserted on TEST input pin or a valid interrupt signal
is received on the INTR or NMI pin.
FSTSW STATUS ; copy 8087 status word to memory
FWAIT
; wait for 8087 to finish before; doing next 8086 instruction
MOV AX, STATUS ;copy status word to AX to
;check bits
In this code we are adding up of FWAIT instruction so that it will stop the execution of
the command until the above instruction is finishes its work .so that you are not loosing
data and after that you will allow to continue the execution of instructions.
ESC Instruction - Escape instruction is used to pass instruction to a coprocessor such as the
8087 math coprocessor which shares the address and data bus with an 8086. Instruction for the
coprocessor are represented by a 6 bit code embedded in the escape instruction. As the 8086
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
fetches instruction byte, the coprocessor also catches these bytes from data bus and puts them in
its queue. The coprocessor treats all of the 8086 instruction as an NOP. When 8086 fetches an
ESC instruction , the coprocessor decodes the instruction and carries out the action specified by
the 6 bit code. In most of the case 8086 treats ESC instruction as an NOP.
LOCK Instruction - Assert bus lock signal
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
NOP Instruction - This instruction simply uses up the three clock cycles and increments the
instruction pointer to point to the next instruction. NOP does not change the status of any flag.
The NOP instruction is used to increase the delay of a delay loop.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
Introduction
It was electricity in the beginning....The people were happy because they did not know that it
was all around them and could be utilized. That was good. Then Faraday came and a stone has
started to roll slowly...
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The first machines using a new sort of energy appeared soon. A long time has passed since then
and just when the people finally got used to them and stopped paying attention to what a new
generation of specialists were doing, someone came to an idea that electrons could be a very
convenient toy being closed in a glass pipe. It was just a good idea at first, but there was no
return. Electronics was born and the stone kept on rolling down the hill faster and faster...
A new science - new specialists. Blue coats were replaced with white ones and people who knew
something about electronics appeared on the stage. While the rest of humanity were passively
watching in disbelief what was going on, the plotters split in two groups - software-oriented
and hardware-oriented. Somewhat younger than their teachers, very enthusiastic and full of
ideas, both of them kept on working but separate ways. While the first group was developing
constantly and gradually, the hardware-oriented people, driven by success, threw caution to the
wind and invented transistors.
Up till that moment, the things could be more or less kept under control, but a broad publicity
was not aware of what was going on, which soon led to a fatal mistake! Being naive in belief that
cheap tricks could slow down technology development and development of the world and
retrieve the good all days, mass market opened its doors for the products of Electronics Industry,
thus closing a magic circle. A rapid drop in prices made these components available for a great
variety of people. The stone was falling freely...
The first integrated circuits and processors appeared soon, which caused computers and other
products of electronics to drop down in price even more. They could be bought everywhere.
Another circle was closed! Ordinary people got hold of computers and computer era has begun...
While this drama was going on, hobbyists and professionals, also split in two groups and
protected by anonymity, were working hard on their projects. Then, someone suddenly put a
question: Why should not we make a universal component? A cheap, universal integrated circuit
that could be programmed and used in any field of electronics, device or wherever needed?
Technology has been developed enough as well as the market. Why not? So it happened, body
and spirit were united and the first integrated circuit was designed and called the
MICROCONTROLLER.
Like all good things, this powerful component is basically very simple. It is made by mixing
tested and high- quality "ingredients" (components) as per following receipt:
1.
The simplest computer processor is used as the "brain" of the future system.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
2.
Depending on the taste of the manufacturer, a bit of memory, a few A/D converters,
timers, input/output lines etc. are added
All that is placed in some of the standard packages.
A simple software able to control it all and which everyone can easily learn about has
been developed.
3.
4.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
On the basis of these rules, numerous types of microcontrollers were designed and they quickly
became man's invisible companion. Their incredible simplicity and flexibility conquered us a
long time ago and if you try to invent something about them, you should know that you are
probably late, someone before you has either done it or at least has tried to do it.
The following things have had a crucial influence on development and success of the
microcontrollers:
So, if you are infected with a virus called electronics, there is nothing left for you to do but to
learn how to use and control its power.
Even though there is a large number of different types of microcontrollers and even more
programs created for their use only, all of them have many things in common. Thus, if you learn
to handle one of them you will be able to handle them all. A typical scenario on the basis of
which it all functions is as follows:
1.
Power supply is turned off and everything is stillthe program is loaded into the
microcontroller, nothing indicates what is about to come
2.
Power supply is turned on and everything starts to happen at high speed! The control
logic unit keeps everything under control. It disables all other circuits except quartz crystal to
operate. While the preparations are in progress, the first milliseconds go by.
3.
Power supply voltage reaches its maximum and oscillator frequency becomes stable.
SFRs are being filled with bits reflecting the state of all circuits within the microcontroller. All
pins are configured as inputs. The overall electronics starts operation in rhythm with pulse
sequence. From now on the time is measured in micro and nanoseconds.
4.
Program Counter is set to zero. Instruction from that address is sent to instruction decoder
which recognizes it, after which it is executed with immediate effect.
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
The value of the Program Counter is incremented by 1 and the whole process is
repeated...several million times per second.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
5.
G.Vijaya Santhi,Asst.Prof
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Architecture 0f 8051
As you can see, all the operations within the microcontroller are performed at high speed and
quite simply, but the microcontroller itself would not be so useful if there are not special circuits
which make it complete. In continuation, we are going to call your attention to them.
Read Only Memory (ROM)
Read Only Memory (ROM) is a type of memory used to permanently save the program being
executed. The size of the program that can be written depends on the size of this memory. ROM
can be built in the microcontroller or added as an external chip, which depends on the type of the
microcontroller. Both options have some disadvantages. If ROM is added as an external chip, the
microcontroller is cheaper and the program can be considerably longer. At the same time, a
number of available pins is reduced as the microcontroller uses its own input/output ports for
connection to the chip. The internal ROM is usually smaller and more expensive, but leaves
more pins available for connecting to peripheral environment. The size of ROM ranges from
512B to 64KB.
Random Access Memory (RAM)
Random Access Memory (RAM) is a type of memory used for temporary storing data and
intermediate results created and used during the operation of the microcontrollers. The content of
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
this memory is cleared once the power supply is off. For example, if the program performes an
addition, it is necessary to have a register standing for what in everyday life is called the sum .
For that purpose, one of the registers in RAM is called the "sum" and used for storing results of
addition. The size of RAM goes up to a few KBs.
Electrically Erasable Programmable ROM (EEPROM)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The EEPROM is a special type of memory not contained in all microcontrollers. Its contents may
be changed during program execution (similar to RAM ), but remains permanently saved even
after the loss of power (similar to ROM). It is often used to store values, created and used during
operation (such as calibration values, codes, values to count up to etc.), which must be saved
after turning the power supply off. A disadvantage of this memory is that the process of
programming is relatively slow. It is measured in miliseconds.
Special function registers are part of RAM memory. Their purpose is predefined by the
manufacturer and cannot be changed therefore. Since their bits are physically connected to
particular circuits within the microcontroller, such as A/D converter, serial communication
module etc., any change of their state directly affects the operation of the microcontroller or
some of the circuits. For example, writing zero or one to the SFR controlling an input/output port
causes the appropriate port pin to be configured as input or output. In other words, each bit of
this register controls the function of one single pin.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Program Counter
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Program Counter is an engine running the program and points to the memory address containing
the next instruction to execute. After each instruction execution, the value of the counter is
incremented by 1. For this reason, the program executes only one instruction at a time just as it is
written. Howeverthe value of the program counter can be changed at any moment, which
causes a jump to a new memory location. This is how subroutines and branch instructions are
executed. After jumping, the counter resumes even and monotonous automatic counting +1, +1,
+1
Central Processor Unit (CPU)
As its name suggests, this is a unit which monitors and controls all processes within the
microcontroller and the user cannot affect its work. It consists of several smaller subunits, of
which the most important are:
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Why do we call them input/output ports? Because it is possible to change a pin function
according to the user's needs. These registers are the only registers in the microcontroller the
state of which can be checked by voltmeter!
Oscillator
Even pulses generated by the oscillator enable harmonic and synchronous operation of all
circuits within the microcontroller. It is usually configured as to use quartz-crystal or ceramics
resonator for frequency stabilization. It can also operate without elements for frequency
stabilization (like RC oscillator). It is important to say that program instructions are not executed
at the rate imposed by the oscillator itself, but several times slower. It happens because each
instruction is executed in several steps. For some microcontrollers, the same number of cycles is
needed to execute any instruction, while it's different for other microcontrollers. Accordingly, if
the system uses quartz crystal with a frequency of 20MHz, the execution time of an instruction is
not expected 50nS, but 200, 400 or even 800 nS, depending on the type of the microcontroller!
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Timers/Counters
Most programs use these miniature electronic "stopwatches" in their operation. These are
commonly 8- or 16-bit SFRs the contents of which is automatically incremented by each coming
pulse. Once the register is completely loaded, an interrupt is generated!
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
If these registers use an internal quartz oscillator as a clock source, then it is possible to measure
the time between two events (if the register value is T1 at the moment measurement has started,
and T2 at the moment it has finished, then the elapsed time is equal to the result of subtraction
T2-T1 ). If the registers use pulses coming from external source, then such a timer is turned into
a counter.
This is only a simple explanation of the operation itself. Its somehow more complicated in
practice.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
There are two things worth attention concerning the microcontroller power supply circuit:
Brown out is a potentially dangerous state which occurs at the moment the microcontroller is
being turned off or when power supply voltage drops to the lowest level due to electric noise. As
the microcontroller consists of several circuits which have different operating voltage levels, this
can cause its out of control performance. In order to prevent it, the microcontroller usually has a
circuit for brown out reset built-in. This circuit immediately resets the whole electronics when
the voltage level drops below the lower limit.
Reset pin is usually referred to as Master Clear Reset (MCLR) and serves for external reset of
the microcontroller by applying logic zero (0) or one (1) depending on the type of the
microcontroller. In case the brown out is not built in the microcontroller, a simple external circuit
for brown out reset can be connected to this pin.
Serial communication
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Parallel connections between the microcontroller and peripherals established over I/O ports are
the ideal solution for shorter distances up to several meters. However, in other cases, when it is
necessary to establish communication between two devices on longer distances it is obviously
not possible to use parallel connections. Then, serial communication is the best solution.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Today, most microcontrollers have several different systems for serial communication built in as
a standard equipment. Which of them will be used depends on many factors of which the most
important are:
One of the most important things concerning serial communication is the Protocol which should
be strictly observed. It is a set of rules which must be applied in order that devices can correctly
interpret data they mutually exchange. Fortunately, the microcontrollers automatically take care
of this, so the work of the programmer/user is reduced to a simple write (data to be sent) and read
(received data).
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Pins 1-8: Port 1 Each of these pins can be configured as an input or an output.
Pin 9: RS A logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By applying
logic zero to this pin, the program starts execution from the beginning.
Pins 10-17: Port 1 Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous communication
output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous communication
clock output.
Pin 12: INT0 Interrupt 0 input.
Pin 13: INT1 Interrupt 1 input.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Pins 18-19:X0,X1 Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins. Instead of it, miniature ceramics
resonators can also be used for frequency stability. Later versions of microcontrollers operate at
a frequency of 0 Hz up to over 50 Hz.
Pin 20: GND Ground.
Pin 21-28: PORT2 If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher address byte,
i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of 64Kb is
not used, which means that not all eight port bits are used for its addressing, the rest of them are
not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the ALE pin, the
external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the state of P0 and
uses it as a memory chip address. Immediately after that, the ALU pin is returned its previous
logic state and P0 is now used as a Data Bus. As seen, port data multiplexing is performed by
means of only one additional (and cheap) integrated circuit. In other words, this port is used for
both data and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that even there
is a program written to the microcontroller, it will not be executed. Instead, the program written
to external ROM will be executed. By applying logic one to the EA pin, the microcontroller will
use both memories, first internal then external (if exists).
Pin 32-39: PORT1 Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE pin
is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
Pin 40: Vcc +5V power supply.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Memory Organization
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The 8051 has two types of memory and these are Program Memory and Data Memory. Program
Memory (ROM) is used to permanently save the program being executed, while Data Memory
(RAM) is used for temporarily storing data and intermediate results created and used during the
operation of the microcontroller. Depending on the model in use (we are still talking about the
8051 microcontroller family in general) at most a few Kb of ROM and 128 or 256 bytes of RAM
is used. However
All 8051 microcontrollers have a 16-bit addressing bus and are capable of addressing 64 kb
memory. It is neither a mistake nor a big ambition of engineers who were working on basic core
development. It is a matter of smart memory organization which makes these microcontrollers a
real programmers goody.
Program Memory
The first models of the 8051 microcontroller family did not have internal program memory. It
was added as an external separate chip. These models are recognizable by their label beginning
with 803 (for example 8031 or 8032). All later models have a few Kbyte ROM embedded. Even
though such an amount of memory is sufficient for writing most of the programs, there are
situations when it is necessary to use additional memory as well. A typical example are so called
lookup tables. They are used in cases when equations describing some processes are too
complicated or when there is no time for solving them. In such cases all necessary estimates and
approximates are executed in advance and the final results are put in the tables (similar to
logarithmic tables).
How does the microcontroller handle external memory depends on the EA pin logic state:
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
EA=0 In this case, the microcontroller completely ignores internal program memory and
executes only the program stored in external memory.
EA=1 In this case, the microcontroller executes first the program from built-in ROM, then the
program stored in external memory.
In both cases, P0 and P2 are not available for use since being used for data and address
transmission. Besides, the ALE and PSEN pins are also used.
Data Memory
As already mentioned, Data Memory is used for temporarily storing data and intermediate results
created and used during the operation of the microcontroller. Besides, RAM memory built in the
8051 family includes many registers such as hardware counters and timers, input/output ports,
serial data buffers etc. The previous models had 256 RAM locations, while for the later models
this number was incremented by additional 128 registers. However, the first 256 memory
locations (addresses 0-FFh) are the heart of memory common to all the models belonging to the
8051 family. Locations available to the user occupy memory space with addresses 0-7Fh, i.e.
first 128 registers. This part of RAM is divided in several blocks.
The first block consists of 4 banks each including 8 registers denoted by R0-R7. Prior to
accessing any of these registers, it is necessary to select the bank containing it. The next memory
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
block (address 20h-2Fh) is bit- addressable, which means that each bit has its own address (07Fh). Since there are 16 such registers, this block contains in total of 128 bits with separate
addresses (address of bit 0 of the 20h byte is 0, while address of bit 7 of the 2Fh byte is 7Fh).
The third group of registers occupy addresses 2Fh-7Fh, i.e. 80 locations, and does not have any
special functions or features.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Additional RAM
In order to satisfy the programmers constant hunger for Data Memory, the manufacturers
decided to embed an additional memory block of 128 locations into the latest versions of the
8051 microcontrollers. However, its not as simple as it seems to be The problem is that
electronics performing addressing has 1 byte (8 bits) on disposal and is capable of reaching only
the first 256 locations, therefore. In order to keep already existing 8-bit architecture and
compatibility with other existing models a small trick was done.
What does it mean? It means that additional memory block shares the same addresses with
locations intended for the SFRs (80h- FFh). In order to differentiate between these two
physically separated memory spaces, different ways of addressing are used. The SFRs memory
locations are accessed by direct addressing, while additional RAM memory locations are
accessed by indirect addressing.
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Memory expansion
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
In case memory (RAM or ROM) built in the microcontroller is not sufficient, it is possible to add
two external memory chips with capacity of 64Kb each. P2 and P3 I/O ports are used for their
addressing and data transmission.
From the users point of view, everything works quite simply when properly connected because
most operations are performed by the microcontroller itself. The 8051 microcontroller has two
pins for data read RD#(P3.7) and PSEN#. The first one is used for reading data from external
data memory (RAM), while the other is used for reading data from external program memory
(ROM). Both pins are active low. A typical example of memory expansion by adding RAM and
ROM chips (Hardware architecture), is shown in figure above.
Even though additional memory is rarely used with the latest versions of the microcontrollers,
we will describe in short what happens when memory chips are connected according to the
previous schematic. The whole process described below is performed automatically.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
When the program during execution encounters an instruction which resides in external
memory (ROM), the microcontroller will activate its control output ALE and set the first 8 bits
of address (A0-A7) on P0. IC circuit 74HCT573 passes the first 8 bits to memory address pins.
A signal on the ALE pin latches the IC circuit 74HCT573 and immediately afterwards 8
higher bits of address (A8-A15) appear on the port. In this way, a desired location of additional
program memory is addressed. It is left over to read its content.
Port P0 pins are configured as inputs, the PSEN pin is activated and the microcontroller
reads from memory chip.
Similar occurs when it is necessary to read location from external RAM. Addressing is
performed in the same way, while read and write are performed via signals appearing on the
control outputs RD (is short for read) or WR (is short for write).
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Special Function Registers (SFRs) are a sort of control table used for running and monitoring the
operation of the microcontroller. Each of these registers as well as each bit they include, has its
name, address in the scope of RAM and precisely defined purpose such as timer control,
interrupt control, serial communication control etc. Even though there are 128 memory locations
intended to be occupied by them, the basic core, shared by all types of 8051 microcontrollers,
has only 21 such registers. Rest of locations are intensionally left unoccupied in order to enable
the manufacturers to further develop microcontrollers keeping them compatible with the
previous versions. It also enables programs written a long time ago for microcontrollers which
are out of production now to be used today.
A Register (Accumulator)
A register is a general-purpose register used for storing intermediate results obtained during
operation. Prior to executing an instruction upon any number or operand it is necessary to store it
in the accumulator first. All results obtained from arithmetical operations performed by the ALU
are stored in the accumulator. Data to be moved from one register to another must go through the
accumulator. In other words, the A register is the most commonly used register and it is
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
impossible to imagine a microcontroller without it. More than half instructions used by the 8051
microcontroller use somehow the accumulator.
B Register
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Multiplication and division can be performed only upon numbers stored in the A and B registers.
All other instructions in the program can use this register as a spare accumulator (A).
R Registers (R0-R7)
This is a common name for 8 general-purpose registers (R0, R1, R2 ...R7). Even though they are
not true SFRs, they deserve to be discussed here because of their purpose. They occupy 4 banks
within RAM. Similar to the accumulator, they are used for temporary storing variables and
intermediate results during operation. Which one of these banks is to be active depends on two
bits of the PSW Register. Active bank is a bank the registers of which are currently used.
The following example best illustrates the purpose of these registers. Suppose it is necessary to
perform some arithmetical operations upon numbers previously stored in the R registers:
(R1+R2) - (R3+R4). Obviously, a register for temporary storing results of addition is needed.
This is how it looks in the program:
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV A,R3
ADD A,R4
MOV R5,A
MOV A,R1
ADD A,R2
SUBB A,R5
PSW register is one of the most important SFRs. It contains several status bits that reflect the
current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two register
bank select bits, Overflow flag, parity bit and user-definable status flag.
P - Parity bit. If a number stored in the accumulator is even then this bit will be automatically
set (1), otherwise it will be cleared (0). It is mainly used during data transmit and receive via
serial communication.
- Bit 1. This bit is intended to be used in the future versions of microcontrollers.
OV Overflow occurs when the result of an arithmetical operation is larger than 255 and cannot
be stored in one register. Overflow condition causes the OV bit to be set (1). Otherwise, it will be
cleared (0).
RS0, RS1 - Register bank select bits. These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four banks
of RAM.
RS1
RS2
Space
in
RAM
Bank0
00h07h
Bank1
08h0Fh
Bank2
10h17h
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Bank3
18h1Fh
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
DPTR register is not a true one because it doesn't physically exist. It consists of two separate
registers: DPH (Data Pointer High) and (Data Pointer Low). For this reason it may be treated as a
16-bit register or as two independent 8-bit registers. Their 16 bits are primarly used for external
memory addressing. Besides, the DPTR Register is usually used for storing data and
intermediate results.
A value stored in the Stack Pointer points to the first free stack address and permits stack
availability. Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack pops
decrement its value by 1. Upon any reset and power-on, the value 7 is stored in the Stack Pointer,
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
which means that the space of RAM reserved for the stack starts at this location. If another value
is written to this register, the entire Stack is moved to the new memory location.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
If neither external memory nor serial communication system are used then 4 ports with in total of
32 input/output pins are available for connection to peripheral environment. Each bit within these
ports affects the state and performance of appropriate pin of the microcontroller. Thus, bit logic
state is reflected on appropriate pin as a voltage (0 or 5 V) and vice versa, voltage on a pin
reflects the state of appropriate port bit.
As mentioned, port bit state affects performance of port pins, i.e. whether they will be configured
as inputs or outputs. If a bit is cleared (0), the appropriate pin will be configured as an output,
while if it is set (1), the appropriate pin will be configured as an input. Upon reset and power-on,
all port bits are set (1), which means that all appropriate pins will be configured as inputs.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Timer T0
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
As seen in figure below, the timer T0 consists of two registers TH0 and TL0 representing a low
and a high byte of one 16-digit binary number.
Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it consists of
will contain 0. If the timer contains for example number 1000 (decimal), then the TH0 register
(high byte) will contain the number 3, while the TL0 register (low byte) will contain decimal
number 232.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In case of
exceeding this value, the timer will be automatically cleared and counting starts from 0. This
condition is called an overflow. Two registers TMOD and TCON are closely connected to this
timer and control its operation.
TMOD Register (Timer Mode)
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The TMOD register selects the operational mode of the timers T0 and T1. As seen in figure
below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 - bit7) refer to
the timer 1. There are 4 operational modes and each of them is described herein.
(P3.3):
GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin
Mode
Description
13-bit timer
16-bit timer
8-bit autoreload
Split mode
T1M1
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
1 - Timer 0 operates only if the INT0 bit is set.
0 - Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
1 - Timer counts pulses brought to the T0 pin (P3.4).
0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the oprtaional mode of the Timer 0.
Timer Control (TCON) Register
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
TCON register is also one of the registers whose bits are directly in control of timer operation.
Only 4 bits of this register are used for this purpose, while rest of them is used for interrupt
control to be discussed later.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
PCON
register
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM1 - Serial port mode bit 1.
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit.
When set, it enables multiprocessor communication in mode 2 and 3, and eventually mode 1. It
should be cleared in mode 0.
REN - Reception Enable bit enables serial reception when set. When cleared, serial
reception is disabled.
TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of
transmiting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit.
RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if 9th
bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte is
sent. It's a signal to the processor that the line is available for a new byte transmite. It must be
cleared from within the software.
RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that byte
is received and should be read quickly prior to being replaced by a new data. This bit is also
cleared from within the software.
As seen, serial port mode is selected by combining the SM0 and SM2 bits:
SM1
Mode
Description
Baud Rate
8-bit Shift
Register
8-bit UART
Determined by
the timer 1
SM0
9-bit UART
9-bit UART
Determined by
the timer 1
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Addressing Modes
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
While operating, the processor processes data as per program instructions. Each instruction
consists of two parts. One part describes WHAT should be done, while the other explains HOW
to do it. The latter part can be a data (binary number) or the address at which the data is stored.
Two ways of addressing are used for all 8051 microcontrollers depending on which part of
memory should be accessed:
Direct Addressing
On direct addressing, the address of memory location containing data to be read is specified in
instruction. The address may contain a number being changed during operation (variable). For
example:
Since the address is only one byte in size (the largest number is 255), only the first 255 locations
of RAM can be accessed this way. The first half of RAM is available for use, while another half
is reserved for SFRs.
MOV A,33h
Indirect Addressing
MOV A,@R0
; Means: Store the value from the register whose address is in the R0 register
into accumulator
On indirect addressing, registers R0, R1 or Stack Pointer are used for specifying 8-bit addresses.
Since only 8 bits are available, it is possible to access only registers of internal RAM this way
(128 locations when speaking of previous models or 256 locations when speaking of latest
models of microcontrollers). If an extra memory chip is added then the 16-bit DPTR Register
(consisting of the registers DPTRL and DPTRH) is used for specifying address. In this way it is
possible to access any location in the range of 64K
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Instruction Set-1
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
The process of writing program for the microcontroller mainly consists of giving instructions
(commands) in the specific order in which they should be executed in order to carry out a
specific task. As electronics cannot understand what for example an instruction if the push
button is pressed- turn the light on means, then a certain number of simpler and precisely
defined orders that decoder can recognise must be used. All commands are known as
INSTRUCTION SET. All microcontrollers compatibile with the 8051 have in total of 255
instructions, i.e. 255 different words available for program writing.
At first sight, it is imposing number of odd signs that must be known by heart. However, It is not
so complicated as it looks like. Many instructions are considered to be different, even though
they perform the same operation, so there are only 111 truly different commands. For example:
ADD A,R0, ADD A,R1, ... ADD A,R7 are instructions that perform the same operation (additon
of the accumulator and register). Since there are 8 such registers, each instruction is counted
separately. Taking into account that all instructions perform only 53 operations (addition,
subtraction, copy etc.) and most of them are rarely used in practice, there are actually 20-30
abbreviations to be learned, which is acceptable.
Types of instructions
Depending on operation they perform, all instructions are divided in several groups:
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:
INC
R1 Means:
Increment
register
R1
(increment
register
R1);
LJMP LAB5 - Means: Long Jump LAB5 (long jump to the address marked as LAB5);
JNZ LOOP - Means: Jump if Not Zero LOOP (if the number in the accumulator is not 0, jump to
the address marked as LOOP);
The other part of instruction, called OPERAND is separated from mnemonic by at least one
whitespace and defines data being processed by instructions. Some of the instructions have no
operand, while some of them have one, two or three. If there is more than one operand in an
instruction, they are separated by a comma.
For example:
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
RET return from a subroutine;
JZ TEMP - if the number in the accumulator is not 0, jump to the address marked as TEMP;
ADD A,R3 - add R3 and accumulator;
CJNE A,#20,LOOP - compare accumulator with 20. If they are not equal, jump to the address
marked as LOOP;
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition, subtraction, division,
multiplication etc. After execution, the result is stored in the first operand. For example:
ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator.
Arithmetic Instructions
Description
Byte
Cycle
ADD A,Rn
ADD
A,direct
ADD
A,@Ri
ADD
A,#data
ADDC
A,Rn
ADDC
A,direct
ADDC
A,@Ri
to
the
ADDC
A,#data
to
the
SUBB
A,Rn
from
the
SUBB
A,direct
SUBB
A,@Ri
SUBB
Mnemonic
RAM
to
the
data
to
the
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
INC A
INC Rn
INC Rx
INC @Ri
DEC A
DEC Rn
DEC Rx
DEC @Ri
INC DPTR
MUL AB
Multiplies A and B
DIV AB
Divides A by B
DA A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
A,#data
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Branch Instructions
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from where the
program continues execution is executed.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Conditional jump instructions: a jump to a new program location is executed only if a specified
condition is met. Otherwise, the program normally proceeds with the next instruction.
Branch Instructions
Description
Byte
Cycle
ACALL
addr11
LCALL
addr16
RET
RETI
AJMP addr11
Absolute jump
LJMP addr16
Long jump
SJMP rel
JC rel
JNC rel
JB bit,rel
JBC bit,rel
JMP
@A+DPTR
JZ rel
JNZ rel
Mnemonic
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
CJNE
A,#data,rel
CJNE
Rn,#data,rel
CJNE
@Ri,#data,rel
DJNZ Rn,rel
DJNZ Rx,rel
NOP
No operation
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
CJNE
A,direct,rel
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Data transfer instructions move the content of one register to another. The register the content of
which is moved remains unchanged. If they have the suffix X (MOVX), the data is exchanged
with external memory.
Data Transfer Instructions
Description
Byte
Cycle
MOV A,Rn
MOV
A,direct
MOV A,@Ri
MOV A,#data
MOV Rn,A
MOV
Rn,direct
MOV
Rn,#data
MOV
direct,A
MOV
direct,Rn
MOV
direct,direct
MOV
direct,@Ri
MOV
direct,#data
MOV @Ri,A
MOV
Mnemonic
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
RAM
MOV
@Ri,#data
MOV
DPTR,#data
MOVC
A,@A+DPTR
MOVC
A,@A+PC
MOVX
A,@Ri
3-10
MOVX
A,@DPTR
3-10
MOVX
@Ri,A
4-11
MOVX
@DPTR,A
4-11
PUSH direct
POP direct
XCH A,Rn
XCH A,direct
XCH A,@Ri
XCHD
A,@Ri
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
@Ri,direct
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Logic Instructions
Logic instructions perform logic operations upon corresponding bits of two registers. After
execution, the result is stored in the first operand.
Logic Instructions
Description
Byte
Cycle
ANL A,Rn
ANL
A,direct
ANL
A,@Ri
ANL
A,#data
ANL
direct,A
ANL
direct,#data
ORL A,Rn
OR register to accumulator
ORL
A,direct
ORL
A,@Ri
ORL
direct,A
ORL
direct,#data
XRL A,Rn
XRL
A,direct
XRL
A,@Ri
XRL
A,#data
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Mnemonic
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
XORL
direct,#data
CLR A
CPL A
SWAP A
RL A
RLC A
RR A
RRC A
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
XRL
direct,A
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is
that these are performed upon single bits.
Bit-oriented Instructions
Description
Byte
Cycle
CLR C
CLR bit
SETB C
SETB bit
CPL C
CPL bit
ANL C,bit
ANL C,/bit
ORL C,bit
ORL C,/bit
MOV C,bit
MOV bit,C
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Mnemonic
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Here is a list of the operands and their meanings:
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
A - accumulator;
Rn - is one of working registers (R0-R7) in the currently active RAM memory bank;
Direct - is any 8-bit address register of RAM. It can be any general-purpose register or a SFR
(I/O port, control register etc.);
@Ri - is indirect internal or external RAM location addressed by register R0 or R1;
#data - is an 8-bit constant included in instruction (0-255);
#data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
addr16 - is a 16-bit address. May be anywhere within 64KB of program memory;
addr11 - is an 11-bit address. May be within the same 2KB page of program memory as the first
byte of the following instruction;
rel - is the address of a close memory location (from -128 to +127 relative to the first byte of the
following instruction). On the basis of it, assembler computes the value to add or subtract from
the number currently stored in the program counter;
bit - is any bit-addressable I/O pin, control or status bit; and
C - is carry flag of the status register (register PSW).
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Some recent microcontrollers, such as the Microchip PIC range, have been designed to be
configured to access external memory and I/O.
The above diagram shows a microcontroller with two ports, A and B. If these two ports are also
used for external data and address bus, the microcontroller can be configured for microprocessor
mode.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Port A is now used as part of the address bus, with port B used for both the remaining address
bus signals and the data bus. So port B pins form part of the address bus, while, a little later, they
are the data bus. This is a common arrangement, called a multiplexed address/data bus
configuration. It uses less pins than would be needed for separate address and data bus
connections.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
In order to obtain the multiplexed address and data signals from the port B pins, an external data
latch is required. This is used to hold the address bits, when the port B pins change to become the
data bus. The purpose of the address strobe is to latch the address bits into the data latch at the
right moment, before the port B pins change to become the data bus.
The above diagram illustrates the basic arrangement of a multiplexed Address/Data bus. It is
similar to that used for the intel 80X86 processor. The basic address/data multiplexed timing is
illustrated below.
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Note that the address remains fixed until the next address strobe, also that the memory read
(when the read line is asserted) and the memory write (when the write line is asserted) take place
towards the end of the data waveform.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
As you already know, the microcontroller oscillator uses quartz crystal for its operation. As the
frequency of this oscillator is precisely defined and very stable, pulses it generates are always of
the same width, which makes them ideal for time measurement. Such crystals are also used in
quartz watches. In order to measure time between two events it is sufficient to count up pulses
coming from this oscillator. That is exactly what the timer does. If the timer is properly
programmed, the value stored in its register will be incremented (or decremented) with each
coming pulse, i.e. once per each machine cycle. A single machine-cycle instruction lasts for 12
quartz oscillator periods, which means that by embedding quartz with oscillator frequency of
12MHz, a number stored in the timer register will be changed million times per second, i.e. each
microsecond.
The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest, their
main purpose is to measure time and count external events. Besides, they can be used for
generating clock pulses to be used in serial communication, so called Baud Rate.
Timer T0
As seen in figure below, the timer T0 consists of two registers TH0 and TL0 representing a low
and a high byte of one 16-digit binary number.
Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it consists of
will contain 0. If the timer contains for example number 1000 (decimal), then the TH0 register
(high byte) will contain the number 3, while the TL0 register (low byte) will contain decimal
number 232.
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In case of
exceeding this value, the timer will be automatically cleared and counting starts from 0. This
condition is called an overflow. Two registers TMOD and TCON are closely connected to this
timer and control its operation.
TMOD Register (Timer Mode)
The TMOD register selects the operational mode of the timers T0 and T1. As seen in figure
below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 - bit7) refer to
the timer 1. There are 4 operational modes and each of them is described herein.
(P3.3):
GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin
1 - Timer 1 operates only if the INT1 bit is set.
0 - Timer 1 operates regardless of the logic state of the INT1 bit.
C/T1 selects pulses to be counted up by the timer/counter 1:
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
1 - Timer counts pulses brought to the T1 pin (P3.5).
0 - Timer counts pulses from internal oscillator.
T1M1,T1M0 These two bits select the operational mode of the Timer 1.
T1M0
Mode
Description
13-bit timer
16-bit timer
8-bit autoreload
Split mode
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
T1M1
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
1 - Timer 0 operates only if the INT0 bit is set.
0 - Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
1 - Timer counts pulses brought to the T0 pin (P3.4).
0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the operational mode of the Timer 0.
T0M1
T0M0
Mode
Description
13-bit timer
16-bit timer
8-bit autoreload
Split mode
This is one of the rarities being kept only for the purpose of compatibility with the previuos
versions of microcontrollers. This mode configures timer 0 as a 13-bit timer which consists of all
8 bits of TH0 and the lower 5 bits of TL0. As a result, the Timer 0 uses only 13 of 16 bits. How
does it operate? Each coming pulse causes the lower register bits to change their states. After
receiving 32 pulses, this register is loaded and automatically cleared, while the higher byte (TH0)
is incremented by 1. This process is repeated until registers count up 8192 pulses. After that,
both registers are cleared and counting starts from 0.
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Mode 1 configures timer 0 as a 16-bit timer comprising all the bits of both registers TH0 and
TL0. That's why this is one of the most commonly used modes. Timer operates in the same way
as in mode 0, with difference that the registers count up to 65 536 as allowable by the 16 bits.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Mode 2 configures timer 0 as an 8-bit timer. Actually, timer 0 uses only one 8-bit register for
counting and never counts from 0, but from an arbitrary value (0-255) stored in another (TH0)
register.
The following example shows the advantages of this mode. Suppose it is necessary to constantly
count up 55 pulses generated by the clock.
If mode 1 or mode 0 is used, It is necessary to write the number 200 to the timer registers and
constantly check whether an overflow has occured, i.e. whether they reached the value 255.
When it happens, it is necessary to rewrite the number 200 and repeat the whole procedure. The
same procedure is automatically performed by the microcontroller if set in mode 2. In fact, only
the TL0 register operates as a timer, while another (TH0) register stores the value from which the
counting starts. When the TL0 register is loaded, instead of being cleared, the contents of TH0
will be reloaded to it. Referring to the previous example, in order to register each 55th pulse, the
best solution is to write the number 200 to the TH0 register and configure the timer to operate in
mode 2.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Mode 3 configures timer 0 so that registers TL0 and TH0 operate as separate 8-bit timers. In
other words, the 16-bit timer consisting of two registers TH0 and TL0 is split into two
independent 8-bit timers. This mode is provided for applications requiring an additional 8-bit
timer or counter. The TL0 timer turns into timer 0, while the TH0 timer turns into timer 1. In
addition, all the control bits of 16-bit Timer 1 (consisting of the TH1 and TL1 register), now
control the 8-bit Timer 1. Even though the 16-bit Timer 1 can still be configured to operate in
any of modes (mode 1, 2 or 3), it is no longer possible to disable it as there is no control bit to do
it. Thus, its operation is restricted when timer 0 is in mode 3.
The only application of this mode is when two timers are used and the 16-bit Timer 1 the
operation of which is out of control is used as a baud rate generator.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
In order to use timer 0, it is first necessary to select it and configure the mode of its operation.
Bits of the TMOD register are in control of it:
Referring to figure above, the timer 0 operates in mode 1 and counts pulses generated by internal
clock the frequency of which is equal to 1/12 the quartz frequency.
Turn on the timer:
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
The TR0 bit is set and the timer starts operation. If the quartz crystal with frequency of 12MHz is
embedded then its contents will be incremented every microsecond. After 65.536 microseconds,
the both registers the timer consists of will be loaded. The microcontroller automatically clears
them and the timer keeps on repeating procedure from the beginning until the TR0 bit value is
logic zero (0).
How to 'read' a timer?
Depending on application, it is necessary either to read a number stored in the timer registers or
to register the moment they have been cleared.
- It is extremely simple to read a timer by using only one register configured in mode 2 or 3. It is
sufficient to read its state at any moment. That's all!
- It is somehow complicated to read a timer configured to operate in mode 2. Suppose the lower
byte is read first (TL0), then the higher byte (TH0). The result is:
Everything seems to be ok, but the current state of the register at the moment of reading was:
TH0 = 14 TL0 = 255
In case of negligence, such an error in counting (255 pulses) may occur for not so obvious but
quite logical reason. The lower byte is correctly read (255), but at the moment the program
counter was about to read the higher byte TH0, an overflow occurred and the contents of both
registers have been changed (TH0: 1415, TL0: 2550). This problem has a simple solution.
The higher byte should be read first, then the lower byte and once again the higher byte. If the
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
number stored in the higher byte is different then this sequence should be repeated. It's about a
short loop consisting of only 3 instructions in the program.
There is another solution as well. It is sufficient to simply turn the timer off while reading is
going on (the TR0 bit of the TCON register should be cleared), and turn it on again after reading
is finished.
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Usually, there is no need to constantly read timer registers. It is sufficient to register the moment
they are cleared, i.e. when counting starts from 0. This condition is called an overflow. When it
occurrs, the TF0 bit of the TCON register will be automatically set. The state of this bit can be
constantly checked from within the program or by enabling an interrupt which will stop the main
program execution when this bit is set. Suppose it is necessary to provide a program delay of
0.05 seconds (50 000 machine cycles), i.e. time when the program seems to be stopped:
First a number to be written to the timer registers should be calculated:
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
When enabled, the timer will resume counting from this number. The state of the TF0 bit, i.e.
whether it is set, is checked from within the program. It happens at the moment of overflow, i.e.
after exactly 50.000 machine cycles or 0.05 seconds.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Programs on timers
ACALL DELAY
SJMP HERE
CLR TF0
RET
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
ACALL DELAY
SJMP HERE
DELAY:SETB TR0
RET
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
One of the microcontroller features making it so powerful is an integrated UART, better known
as a serial port. It is a full-duplex port, thus being able to transmit and receive data
simultaneously and at different baud rates. Without it, serial data send and receive would be an
enormously complicated part of the program in which the pin state is constantly changed and
checked at regular intervals. When using UART, all the programmer has to do is to simply select
serial port mode and baud rate. When it's done, serial data transmit is nothing but writing to the
SBUF register, while data receive represents reading the same register. The microcontroller takes
care of not making any error during data transmission.
Serial port must be configured prior to being used. In other words, it is necessary to determine
how many bits is contained in one serial word, baud rate and synchronization clock source.
The whole process is in control of the bits of the SCON register (Serial Control).
In mode 0, serial data are transmitted and received through the RXD pin, while the TXD pin
output clocks. The bout rate is fixed at 1/12 the oscillator frequency. On transmit, the least
significant bit (LSB bit) is sent/received first.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
TRANSMIT - Data transmit is initiated by writing data to the SBUF register. In fact, this
process starts after any instruction being performed upon this register. When all 8 bits have been
sent, the TI bit of the SCON register is automatically set.
RECEIVE - Data receive through the RXD pin starts upon the two following conditions are
met: bit REN=1 and RI=0 (both of them are stored in the SCON register). When all 8 bits have
been received, the RI bit of the SCON register is automatically set indicating that one byte
receive is complete.
Since there are no START and STOP bits or any other bit except data sent from the SBUF
register in the pulse sequence, this mode is mainly used when the distance between devices is
short, noise is minimized and operating speed is of importance. A typical example is I/O port
expansion by adding a cheap IC (shift registers 74HC595, 74HC597 and similar).
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Mode 1
In mode 1, 10 bits are transmitted through the TXD pin or received through the RXD pin in the
following manner: a START bit (always 0), 8 data bits (LSB first) and a STOP bit (always 1).
The START bit is only used to initiate data receive, while the STOP bit is automatically written
to the RB8 bit of the SCON register.
TRANSMIT - Data transmit is initiated by writing data to the SBUF register. End of data
transmission is indicated by setting the TI bit of the SCON register.
RECEIVE - The START bit (logic zero (0)) on the RXD pin initiates data receive. The
following two conditions must be met: bit REN=1 and bit RI=0. Both of them are stored in the
SCON register. The RI bit is automatically set upon data reception is complete.
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
In mode 2, 11 bits are transmitted through the TXD pin or received through the RXD pin: a
START bit (always 0), 8 data bits (LSB first), a programmable 9th data bit and a STOP bit
(always 1). On transmit, the 9th data bit is actually the TB8 bit of the SCON register. This bit
usually has a function of parity bit. On receive, the 9th data bit goes into the RB8 bit of the same
register (SCON).The baud rate is either 1/32 or 1/64 the oscillator frequency.
TRANSMIT - Data transmit is initiated by writing data to the SBUF register. End of data
transmission is indicated by setting the TI bit of the SCON register.
Mi
Microprocessors
and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
RECEIVE - The START bit (logic zero (0)) on the RXD pin initiates data receive. The
following two conditions must be met: bit REN=1 and bit RI=0. Both of them are stored in the
SCON register. The RI bit is automatically set upon data reception is complete.
Mode 3
Mode 3 is the same as Mode 2 in all respects except the baud rate. The baud rate in Mode 3 is
variable.
The parity bit is the P bit of the PSW register. The simplest way to check correctness of the
received byte is to add a parity bit to it. Simply, before initiating data transmit, the byte to
transmit is stored in the accumulator and the P bit goes into the TB8 bit in order to be a part of
the message. The procedure is opposite on receive, received byte is stored in the accumulator
and the P bit is compared with the RB8 bit. If they are the same- everything is OK!
Baud Rate
Baud Rate is a number of sent/received bits per second. In case the UART is used, baud rate
depends on: selected mode, oscillator frequency and in some cases on the state of the SMOD bit
of the SCON register. All the necessary formulas are specified in the table:
Baud
Rate
Mode
0
Fosc. /
12
Mode
BitSMOD
BitSMOD
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Fosc. /
32
Fosc. /
64
1
0
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Mode
2
Fosc.
16 12
(256TH1)
Mode
3
Fosc.
16 12
(256TH1)
Timer 1 is usually used as a clock generator as it enables various baud rates to be easily set. The
whole procedure is simple and is as follows:
Fosc. (MHz)
11.0592
12
14.7456
150
40 h
30 h
00 h
300
A0 h
98 h
80 h
75 h
52 h
600
D0 h
CC h
C0 h
BB h
A9 h
1200
E8 h
E6 h
E0 h
DE h
D5 h
2400
F4 h
F3 h
F0 h
EF h
EA h
F3 h
EF h
EF h
4800
4800
FA h
F8 h
9600
FD h
FC h
9600
19200
16
20
F5 h
FC h
0
F5 h
FD h
Bit
SMOD
1
1
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
FE h
76800
FF h
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
38400
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Interrupts of 8051
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Interrupts
- An interrupt is the occurrence of an event that causes a temporary suspension of a
program while the condition is serviced by another program
- The program or routine that deals with the interrupt is the interrupt service routine (ISR)
or interrupt handler
- Interrupts allow a system to respond asynchronously to an event and deal with the event
while another program is executing
- An interrupt driven system gives the illusion of doing many things simultaneously
- Of course, the CPU cannot execute more than one instruction at a time - it can only
temporarily suspend execution of one program, execute another, and then return to the
first program
- In a way, interrupts are like subroutines, except that one does not know when the
interrupt code will be executed
Interrupt Handling
- When an interrupt occurs, CPU:
finishes the instruction it is currently executing
stores the PC on the stack
saves the current status of all interrupts internally
fetches the ISR address for the interrupt from IVT (interrupt vector table), stores it into
PC and jumps to that address
executes the ISR until it reaches the RETI instruction
upon RETI, the CPU pops back the old PC from the stack and continues with whatever
it was doing before the interrupt occurred.
Interrupts v. Pooling
Polling:
-CPU monitors all served devices continuously, looking for a service request flag
- Whenever it sees a request, it serves the device and then keeps polling
-CPU is always busy with polling doing the while any request loop
Interrupts:
-If and when a device is ready and needs attention, it informs the CPU
- CPU drops whatever it was doing and serves the device and then returns back to its
original task
- CPU is always free, when not serving any interrupts
Interrupt Sources
- 2 external (INT0 and INT1)
- 2 Timers (TF0 and TF1)
- 1 Serial (SI)
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
- Sets which Interrupt will have priority should 2 occur simultaneously, or if another is
being serviced the higher priority will be processed first.
- Putting a 1 in a bit assigns its interrupt to the high priority level.
Pending Interrupts
- If an interrupt occurs while it is disabled, or while a higher priority interrupt is active, it
becomes pending.
- As soon as the interrupt is enabled, it will cause a call.
- It is also possible to cancel it by software by clearing the appropriate bit in the register.
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Interrupt Vectors
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
- Each vector has 8 bytes for a routine. The interrupt code may all be contained here
(Small ISR).
- From the vector location execution may branch to a much larger routine elsewhere in
memory (Large ISR)
External Interrupts
IT0/IT1:
Mi
Microprocessors
and Interfacing
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Serial Interrupts
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
MOV TMOD , #20H ;load TMOD with 20h to select timer 1 in mode 2
;programming
MOV TH1, #-3H
; to set the baud rate to 9600bps
MOV SCON,#50H ;to select serial programming in mode 0
SETB TR1
;start the timer
AGAIN:MOV SBUF , # A ;load SBUF with the ascii character of A
HERE:JNB TI,HERE
;continuosly monitor the transmit interrupt flag to check
;that the byte is transmitted or not
CLR TI
;clear the flag to transmit next byte
SJMP AGAIN
;jump to required label to repeat the process again
Program to receive the byte continuously:
MOV TMOD , #20H ;load TMOD with 20h to select timer 1 in mode 2
;programming
MOV TH1, #-3H
; to set the baud rate to 9600bps
MOV SCON,#50H ;to select serial programming in mode 0
SETB TR1
;start the timer
HERE:JNB TI,HERE
;continuosly monitor the transmit interrupt flag to check
;that the byte is transmitted or not
;load the value of SBUF into Accumulator
;the byte received is send to port 1
;clear the flag to receive next byte
;jump to required label to repeat the process again
MOV A,SBUF
MOV P1,A
CLR RI
SJMP HERE
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
DW
DW
STACK SEGMENT
STACK DW
TOP_STACK
STACK ENDS
0BH
LABEL
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
DATA SEGMENT
FACT_INPUT
FACT_OUTPUT
DATA ENDS
0016H
2
DUP(0)
DUP(0)
WORD
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOP_STACK
MOV AX,0001H
MOV CX,FACT_INPUT
CALL FACTORIAL
MOV FACT_OUTPUT,AX
MOV FACT_OUTPUT+2,DX
HLT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
DW
DW
STACK SEGMENT
STACK DW
TOP_STACK
STACK ENDS
0BH
LABEL
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0016H
2
DUP(0)
DUP(0)
WORD
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOP_STACK
MOV SI,OFFSET FACT_INPUT
MOV DI,OFFSET FACT_OUTPUT
MOV AX,0001H
CALL FACTORIAL
HLT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
DW
DW
STACK SEGMENT
STACK DW
TOP_STACK
STACK ENDS
0BH
LABEL
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
DATA SEGMENT
FACT_INPUT
FACT_OUTPUT
DATA ENDS
0016H
2
DUP(0)
DUP(0)
WORD
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOP_STACK
CALL FACTORIAL
HLT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
Microprocessors and Interfacing
DW
DW
STACK SEGMENT
STACK DW
TOP_STACK
STACK ENDS
0BH
LABEL
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
0016H
2
DUP(0)
DUP(0)
WORD
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
START:MOV AX,DATA
MOV DS,AX
MOV AX,STACK
MOV SS,AX
MOV SP,OFFSET TOP_STACK
MOV AX,FACT_INPUT
PUSH AX
CALL FACTORIAL
POP AX
HLT
G.Vijaya Santhi,Asst.Prof
Visit our site & get updates (POSTS) to your Email | TWITTER | Mobile | Face book | ORKUT @ FREE *
w
Ad w.
m yo
in ur
: N sw
.R w
aj 8.t
ee k
v
G.Vijaya Santhi,Asst.Prof