8086 PDF
8086 PDF
UNIT -I
8086 Architecture
Architecture of 8086
Register Organization
Programming Model
Memory addresses
Memory Segmentation
Timing diagrams
UNIT-I
8086 Architecture
Introduction to Microprocessors
A microprocessor is a computer processor which incorporates the
functions of a computer's central processing unit (CPU) on a
single integrated circuit (IC), or at most a few integrated circuits
The microprocessor is a multipurpose, clock driven, register based,
digital-integrated circuit which accepts binary data as input, processes it
according to instructions stored in its memory, and provides results as
output. Microprocessors contain both combinational logic and sequential
digital logic. Microprocessors operate on numbers and symbols represented
in the binary numeral system.
Generation of Microprocessors:
INTEL 4004 ( 1971)
⚫ 4-bit microprocessor
⚫ 4 KB main memory
⚫ 45 instructions
⚫ PMOS technology
⚫ was first programmable device which was used in calculators
INTEL 8008 (1972)
⚫ 8-bit version of 4004
⚫ 16 KB main memory
⚫ 48 instructions
⚫ PMOS technology
⚫ Slow
Intel 8080 (1973)
8-bit microprocessor
⚫ 64 KB main memory
⚫ 2 microseconds clock cycle time
⚫ 500,000 instructions/sec
⚫ 10X faster than 8008
⚫ NMOS technology
⚫ Drawback was that it needed three power supplies.
By Prof. Akshay Gaikawad & Mr. Rishikesh Yadav
V2V Classes, Kalyan Page 2
SEM IV Dip Comp, IT & Allied Branches
INTEL 8086/8088
Buses
The registers AX, BX, CX, and DX are the general 16-bit registers.
Segment registers:
To complete 1Mbyte memory is divided into 16 logical segments. The
complete 1Mbyte memory segmentation is as shown in fig 1.5. Each
segment contains 64Kbyte of memory. There are four segment registers.
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 addresses in string
manipulation instructions.
Flag Register:
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. The 8086 flag register as shown in
the fig 1.6. 8086 has 9 active flags and they are divided into two categories:
1. Conditional Flags
2. Control Flags
Carry Flag (CY): This flag indicates an overflow condition for unsigned
integer arithmetic. It is also used in multiple-precision arithmetic.
Parity Flag (PF):This flag is used to indicate the parity of result. If lower
order 8-bits of the result contains even number of 1’s, the Parity Flag is set
and for odd number of 1’s, the Parity flag is reset.
Zero Flag (ZF):It is set; if the result of arithmetic or logical operation is zero
else it is reset.
Sign Flag (SF):In sign magnitude format the sign of number is indicated by
MSB bit. If the result of operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the
execution unit. Control flags are as follows:
Trap Flag (TF): It is used for single step control. It allows user to execute one
instruction of a program at a time for debugging. When trap flag is set,
program can be run in single step mode.
Direction Flag (DF):It is used in string operation. If it is set, string bytes are
accessed from higher memory address to lower memory address. When it is
reset, the string bytes are accessed from lower memory address to higher
memory address.
8086 Architecture
The Execution unit tells the BIU where to fetch instructions or data
from
decodes instructions and
Executes instructions
Control Circuitry:
It directs internal operations.
SUBTRACT
XOR
INCREMENT
DECREMENT
COMPLEMENT
FLAG REGISTERS:
A flag is a flip flop that indicates some condition produced by
execution of an instruction or controls certain operation of the EU.
It is 16 bit
2. Control flags
Conditional Flags
Carry Flag (CY): This flag indicates an overflow condition for unsigned
integer arithmetic. It is also used in multiple-precision arithmetic.
Parity Flag (PF):This flag is used to indicate the parity of result. If lower
By Prof. Akshay Gaikawad & Mr. Rishikesh Yadav
V2V Classes, Kalyan Page 13
SEM IV Dip Comp, IT & Allied Branches
order 8-bits of the result contains even number of 1’s, the Parity Flag is set
and for odd number of 1’s, the Parity flag is reset.
Zero Flag (ZF):It is set; if the result of arithmetic or logical operation is zero
else it is reset.
Sign Flag (SF):In sign magnitude format the sign of number is indicated by
MSB bit. If the result of operation is negative, sign flag is set.
Control Flags
Control flags are set or reset deliberately to control the operations of the
execution unit. Control flags are as follows:
Trap Flag (TF): It is used for single step control. It allows user to execute one
instruction of a program at a time for debugging. When trap flag is set,
program can be run in single step mode.
Direction Flag (DF):It is used in string operation. If it is set, string bytes are
accessed from higher memory address to lower memory address. When it is
reset, the string bytes are accessed from lower memory address to higher
memory address.
mode.
Instruction Queue:
BIU gets upto 6 bytes of next instructions and stores them in the
instruction queue. When EU executes instructions and is ready for its next
instruction, then it simply reads the instruction from this instruction queue
resulting in increased execution speed. Fetching the next instruction while
the current instruction executes is called pipelining.( based on FIFO) .This is
much faster than sending out an addresses to the system memory and
waiting for memory to send back the next instruction byte or bytes .Here
the Queue will be dumped and then reloaded from the new Address.
Segment Register:
The 8086 20 bit addresses So it can address upto 2 20 in memory ( 1 Mbyte)
but at any instant it can address upto 4 64 KB segments. This four segments
holds the upper 16 bits of the starting address of four memory segments
that the 8086 is working with it at particular time .The BIU always inserts
zeros for the lowest 4 bits of the 20 bit starting address
Example : If the code segment register contains 348AH then the code
segment starts at 348A0H .In other words a 64Kbyte segment can be
located anywhere within 1MByte address Space but the segment will
always starts at an address with zeros in the lowest 4 bits
Stack: is a section of memory set aside to store addresses and data while
subprogram executes is often called segment base . The stack segment
register always holds the upper 16 bit starting address of program stack.
The extra segment register and data segment register is used to hold the
upper 16 bit starting addresses of two memory segments that are used for
data .
Instruction Pointer holds the 16 bit address or offset of the next code byte
within the code segment. The value contained in the Instruction Pointer
called as Offset because the value must be added to the segment base
address in CS to produce the required 20 bit address.
These three registers are used to store temporary storage of data like
general purpose registers .They hold the 16 bit offset data of the data word
in one of the segment
Programming model
The point to note is that the beginning segment address must begin
at an address divisible by 16.Also note that the four segments need not be
defined separately. It is allowable for all four segments to completely
overlap (CS = DS = ES = SS).
A logical address gives the displacement from the base address of the
segment to the desired location within it, as opposed to its "real" address,
which maps directly anywhere into the 1 MByte memory space. This "real"
address is called the physical address.
What is the difference between the physical and the logical address?
The physical address is 20 bits long and corresponds to the actual binary
code output by the BIU on the address bus lines. The logical address is an
offset from location 0 of a given segment.
Logical address is in the form of: Base Address: Offset Offset is the
displacement of the memory location from the starting location of the
segment. To calculate the physical address of the memory, BIU uses the
following formula:
Example:
To convert this 16-bit address into 20-bit, the BIU appends 0H to the LSB (by
multiplying with 16) of the address. After appending, the starting address of
the Data Segment becomes 22220H.
Where 0016H is the offset, 2222 H is the value of DS Therefore the physical
address:22220H + 0016H
: 22236 H
The following table describes the default offset values to the corresponding
memory segments.
flexibility.
The 8086 signals can be categorized in three groups. The first are the
signals having common functions in minimum as well as maximum mode,
the second are the signals which have special functions in minimum mode
and third are the signals having special functions for maximum mode.
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. Here T1, T2, T3, T4 and TW are the
clock states of a machine cycle. TW is await state. 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 or 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
Read signal, when low, indicates the peripherals that the processor is
performing a memory or I/O read operation. is active low and shows
the state for T2, T3, TW of any read cycle. The signal remains tristated
during the 'hold acknowledge'.
READY:
INTR-Interrupt Request:
This is a level triggered input. This is sampled during the last clock
cycle 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 resetting the interrupt
enable flag. This signal is active high and internally synchronized.
TEST:
NMI-Non-maskable Interrupt:
RESET:
This input causes the processor to terminate the current activity and
start execution from FFFF0H. The signal is active high and must be active for
at least four clock cycles. It restarts execution when the RESET returns low.
RESET is also internally synchronized.
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.
The range of frequency for different 8086 versions is from 5MHz to 10MHz.
VCC :
+5V power supply for the operation of the internal circuit. GND
ground for the internal circuit.
MN/MX :
The logic level at this pin decides whether the processor is to operate
M/IO -Memory/IO:
-Interrupt Acknowledge:
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.
-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.
Logically, this is equivalent to S1 in maximum mode. Its timing is the same
as M/I/O. This is tristated during 'hold 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
By Prof. Akshay Gaikawad & Mr. Rishikesh Yadav
V2V Classes, Kalyan Page 33
SEM IV Dip Comp, IT & Allied Branches
middle of the next clock cycle after completing the current bus (instruction)
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 it should be externally synchronized.
These are the status lines which reflect the type of operation, being
carried out by the processor. These become active during T4 of the previous
cycle and remain active during T1 and T2 of the current bus cycle. The
status lines return to passive state during T3 of the current bus cycle so that
they may again become active for the next bus cycle during T4. Any change
in these lines during T3 indicates the starting of a new cycle, and return to
passive state indicates end of the bus cycle. These status lines are encoded
in table 1.3
This output pin indicates that other system bus masters will be
prevented from gaining the system bus, while the signal is low.
The signal is activated by the 'LOCK' prefix instruction and remains
active until the completion of the next instruction. This floats to tri-state
off during "hold acknowledge". 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.
ReQuest/Grant:
These pins are used by other local bus masters, in maximum mode, to
force the processor to release the local bus at the end of the processor's
current bus cycle. Each of the pins is bidirectional with having
higher priority than pins have internal pull-up resistors and
may be left unconnected. The request! Grant sequence is as follows:
1. A pulse 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 clock
cycle. The CPU's 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 8086 that
the 'hold' request is about to end and the 8086 may regain control of the
local bus at the next clock cycle.
Latches:
Transreceivers
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 signal. They are controlled by two
signals, namely, DEN* and DT/R*. The DEN* signal indicates that the valid
data is available on the data bus, while DT/R indicates the direction of data,
i.e. from or to the processor.
Memory:
The system contains memory for the monitor and users program
storage. Usually, EPROMS are used for monitor storage, while RAMs for
users program storage.
IO Devices:
A system may contain I/O devices for communication with the processor as
well as some special purpose I/O devices.
Clock Generator:
The clock generator generates the clock from the crystal oscillator
and then shapes it and divides to make it more precise so that it can be
used as an accurate timing reference for the system. The clock generator
also synchronizes some external signals with the system clock.
The read cycle begins in T1 with the assertion of the 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 Tl 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 addressed 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 Tl 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.
The BHE* and A0 signals are used to select the proper byte or bytes
of memory or I/O word to be read or written. The M/IO*, RD* and WR*
signals indicate the types of data transfer as specified in Table
The HOLD pin is checked at the end of the each bus cycle. If it is
received active by the processor before T4 of the previous cycle or during
T1 state of the current cycle, the CPU activities HLDA in the next clock cycle
and for the succeeding bus cycles, the bus will be given to another
requesting master The control 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 as shown in
fig
The maximum mode system timing diagrams are also divided in two
portions as read (input) and write (output) timing diagrams. The
address/data and address/status timings are similar to the minimum mode.
ALE is asserted in T1, just like minimum mode. The only difference lies in
the status signals used and the available control and advanced command
signals. The fig. 1.2 shows the maximum mode timings for the read
operation while the fig. 1.3 shows the same for the write operation.
UNIT -II
Instruction Set and Assembly Language Programming
of 8086
Instruction formats, Addressing modes,
Instruction Set
Assembler Directives,
Procedures, Macros
Simple Programs involving Logical
Branch and Call Instructions
Sorting Evaluating Arithmetic Expressions
String Manipulations
UNIT-II
The instruction format contains two fields
operation code / opcode
Operand field
OPERAND:
The CPU executes the instruction using the information resides in these fields .
The least three significant 3 bits of the opcode are used for specifying register
operand if any otherwise all the 8 bits form an opcode and the operands are implied.
REGISTER TO REGISTER
The format is 2 byte long
The first byte of the code specifies the opcode and width
The second byte of the code shows the register operand and R/M field
The Register represented by REG is one of the operands . The R/M field specifies
another register or memory location .ie the other operand
This is similar to the register to register format except for the MOD field is shown.
The first two bytes contains the information regarding OPCODE,MOD and R/M fields
The remaining 4 bytes contains 2 bytes of displacement and 2 bytes of data
Example
MOV DL, 08H
The 8-bit data (08H) given in the instruction is moved to DL
(DL) 08H
MOV AX, 0A9FH
The 16-bit data (0A9FH) given in the instruction is moved to AX register
(AX) 0A9FH
The square brackets around the 1354H denote the contents of the memory location.
When executed, this instruction will copy the contents of the memory location into BX
register. This addressing mode is called direct because the displacement of the operand
from the segment base is specified directly in the instruction.
The instruction will specify the name of the register which holds the data to be operated by the
instruction. All registers except IP may be used in this mode
Example:
MOV CL, DH
The content of 8-bit register DH is moved to another 8-bit register CL
(CL) (DH)
Example
MOV AX, [BX]; suppose the register BX contains 4895H, then the contents
; 4895H are moved to AX
ADD CX, {BX}
In this addressing mode, the operands offset address is found by adding the contents of
SI or DI register and 8-bit/16-bit displacements. DS and ES are the default segments for
index registers SI and DI respectively. This is the special case of the of register indirect
addressing mode.
Example
OUT − Used to send out a byte or word from the accumulator to the provided
port.
LDS − Used to load DS register and other provided register from the memory
LES − Used to load ES register and other provided register from the memory.
2. ARITHMETIC INSTRUCTIONS
These instructions are used to perform arithmetic operations like addition,
subtraction, multiplication, division, etc.
Following is the list of instructions under this group −
3. LOGICAL INSTRUCTIONS
These instructions are used to perform operations where data bits are involved,
i.e. operations like logical, shift, etc.
Following is the list of instructions under this group −
AND − Used for adding each bit in a byte/word with the corresponding bit in
another byte/word.
OR − Used to multiply each bit in a byte/word with the corresponding bit in
another byte/word.
XOR − Used to perform Exclusive-OR operation over each bit in a byte/word with
the corresponding bit in another byte/word.
TEST − Used to add operands to update flags, without affecting operands.
SHR − Used to shift bits of a byte/word towards the right and put zero(S) in
MSBs.
SAR − Used to shift bits of a byte/word towards the right and copy the old MSB
into the new MSB.
RCR − Used to rotate bits of byte/word towards the right, i.e. LSB to CF and CF to
MSB.
RCL − Used to rotate bits of byte/word towards the left, i.e. MSB to CF and CF to
LSB.
4. STRING INSTRUCTIONS
String is a group of bytes/words and their memory is always allocated in a
sequential order.
Following is the list of instructions under this group −
REP − Used to repeat the given instruction till CX ≠ 0.
REPE/REPZ − Used to repeat the given instruction until CX = 0 or zero flag ZF = 1.
REPNE/REPNZ − Used to repeat the given instruction until CX = 0 or zero flag ZF
= 1.
MOVS/MOVSB/MOVSW − Used to move the byte/word from one string to
another.
COMS/COMPSB/COMPSW − Used to compare two string bytes/words.
INS/INSB/INSW − Used as an input string/byte/word from the I/O port to the
provided memory location.
OUTS/OUTSB/OUTSW − Used as an output string/byte/word from the provided
memory location to the I/O port.
SCAS/SCASB/SCASW − Used to scan a string and compare its byte with a byte in
AL or string word with a word in AX.
LODS/LODSB/LODSW − Used to store the string byte into AL or string word into
AX.
8. INTERRUPT INSTRUCTIONS
These instructions are used to call the interrupt during program execution.
INT − Used to interrupt the program during execution and calling service
specified.
INTO − Used to interrupt the program during execution if OF = 1
IRET − Used to return from interrupt service to the main program
ASSEMBLER DIRECTIVES
Assembler directives are the Instructions to the Assembler, linker and loader
regarding the program being executed. also called ‘pseudo instructions. Control the
generation of machine codes and organization of the program; but no machine codes
are generated for assembler directives.
They are used to
› specify the start and end of a program
› attach value to variables
› allocate storage locations to input/ output data
› define start and end of segments, procedures, macros etc..
ASSUME
Used to tell the assembler the name of the logical segment it should use for a
specified segment. You must tell the assembler that what to assume for any segment
you use in the program.
Example
ASSUME: CODE
Tells the assembler that the instructions for the program are in segment named CODE.
DB – Defined Byte
Used to declare a byte type variable or to set aside one or more locations of type byte in
memory.
Example
PRICES DB 49H, 98H, 29H:
Declare array of 3 bytes named PRICES and initialize 3 bytes as shown.
DD – Define Double Word
Used to declare a variable of type doubleword or to reserve a memory location which
can be accessed as doubleword.
DQ – Define Quadword
Used to tell the assembler to declare the variable as 4 words of storage in memory.
DT – Define Ten Bytes
Used to tell the assembler to declare the variable which is 10 bytes in length or reserve
10 bytes of storage in memory.
DW – Define Word
Used to tell the assembler to define a variable type as word or reserve word in memory.
DUP: used to initialize several locations and to assign values to location
END – End the Program
To tell the assembler to stop fetching the instruction and end the program execution.
ENDP – it is used to end the procedure.
ENDS – used to end the segment.
EQU – EQUATE
By Prof. Akshay Gaikawad & Mr. Rishikesh Yadav
V2V Classes, Kalyan Page 63
SEM IV Dip Comp, IT & Allied Branches
Tells the assembler to increment the location counter to the next even address if it is not
already at an even address.
EXTRN
Used to tell the assembler that the name or labels following the directive are in some
other assembly module.
GLOBAL – Declares Symbols As Public Or Extrn
Used to make the symbol available to other modules.It can be used in place of EXTRN or
PUBLIC keyword.
GROUP – Group related segment
Used to tell the assembler to group the logical segments named after the
directive into one logical segment. This allows the content of all the segments to be
accessed from the same group.
INCLUDE – include source code from file
Used to tell the assembler to insert a block of source code from the named file
into the current source module. This shortens the source code.
LABEL
Used to give the name to the current value in the location counter. The LABEL directive
must be followed by a term which specifies the type you want associated with that
name.
LENGTH
Used to determine the number of items in some data such as string or array.
NAME
Used to give a specific name to a module when the programs consisting of several
modules.
OFFSET
It is an operator which tells the assembler to determine the offset or displacement of
named data item or procedure from the start of the segment which contains it.
ORG – Originate
Tells the assembler to set the location counter value.
Example, ORG 7000H sets the location counter value to point to 7000H location in
memory.
$ is often used to symbolically represent the value of the location counter. It is
used with ORG to tell the assembler to change the location according to the current
value in the location counter. E.g. ORG $+100.
UNIT -III
I/O Interface
8255 PPI
Various Modes of Operation and Interfacing to 8086
D/A and A/D Converter
Stepper motor
Interfacing of DMA controller 8257
Interfacing with advanced devices
Memory Interfacing to 8086
Interrupt Structure of 8086
Interrupt Vector Table, Interrupt Service Routine
architecture of 8259.
Communication Interface
Serial Communication Standards
Serial Data Transfer Schemes
8251 USART Architecture and Interfacing.
UNIT-3
I/O Interface
Introduction:
Input port:
It is used to read data from the input device such as keyboard. The simplest form
of input port is a buffer. The input device is connected to the microprocessor through
buffer, as shown in the fig.1. This buffer is a tri-state buffer and its output is available
only when enable signal is active. When microprocessor wants to read data from the
input device (keyboard), the control signals from the microprocessor activates the buffer
by asserting enable input of the buffer. Once the buffer is enabled, data from the input
device is available on the data bus. Microprocessor reads this data by initiating read
command.
Output port:
It is used to send data to the output device such as display from the
microprocessor. The simplest form of output port is a latch. The output device is
connected to the microprocessor through latch, as shown in the fig.2. When
microprocessor wants to send data to the output device is puts the data on the data bus
and activates the clock signal of the latch, latching the data from the data bus at the
output of latch. It is then available at the output of latch for the output device.
the message. A parity bit can help to reduce this. However, electrical wire parallel data
transmission is therefore less reliable for long distances because corrupt transmissions
are far more likely.
The interrupt driven I/O technique allows the CPU to execute its main program
and only stop to service I/O device when it is told to do so by the I/O system as shown in
fig.3. This method provides an external asynchronous input that would inform the
processor that it should complete whatever instruction that is currently being executed
and fetch a new routine that will service the requesting device. Once this servicing is
completed, the processor would resume exactly where it left off.
An analogy to the interrupt concept is in the classroom, where the professor serves
as CPU and the students as I/O ports. The classroom scenario for this interrupt analogy
will be such that the professor is busy in writing on the blackboard and delivering his
lecture.
The student raises his finger when he wants to ask a question (student requesting for
service). The professor then completes his sentence and acknowledges student‟s
request by saying “YES” (professor acknowledges the interrupt request). After
acknowledgement from the professor, student asks the question and professor gives
answer to the question (professor services the interrupt). After that professor continues
its remaining lecture form where it was left.
PIO 8255:
The two groups of I/O pins are named as Group A and Group B. Each of thesetwo
groups contains a subgroup of eight I/O lines called as 8-bit port and anothersubgroup of
four lines or a 4-bit port. Thus Group A contains an 8-bit port Aalong with a 4-bit port C
upper.
The port A lines are identified by symbols PA0-PA7 while the port C lines are
identified as PC4-PC7 similarly. Group B contains an 8-bit port B, containing lines PB0-
PB7 and a 4-bit port C with lower bits PC0-PC3. The port C upper and port C lower can be
used in combination as an 8-bit port C. Both the port Cs is assigned the same address.
Thus one may have either three 8-bit I/O ports or two 8-bit and two 4-bit I/O 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
By Prof. Akshay Gaikawad & Mr. Rishikesh Yadav
V2V Classes, Kalyan Page 71
SEM IV Dip Comp, IT & Allied Branches
control word register (CWR). The internal block diagram and the pin configuration of
8255 are shown in figs.
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 transfer of both data and control
words. RD, WR, A1, A0 and RESET are the inputs, provided by the microprocessor to
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 port A lines are identified by symbols PA0-PA7 while the port C lines are
Identified as PC4-PC7. Similarly, Group B contains an 8-bit port B, containing
lines PB0-PB7 and a 4-bit port C with lower bits PC0- PC3. The port C upper
and port C lower can be used in combination as an 8-bit port C.
Both the port C is assigned the same address. Thus one may have either three
8-bit 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
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 mode1 or mode2.
PC3-PC0: These are the lower port C lines; other details are the same as PC7-PC4
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.
D0-D7: These are the data bus lines those carry data or control word to/from the
microprocessor.
RESET:Logic high on this line clears the control word register of 8255. All ports are
set as input ports by default after reset.
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.
These are two basic modes of operation of 8255. I/O mode and Bit Set-Reset mode
(BSR).
In I/O mode, the 8255 ports work as programmable I/O ports, while in BSR mode only
port C (PC0-PC7) can be used to set or reset its individual port bits.
Under the I/O mode of operation, further there are three modes of operation of 8255,
so as to support different types of applications, mode 0, mode 1 and mode 2.
BSR Mode: In this mode any of the 8-bits of port C can be set or reset depending on D0
of the control word. The bit to be set or reset is selected by bit select flags D3, D2 and D1
of the CWR as given in table.
I/O Modes:
a) Mode 0 (Basic I/O mode): This mode is also called as basic input/output Mode. This
mode provides simple input and output capabilities using each of the threeports. Data
can be simply read from and written to the input and output portsrespectively, after
appropriate initialization.
1. Two 8-bit ports (port A and port B) and two 4-bit ports (port C upper and lower)
are available. The two 4-bit ports can be combined used as a third 8-bit port.
2. Any port can be used as an input or output port.
3. Output ports are latched. Input ports are not latched.
4. A maximum of four ports are available so that overall 16 I/O configurations
arepossible.
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
orhandshake lines for port B. This group which includes port B and PC0-PC2 is called
asgroup B for Strobed data input/output. Port C lines PC3-PC5 provides strobe lines for
portA.This group including port A and PC3-PC5 from group A. Thus port C is utilized
forgenerating handshake signals.
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
andoutputs both are latched.
4. Out of 8-bit port C, PC0-PC2 are used to generate control signals for port B
andPC3-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 areexplained as
follows:
• STB (Strobeinput) – If this lines falls to logic low level, the data available at 8-
bit input port is loaded into input latches.
• IBF (Input buffer full) – If this signal rises to logic 1, it indicates that data
hasbeen loaded into latches, i.e. it works as an acknowledgement. IBF is set
by a lowon STB and is reset by the rising edge of RD input.
• INTR (Interruptrequest) – This active high output signal can be used
tointerrupt the CPU whenever an input device requests the service. INTR is
set by ahigh STBpin and a high at IBF pin. INTE is an internal flag that can be
controlledby 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
berequest the service of the processor by putting the data on the bus and
sending thestrobe signal.
• OBF (Output buffer full) – This status signal, whenever falls to low,
indicatesthat CPU has written data to the specified output port. The OBF flip-
flop will beset by a rising edge of WR signal and reset by a low going edge at
the ACKinput.
• ACK (Acknowledgeinput) – ACK signal acts as an acknowledgement to begiven
by an output device. ACK signal, whenever low, informs the CPU that thedata
transferred by the CPU to the output device through the port is received
bythe output device.
• INTR (Interruptrequest) – Thus an output signal that can be used to
interruptthe 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
fallingedge on WRinput. The INTEA and INTEB flags are controlled by the bit
set-reset mode ofPC6 and PC2 respectively.
In this mode, 8255 is a bidirectional 8-bit port with handshake signals. The Rdand WR signals
decide whether the 8255 is going to operate as an input port oroutput port.
INTR – (Interrupt request) As in mode 1, this control signal is active high and
isused to interrupt the microprocessor to ask for transfer of the next data
byteto/from it. This signal is used for input (read) as well as output (write)
operations.
Control Signals for Output operations:
OBF (Output buffer full) – This signal, when falls to low level, indicates that
theCPU has written data to port A.
ACK (Acknowledge) This control input, when falls to logic low level,
Acknowledges that the previous data byte is received by the destination and
nextbyte may be sent by the processor. This signal enables the internal tristate
buffersto send the next data byte on port A.
INTE1 ( A flag associated with OBF ) This can be controlled by bit set/resetmode
with PC6.
STB (Strobe input)a low on this line is used to strobe in the data into the
inputLatches of 8255.
IBF (Input buffer full) when the data is loaded into input buffer, this signal risesto
logic „1‟. This can be used as an acknowledge that the data has been receivedby
the receiver.
The waveforms in fig show the operation in Mode 2 for output as well as
inputport.
Note: WR must occur before ACK and STB must be activated before RD.
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 treated as an input device by the microprocessor
that sends an initializing 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.
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 100µs 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, as shown. 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
not contain any internal sample and hold circuit.
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.
Fig (1) and Fig (2) show the block diagrams and pin diagrams for ADC 0808/0809.
Table.1
Address lines
Analog I/P selected
C B A
I/P 0 0 0 0
I/P 1 0 0 1
I/P 2 0 1 0
I/P 3 0 1 1
I/P 4 1 0 0
I/P 5 1 0 1
I/P 6 1 1 0
I/P 7 1 1 1
Table.2
The digital to analog converters convert binary numbers into their analog
equivalent voltages. The DAC find applications in areas like digitally controlled gains,
motor speed controls, programmable gain amplifiers, etc.
The supply range extends from +5V to +15V , while Vref may be anywhere
between -10V to +10V. The maximum analog output voltage will be +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 7523 to convert the current output of AD7523 to a proportional output
voltage.
111
of the shaft.
The circuit for interfacing a winding Wn with an I/O port is given in fig.4. Each of
the windings of a stepper motor needs this circuit for its interfacing with the
output port. A typical stepper motor may have parameters like torque 3 Kg-cm,
operating voltage 12V, current rating 0.2 A and a step angle 1.80 i.e. 200
steps/revolution (number of rotor teeth).
A simple schematic for rotating the shaft of a stepper motor is called a wave
scheme. In this scheme, the windings Wa, Wb, Wc and Wd are applied with the
required voltages pulses, in a cyclic fashion. By reversing the sequence of
excitation, the direction of rotation of the stepper motor shaft may be reversed.
Table.1 shows the excitation sequences for clockwise and anticlockwise rotations.
Another popular scheme for rotation of a stepper motor shaft applies pulses to
two successive windings at a time but these are shifted only by one position at a
time. This scheme for rotation of stepper motor shaft is shown in table2.
Motion step A B C D
1 1 0 0 0
2 0 1 0 0
Clock wise 3 0 0 1 0
4 0 0 0 1
5 1 0 0 0
1 1 0 0 0
2 0 0 0 1
Anticlock
3 0 0 1 0
wise
4 0 1 0 0
5 1 0 0 0
Motion step A B C D
1 0 0 1 1
2 0 1 1 0
Clock wise 3 1 1 0 0
4 1 0 0 1
5 0 0 1 1
1 0 0 1 1
2 1 0 0 1
Anticlock
3 1 1 0 0
wise
4 0 1 1 0
5 0 0 0 0
Keyboard Interfacing
In most keyboards, the key switches are connected in a matrix of Rows and Columns.
1. D e t e c t a k e y p r e s s
2. D e b o u n c e t h e k e y p r e s s .
3. Encode the keypress (produce a standard code for the pressed key).
Key Debounce:
The rows of the matrix are connected to four output Port lines, &columns are
connected to four input Port lines.
When no keys are pressed, the column lines are held high by the pull-up resistors
connected to +5v.
Pressing a key connects a row & a column.
To detect if any key is pressed is to output 0‟s to all rows & then check columns
to see it a pressed key has connected a low (zero) to a column.
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 i.e indicating a key press.
A simple 20/10 msec delay is executed to 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 & the initial detection was
caused by a noise pulse.
To avoid this problem, two schemes are suggested:
1. Use of Bistablemultivibrator at the output of the key to debounce it.
2. The microprocessor has to wait for the transient period (at least for 10
ms), so that the transient response settles down and reaches a steady
state.
If any of the columns are low now, then the assumption is made that it was a
valid key press.
By Prof. Akshay Gaikawad & Mr. Rishikesh Yadav
V2V Classes, Kalyan Page 97
SEM IV Dip Comp, IT & Allied Branches
The final task is to determine the row & column of the pressed key &convert this
information to Hex-code for the pressed key.
The 4-bit code from I/P port & the 4-bit code from O/P port (row &column) are
converted to Hex-code.
Display Interface
I/O Interface
Any application of a microprocessor system requires the
transfer of data between microprocessor and external environment and also with in the
microprocessor. This is known as Input/Output. There are three different ways that the data transfer
can take place. They are
I/O mapped I/O is the most commonly used I/O transfer technique. In this method I/O locations are
placed separately from memory. The addresses for isolated I/O devices are separate from memory.
Using this method user can use the entire memory. This method allows data transfer only by using
instructions IN, OUT. The pins M/ IO and W/R are used to indicate I/O read or an I/O write operations.
The signals on these lines indicate that the address on the address bus is for I/O devices.
Memory mapped I/O does not use the IN, OUT instruction it
uses only the instruction that transfers data between microprocessor and memory. A memory
mapped I/O device is treated as memory location. The disadvantage in this system is the overall
memory is reduced. The advantage of this system is that any memory transfer instruction can be used
for data transfer and control signals like I/O read and I/O write are not necessary which simplify the
hardware.
Memory interfacing
Memory is an integral part of a microcomputer system. There
are two main types of memory.
(i) Read only memory (ROM): As the name indicates this memory is available only for
reading purpose. The various types available under this category are PROM, EPROM,
EEPROM which contain system software and permanent system data.
(ii) Random Access memory (RAM): This is also known as Read Write Memory. It is a volatile
memory. RAM contains temporary data and software programs generally for different
applications.
AO ........... AN. The number of address lines indicates the total memory capacity of the memory device. A
1K memory requires 10 address lines A0-A9. Similarly a 1MB requires 20 lines A0-A19 (in the case of
8086). The memory devices may have separate I/O lines or a common set of bidirectional I/O lines.
Using these lines data can be transferred in either direction. Whenever output buffer is activated the
operation is read whenever input buffers are activated the operation is write. These lines are labelled
as I/O,......... I/On or DO ..................... Dn. The size of a memory location is dependent upon the number of
data bits. If the number of data lines are eight D 0 - D7 then 8 bits or 1 byte of data can be stored in
each location. Similarly if numbers of data bits are 16 (D 0 - D15) then the memory size is 2 bytes. For
example 2K x 8 indicates there are 2048 memory locations and each memory location can store 8 bits
of data.
Memory devices may contain one or more inputs which are
used to select the memory device or to enable the memory device. This pin is denoted by CS (Chip
select) or CE (Chip enable). When this pin is at logic '0' then only the memory device performs a read
or a write operation. If this pin is at logic ‘1’ the memory chip is disabled. If there are more than one
CS input then all these pins must be activated to perform read or write operation.
All memory devices will have one or more control inputs.
When ROM is used we find OE output enable pin which allows data to flow out of the output data
pins. To perform this task both CS and OE must be active. A RAM contains one or two control inputs.
They are R / W or RD and WR . If there is only one input R/ W then it performs read
operation when R/ W pin is at logic 1. If it is at logic 0 it performs write operation. Note that this is
possible only when CS is also active.
Connect the 16-bit data bus of the memory bank with that of the microprocessor 8086.
3. The remaining address lines of the microprocessor, BHE and A0 are used for decoding the
required chip select signals for the odd and even memory banks. CS of memory is derived from the
O/P of the decoding circuit.
As a good and efficient interfacing practice, the address map of the system should be
continuous as far as possible, i.e. there should be no windows in the map. A memory location should
have a single address corresponding to it, i.e. absolute decoding should be preferred, and minimum
hardware should be used for decoding. In a number of cases, linear decoding may be used to minimise
the required hardware.Let us now consider a few example problems on memory interfacing with
8086.
Most of devices are parallel in nature. These devices transfer data simultaneously on data
lines. But parallel data transfer process is very complicated and expensive. Hence in some situations
the serial I/O mode is used where one bit is transferred over a single line at a time. In this type of
transmission parallel word is converted into a stream of serial bits which is known as parallel to serial
conversion. The rate of transmission in serial mode is BAUD, i.e., bits per second. The serial data
transmission involves starting, end of transmission, error verification bits along with the data. Any
serial I/O involves the following concepts.
(a) Interfacing requirements (b) Alphanumeric codes (c) Transmission format (d) Error checks in data
communication (e) Data communication over lines (f) Standards in serial I/O
The microprocessor has to identify the port address to perform read or write operation. Serial
I/O uses only one data line, chip select, read, write control signals.
Data transfer takes place using ASCII code (American standard code for Information
Interchange) which is 7 bit code with 128 combinations. The data can be transmitted by taking various
parameters into consideration such as synchronization or asynchronization, direction of data flow
speed, errors, medium of data transmission etc. In synchronous transmission both transmitter and
receiver operate, in synchronous to each other.
Synchronization used for high speed operations. In asynchronous data transmission data is
transmitted between Start and Stop bits with logic 1 as mark logic 0 as space. In asynchronous we get
around 11 bits for data transmission one start, 8 bits of data, 2 stop bits. A synchronous data
transmission is used for less than 20 Kbits /second transmission.
RECEIVER/TRANSMITTER (USART)
Fig. 5.7 shows the block diagram of 8251 A. The block diagram shows all the elements of a
programmable chip; it includes the interfacing signals, the control register and the status register. The
functions of various blocks are described below:
(A) Data bus buffer: This 3-state, bidirectional buffer is used to interface the 8251A to the system data
bus. Data is transmitted or received by the buffer upon execution of input and output instruction of
the CPU Command words and status information are also transferred through the data bus buffer. The
command, status and data in and data out are separate 8-bit registers to provide double buffering.
The functional block accepts inputs form the control bus and generates control signals for
overall device operation. It contains the control word register and command word register that store
the various control formats for the device functional definition.
For example
If Baud rate equals 220 Baud
TXC equals 220 Hz in the 1x mode.
TXC equals 3.52 KHz in the 16x mode.
TXC equals 14.08 KHz in the 64x mode.
INTERFACING STANDARDS
(Ref: Interfacing through Microprocessors by K. Subba Rao, Hi-tech publishers, P. 266)
Serial I/O is used to interface various devices or for connecting various equipment to the
system. Common understanding is necessary among various manufacturers such that a standard
notation is followed for interfacing these components. These standards may be provided by IEEE or by
any standard professional organisation. The serial I/O standards must specify clearly voltage levels,
speed of data transfer, length of cables etc. In serial I/O data can be transmitted as either current or
voltage 20 mA or 60 mA current loops are used if data is transmitted using current. Current flow takes
place when the system is at logic 1. The current flow is stopped when the system is at logic 0. In the
current loop method the signals are relatively noise-free and they are best suited for long distance
transmission.
RS-232 is developed long before which is used for communication between terminals and
modems. Using RS-232C data can be transmitted as voltage. The data terminals equipment and data
communication equipment are used to communicate using RS-232C cable. RS-232C is not compatible
with TTL logic and cannot be used for long distance transmission.
OVERVIEW
Modems were developed so that terminals could use phone lines to communicate with
distant computers. As we stated earlier, modems and other devices used to send serial data are often
referred to as data communication equipment or DCE. The terminals or computers that are sending or
receiving the data are referred to as data terminal equipment or DTE. In response to the need for
signal and handshake standards between DTE and DCE, the Electronic Industries Association (EIA)
developed EIA standard RS-232C. This standard describes the function of 25 signal and handshake pins
for serial-data transfer. It also describes the voltage levels, impedance levels, rise and fall times,
maximum bit rate, and maximum capacitance for these signal lines.
RS-232C specifies 25 signal pins, and it specifies that the DTE connector should be a male and
the DCE connector should be a female. A specific connector is not given, but the most commonly used
connectors are the DB-25P male shown in Figure 14-7a. For systems where many of the 25 pins are
not needed, a 9-pin DIN connector such as the DE-9P male connector shown in Figure 14-7b is used.
The voltage levels for all RS-232C signals are as follows. A logic high, or mark, is a voltage
between -3V and -15 V under load (-25 V no load). A logic low or space is a voltage between +3 V and
+15 V under load (+ 25 V no load). Voltages such as ±12 V are commonly used.
The MCI488s require + and - supplies, but the MCI489s require only+ 5 V. Note the capacitor
to ground on the outputs of the MCI488 drivers is to reduce cross talk between adjacent wires, the
rise and fall times for RS-232C signals are limited to 30 V/µs.
Figure 14-9 shows the signal names, signal direction, and a brief description for each of the 25
pins denned for RS-232C. For most applications only a few of these pins are used.
Note that the signal direction is specified with respect to the DGE, this convention is part of the
standard. Note that there is both a chassis ground (pin 1) and a signal ground (pin 7). To prevent large
ac-induced ground currents in the signal ground, these two should be connected together only at the
power supply in the terminal or the computer.
The TxD, RxD, and handshake signals shown with common names in Figure 14-9 are the ones most often
used for simple systems. These signals control what is called the primary or forward communications
channel of the modem. Some modems allow communication over a secondary or backward channel,
which operates in the reverse direction from the forward channel and at a much lower baud rate. Pins
12, 13, 14, 16, and 19 are the data and handshake lines for this backward channel. Pins 15, 17, 21, and
24 are used for synchronous data communication.