8255 and Input output interfacing_6
8255 and Input output interfacing_6
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.
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 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 achieved
by programming the bits of an internal register of 8255 called as control word
register (CWR).
· 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.
· 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.
Modes of Operation of 8255
· These are two basic modes of operation of 8255. I/O mode and Bit Set-Reset
mode (BSR).
· In I/O mode, the 8255 ports work as programmable I/O ports, while in BSR mode only
port C (PC0-PC7) can be used to set or reset its individual port bits.
· Under the I/O mode of operation, further there are three modes of operation of
8255, so as to support different types of applications, mode 0, mode 1 and mode 2.
· 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 are
possible.
· All these modes can be selected by programming a register internal to 8255known as
CWR.
· The control word register has two formats. The first format is valid for I/O modes
of operation, i.e. modes 0, mode 1 and mode 2 while the second format is valid for
bit set/reset (BSR) mode of operation.
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
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 are explained as
follows:
• STB (Strobe input) – 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 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.
• 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
beset 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 ofPC6 and PC2 respectively.
c) Mode 2 (Strobed bidirectional I/O): This mode of operation of 8255 is also called as
strobed bidirectional I/O. This mode of operation provides 8255 with additional features for
communicating with a peripheral device on an 8-bit data bus. Handshaking signals are
provided to maintain proper data flow and synchronization between the data transmitter
and receiver. The interrupt generation and other functions are similar to mode 1.
In this mode, 8255 is a bidirectional 8-bit port with handshake signals. The Rd and WR
signals decide whether the 8255 is going to operate as an input port or output port.
· INTR – (Interrupt request) As in mode 1, this control signal is active high and
is used to interrupt the microprocessor to ask for transfer of the next data byte
to/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
the CPU 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
next byte may be sent by the processor. This signal enables the internal tristate
buffers to 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 input
Latches of 8255.
· IBF (Input buffer full) when the data is loaded into input buffer, this signal rises to
logic „1̏ . This can be used as an acknowledge that the data has been received by
the receiver.
· The waveforms in fig show the operation in Mode 2 for output as well as input
port.
· 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.
· The process of analog to digital conversion is a slow
· Process and the microprocessor have 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. The set asks of issuing an SOC pulse to ADC, reading
EOC 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 anywhere from a few microseconds in caseof 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:
· Ensure the stability of analog input, applied to the ADC.
· Issue start of conversion pulse to ADC
· Read end of conversion signal to mark the end of conversion processes.
· Read digital data output of the ADC as equivalent digital output.
· 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 as ample and hold circuit which samples the analog signal and holds it
constant for specific time duration. The microprocessor may issue a hold signal to the
sample and hold circuit.
· If the applied input changes before the complete conversion process is over, the
digital equivalent of the analog input calculated by the ADC may not be correct.
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
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.
· 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.
· 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 3 0 0 1 0
Wise Direction 4 0 0 0 1
5 1 0 0 0
1 1 0 0 0
2 0 0 0 1
Anti clock
wise 3 0 0 1 0
Direction 4 0 1 0 0
5 1 0 0 0
Table.2 An alternative scheme for rotating stepper motor shaft
Motion step A B C D
1 0 0 1 1
2 0 1 1 0
Clock wise 3 1 1 0 0
Direction 4 1 0 0 1
5 0 0 1 1
1 0 0 1 1
2 1 0 0 1
Anti clock
wise 3 1 1 0 0
Direction 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.
· Getting meaningful data from a keyboard requires three major tasks:
1. 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).
· Logic „0̏ is read by the microprocessor when the key is pressed.
Key Debounce:
Whenever a mechanical push-bottom is pressed or released once,the mechanical
components of the key do not change the positionsmoothly; rather it generates a transient
response. These may be interpreted as the multiple pressures and responded accordingly.
· 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 m sec 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 Bistable multivibrator 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.
· 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.
Interfacing 4x4 keyboard
Display Interface
Interfacing multiplexed 7-segment display
Interfacing with Advanced devices
4.1 MEMORY AND I/O INTERFACING
(Ref: Interfacing through Microprocessors by K. Subba Rao, Hi-tech publishers, P. 163-166)
In program controlled I/O data transfer scheme the transfer of data is completely under the control
of the microprocessor program. In this case an I/O operation takes place only when an I/O transfer instruction
is executed.
In an interrupt program controlled I/O an external device indicates directly to the microprocessor its
readiness to transfer data by a signal at an interrupt input of the microprocessor. When microprocessor
receives this signal the control is transferred to ISS (Interrupt service subroutine) which performs the data
transfer.
Hardware controlled I/O is also known as direct memory access DMA. In this case the data transfer
takes place directly between an I/O device and memory but not through microprocessors. Microprocessor
only initializes the process of data transfer by indicating the starting address and the number of words to be
transferred.
The instruction .set of any microprocessor contains instructions that transfer information to an I/O
device and to read information from an I/O device. In 8086 we have IN, OUT instructions for this purpose.
OUT instruction transfers information to an I/O device whereas IN instruction is used to read information
from an I/O device. Both the instructions perform the data transfer using accumulator AL or AX. The I/O
address is stored in register DX.
The port number is specified along with IN or OUT instruction. The external I/O interface decodes to
find the address of the I/O device. The 8 bit fixed port number appears on address bus A0 - A7 with A8 - A15
all zeros. The address connections above A15 are undefined for an I/O instruction. The 16 bit variable port
number appears on address connections A0 - A15. The above notation indicates that first 256 I/O port
addresses 00 to FF are accessed by both the fixed and variable I/O instructions. The I/O addresses from 0000
to FFFF are accessed by the variable I/O address.
I/O devices can be interfaced to the microprocessors using two methods. They are I/O mapped I/O
and memory mapped I/O. The I/O mapped I/O is also known as isolated I/O or
direct I/O. In I/O mapped I/O the IN and OUT instructions transfer data between the accumulator or memory
and I/O device. In memory mapped I/O the instruction that refers memory can perform the data transfer.
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.
While executing particular task it is necessary to access memory to get instruction codes and
data stored in memory. Microprocessor initiates the necessary signals when read or write operation is to be