MODULE-5: Interfacing: Microcontroller Notes:18EE52
MODULE-5: Interfacing: Microcontroller Notes:18EE52
MODULE-5: Interfacing: Microcontroller Notes:18EE52
MODULE-5:Interfacing
Structure
5.3 ADC, DAC and sensor interfacing: ADC 0808 interfacing to 8051,
5.6 Motor control: Relay, PWM, DC and stepper motor: Relays and opt isolators,
5.9 8051 interfacing with 8255: Programming the 8255, 8255 interfacing, C programming
for 8255
Objectives
1. To Interface 8051 with real-world devices such as LCDs and keyboards, ADC, DAC
chips and sensors.
2. To Interface 8031/51 with external memories, 8255 chip to add ports and relays,
optisolators and motors.
LCD operation
In recent years the LCD is finding widespread use replacing LEDs (seven-segment LEDs or
other multi segment LEDs). This is due to the following reasons:
The LCD discussed in this section has 14 pins. The function of each pin is given in Table 12-
1. Figure 12-1 shows the pin positions for various LCDs.
VCC> VSS> and VEE
While Vcc and Vss provide +5V and ground, respectively, VEE is used for controlling LCD
contrast.
There are two very important registers inside the LCD. The RS pin is used for their selection
as follows. If RS = 0, the instruction command code register is selected, allowing the user to
send a command such as clear display, cursor at home, etc. If RS = 1 the data register is
selected, allowing the user to send data to be displayed on the LCD.
R/W, read/write
R/W input allows the user to write information to the LCD or read information from it. R/W
= 1 when reading; R/W = 0 when writing.
E, enable
The enable pin is used by the LCD to latch information presented to its data pins.
When data is supplied to data pins, a high-to-low pulse must be applied to this pin in order
for the LCD to latch in the data present at the data pins. This pulse must be a minimum of
450 ns wide.
DO-D7
1. The 8-bit data pins, DO – D7, are used to send information to the LCD or read the
contents of the LCD’s internal registers.
2. To display letters and numbers, we send ASCII codes for the letters A – Z, a – z, and
numbers 0 – 9 to these pins while making RS = 1.
3. We also use RS = 0 to check the busy flag bit to see if the LCD is ready to receive
information. The busy flag is D7 and can be read when R/W = 1 and RS = 0, as
follows: if R/W= 1, RS = 0. When D7 = 1 (busy flag = 1), the LCD is busy taking
care of internal operations and will not accept any new information. When D7 = 0, the
LCD is ready to receive new information.
Note: It is recommended to check the busy flag before writing any data to the LCD.
To send any of the commands to the LCD, make pin RS = 0. For data, make RS = 1. Then
send a high-to-low pulse to the E pin to enable the internal latch of the LCD.
5.1.1 Sending code or data to the LCD with checking busy flag
Notice in the above program that the busy flag is D7 of the command register. To read the
command register we make R/W = 1 and RS = 0, and a L-to-H pulse for the E pin will
provide us the command register. After reading the command register, if bit D7 (the busy flag)
is high, the LCD is busy and no information (command or data) should be issued to it. Only
when D7 = 0 can we send data or commands to the LCD. Notice in this method that no time
delays are used since we are checking the busy flag before issuing commands or data to the
LCD. Contrast the Read and Write timing for the LCD. Note that the E line is negative-edge
triggered for the write while it is positive-edge triggered for the read.
In the LCD, one can put data at any location. The following shows address locations and how
they are accessed.
where AAAAAAA = 0000000 to 0100111 for line 1 and AAAAAAA – 1000000 to 1100111
for line 2.
The upper address range can go as high as 0100111 for the 40-charac-ter-wide LCD, while
for the 20-character-wide LCD it goes up to 010011 (19 decimal = 10011 binary). Notice that
the upper range 0100111 (binary) = 39 decimal, which corresponds to locations 0 to 39 for
the LCDs of 40×2 size.
Example 5-3
Write an 8051 C program to send letters ‘M’, ‘D’, and ‘£’ to the LCD using delays.
Example 5-3
1. At the lowest level, keyboards are organized in a matrix of rows and columns. The
CPU accesses both rows and columns through ports; therefore, with two 8-bit ports,
an 8 x 8 matrix of keys can be connected to a microprocessor.
2. When a key is pressed, a row and a column make a contact; otherwise, there is no
connection between rows and columns. In IBM PC keyboards, a single
microcontroller (consisting of a microprocessor, RAM and EPROM, and several ports
all on a single chip) takes care of hardware and software interfacing of the keyboard.
3. In such systems, it is the function of programs stored in the EPROM of the
microcontroller to scan the keys continuously, identify which one has been activated,
and present it to the motherboard. In this section we look at the mechanism by which
the 8051 scans and identifies the key.
1. Figure5.5 shows a 4 x 4 matrix connected to two ports. The rows are connected to an
output port and the columns are connected to an input port.
2. If no key has been pressed, reading the input port will yield 1 s for all columns since
they are all connected to high (Vcc).
3. If all the rows are grounded and a key is pressed, one of the columns will have 0 since
the key pressed provides the path to ground. It is the function of the microcontroller to
scan the keyboard continuously to detect and identify the key pressed. How it is done
is explained next.
1. To detect a pressed key, the microcontroller grounds all rows by providing 0 to the
output latch, then it reads the columns. If the data read from the columns is D3 – DO
= 1111, no key has been pressed and the process continues until a key press is
detected.
2. However, if one of the column bits has a zero, this means that a key press has
occurred. For example, if D3 – DO = 1101, this means that a key in the Dl column has
been pressed.
3. After a key press is detected, the microcontroller will go through the process of
identifying the key. Starting with the top row, the microcontroller grounds it by
providing a low to row DO only; then it reads the columns.
4. If the data read is all Is, no key in that row is activated and the process is moved to
the next row. It grounds the next row, reads the columns, and checks for any zero.
This process continues until the row is identified. After identification
Example 5-4
Identify the row and column of the pressed key for each of the following.
Solution:
1. The row belongs to DO and the column belongs to D2; therefore, key number 2 was
pressed.
2. The row belongs to Dl and the column belongs to D3; therefore, key number 7 was
pressed
1. To make sure that the preceding key has been released, Os are output to all rows
at once, and the columns are read and checked repeatedly until all the columns
are high. When all columns are found to be high, the program waits for a short
amount of time before it goes to the next stage of waiting for a key to be
pressed.
2. To see if any key is pressed, the columns are scanned over and over in an infinite loop
until one of them has a 0 on it. Remember that the output latches connected to rows
still have their initial zeros (provided in stage 1), making them
grounded. After the key press detection, the microcontroller waits 20 ms for
the bounce and then scans the columns again. This serves two functions: (a) it
ensures that the first key press detection was not an erroneous one due to a
spike noise, and (b) the 20-ms delay prevents the same key press from being
interpreted as a multiple key press. If after the 20Tins delay the key is still
pressed, it goes to the next stage to detect which row it belongs to; otherwise,
it goes back into the loop to detect a real key press.
3. To detect which row the key press belongs to, the microcontroller grounds one
row at a time, reading the columns each time. If it finds that all columns are
high, this means that the key press cannot belong to that row; therefore, it
grounds the next row and continues until it finds the row the key press belongs
to. Upon finding the row that the key press belongs to, it sets up the starting
address for the look-up table holding the scan codes (or the ASCII value) for
that row and goes to the next stage to identify the key.
4. To identify the key press, the microcontroller rotates the column bits, one bit
at a time, into the carry flag and checks to see if it is low. Upon finding the
zero, it pulls out the ASCII code for that key from the look-up table; otherwise,
it increments the pointer to point to the next element of the look-up table.
5.3 ADC, DAC and sensor interfacing: ADC 0808 interfacing to 8051
1. Analog to digital converters are among the most widely used devices for data
acquisitions. Digital computers use binary (discrete) value but in physical world
everything is analog (continuous).
2. A physical quantity is converted to electrical signals using device called transducer or
also called as sensors. Sensors and many other natural quantities produce an output
that is voltage (or current).
3. Therefore we need an analog - to - digital converter to translate the analog signal to
digital numbers so that the microcontroller can read and process them. An ADC has
an n bit resolution where n can be 8, 10, 16, 0r even 24 bits. The higher resolution
ADC provides a smaller step size, where step size is smallest change that can be
discerned by an ADC.
ADC0808 has 8 analog inputs. ADC0808 allows us to monitor up to 8 different analog inputs
using only a single chip. ADC0808 has an 8-bit data output. The 8 analog inputs channels are
multiplexed and selected according to table given below using three address pins, A, B, and C.
a) CS
Chip select is an active low input used to activate the ADC0804 chip. To access the
ADC0804, this pin must be low.
b) RD (read)
This is an input signal and is active low. The ADC converts the analog input to its binary
equivalent and holds it in an internal register. RD is used to get the converted data out of the
ADC0804 chip. When CS = 0, if a high-to-low pulse is applied to the RD pin, the 8-bit digital
output shows up at the DO – D7 data pins. The RD pin is also referred to as output enable
(OE).
This is an active low input used to inform the ADC0804 to start the conversion
process. If CS = 0 when WR makes a low-to-high transition,
the ADC0804 starts converting the analog input value of Vin to an 8-bit digital number.
CLK IN is an input pin connected to an external clock source when an external clock is used
for timing. However, the 804 has an internal clock generator. To use the internal clock
generator (also called self-clocking) of the ADC0804, the CLK IN and CLK R pins are
connected to a capacitor and a resistor.
Typical values are R = 10K ohms and C = 150 pF. Substituting in the above equation, we
get/= 606 kHz. In that case, the conversion time is 110 us.
This is an output pin and is active low. It is a normally high pin and when the conversion is
finished, it goes low to signal the CPU that the converted data is ready to be picked up. After
INTR goes low, we make CS = 0 and send a high-to-low pulse to the RD pin to get the data
out of the ADC0804 chip.
These are the differential analog inputs where Vjn = Vjn (+) – Vjn (-). Often the Vjn (-) pin is
connected to ground and the Vjn (+) pin is used as the analog input to be converted to digital.
g) Vcc
This is the +5 volt power supply. It is also used as a reference voltage when the Vref/2 input
(pin 9) is open (not connected). This is discussed next.
h) Vref/2
Pin 9 is an input voltage used for the reference voltage. If this pin is open (not connected), the
analog input voltage for the ADC0804 is in the range of 0 to 5 volts (the same as the Vcc pin).
i) DO-D7
DO – D7 (D7 is the MSB) are the digital data output pins since ADC0804 is a parallel ADC
chip. These are tri-state buffered and the converted data is accessed only when CS = 0 and
RD is forced low. To calculate the output voltage, use the following formula.
These are the input pins providing the ground for both the analog signal and the digital signal.
Analog ground is connected to the ground of the analog Vin while digital ground is connected
to the ground of the Vcc pin. The reason that we have two ground pins is to isolate the analog
Vin signal from transient voltages caused by digital switching of the output DO – D7. Such
isolation contributes to the accuracy of the digital data output. In our discussion, both are
connected to the same ground; however, in the real world of data acquisition the analog and
digital grounds are handled separately.
From this discussion we conclude that the following steps must be followed for data
conversion by the ADC0804 chip.
The MAX1112 is an 8-bit serial ADC chip with 8 channels of analog input. It has a
single dout to bring out the digital data after it has been converted. It is compatible with a
popular SPI and Microwire serial standard. The following are descriptions of the MAX1112
pins.
a) CHO – CH7
CHO – CH7 are 8 channels of the analog inputs. In the single-ended mode, each of
the channels can be used for an analog input where the COM pin is used as a ground
reference for all the channels. In single-ended mode, 8 channels of input allow us to read 8
different analog inputs. We select the input channel by sending in the control byte via the
DIN pin. In differential mode, we have 4 sets of 2-channel differentials. CHO and CHI go
together, and CH2 -CH3, and so on.
b) COM
Ground reference for the analog input in single-ended mode.
c)CS
Chip select is an active low input used to select the MAX1112 chip.
d)SCLK
Serial clock input. SCLK is used to bring data out and send in the control byte, one bit at a
time.
e) dout
Serial data out. The digital data is clocked out one bit at a time on the H-to-L edge
(falling edge) of SCLK.
Serial strobe output. In internal clock mode this indicates end-of-conversion. It goes
high when the conversion is complete.
h) vdd
vdd is the +5 volt power supply.
Example 5-7
Find the MAX1112 control byte for (a) CHO, and (b) CH3. Assume single-ended, unipolar,
internal clock, and fully operational modes.
Solution:
From Figure 13-14, we have the following:
(a) 10001110 (8E in hex) (b) 10111110 (BE in hex)
1. When the last bit of the control byte, PDO, is sent in, the conversion starts, and
SSTRB goes low. The end-of-conversion state is indicated by SSTRB going high,
which happens 55 us after PDO is clocked in.
2. We can either wait 55 µs, or monitor SSTRB before we get the digital data out of the
ADC chip. Next we show how to get digital data out of the MAX1112.
The following is Assembly code for reading out digital data in the MAX1112:
//The following program selects the channel and //reads ADC data
2. Recall from your digital electronics book the two methods of creating a DAC: binary
weighted and R/2R ladder. The vast majority of integrated circuit DACs, including
the MC1408 (DAC0808) used in this section use the R/2R method since it can
achieve a much higher degree of precision.
3. The first criterion for judging a DAC is its resolution, which is a function of the
number of binary inputs.
4. The common ones are 8, 10, and 12 bits. The number of data bit inputs decides the
resolution of the DAC since the number of analog output levels is equal to 2″,
where n is the number of data bit inputs.
5. Therefore, an 8-input DAC such as the DAC0808 provides 256 discrete voltage (or
current) levels of output. Similarly, the 12-bit DAC provides 4096 discrete voltage
levels. The total current provided by the Iout pin is a function of the binary numbers at
the DO – D7 inputs of the DAC0808 and the reference current (Iref), and is as follows:
Where DO is the LSB, D7 is the MSB for the inputs, and Iref is the input current that
must be applied to pin 14. The Iref current is generally set to 2.0 mA.
Example 5-8
Example 5-9
DAC interfacing in C
a) Temperature sensors
1. Transducers convert physical data such as temperature, light intensity, flow, and
speed to electrical signals. Depending on the transducer, the output produced is in the
form of voltage, current, resistance, or capacitance. For example, temperature is
converted to electrical signals using a transducer called a thermistor.
2. A thermistor responds to temperature change by changing resistance, but its response
is not linear.
3. The complexity associated with writing software for such nonlinear devices has led
many manufacturers to market a linear temperature sensor. Simple and widely used
linear temperature sensors include the LM34 and LM35 series from National
Semiconductor Corp.
b) LM35
The LM35 series sensors are precision integrated-circuit temperature sensors whose output
voltage is linearly proportional to the Celsius (centigrade) temperature. The LM35 requires
no external calibration since it is internally calibrated. It outputs 10 mV for each degree of
centigrade temperature.
1. Signal conditioning is widely used in the world of data acquisition. The most common
transducers produce an output in the form of voltage, current, charge, capacitance, and
resistance.
2. However, we need to convert these signals to voltage in order to send input to an A-
to-D converter. This conversion (modification) is commonly called signal
conditioning. Signal conditioning can be a current-to-voltage conversion or a signal
amplification.
3. For example, the thermistor changes resistance with temperature. The change of
resistance must be translated into voltages in order to be of any use to an ADC. Look
at the case of connecting an LM35 to an ADC0848. Since the ADC0848 has 8-bit
resolution with a maximum of 256 (28) steps and the LM35 (or LM34) produces 10
mV for every degree of temperature change, we can condition Vin of the ADC0848 to
produce a Vout of 2560 mV (2.56 V) for full-scale output.
4. Therefore, in order to produce the full-scale Vout of 2.56 V for the ADC0848, we need
to set Vref = 2.56. This makes Vout of the ADC0848 correspond directly to the
temperature as monitored by the LM35.
5.6 Motor control: Relay, PWM, DC and stepper motor: Relays and opt isolators
Electromechanical relays
1. A relay is an electrically controllable switch widely used in industrial controls,
automobiles, and appliances. It allows the isolation of two separate sections of a
system with two different voltage sources. For example, a +5V system can be isolated
from a 120V system by placing a relay between them. One such relay is called an
electromechanical (or electromagnetic) relay (EMR)
2. The EMRs have three components: the coil, spring, and contacts. In Figure 17-1, a
digital +5V on the left side can control a 12V motor on the right side without any
physical contact between them.
3. When current flows through the coil, a magnetic field is created around the coil (the
coil is energized), which causes the armature to be attracted to the coil. The
armature’s contact acts like a switch and closes or opens the circuit. When the coil is
not energized, a spring pulls the armature to its normal state of open or closed.
4. In the block diagram for electromechanically relays (EMR) we do not show the spring,
but it does exist internally. There are all types of relays for all kinds of applications. In
choosing a relay the following characteristics need to be considered:
The maximum DC/AC voltage and current that can be handled by the contacts. This is in the
range of a few volts to hundreds of volts, while the current can be from a few amps to 40A or
more, depending on the relay. Notice the difference between this voltage/current specification
and the voltage/current needed for energizing the coil. The fact that one can use such a small
amount of voltage/current on one side to handle a large amount of voltage/current on the
other side is what makes relays so widely used in industrial controls.
Digital systems and microcontroller pins lack sufficient current to drive the relay. While the
relay’s coil needs around 10 mA to be energized, the microcontroller’s pin can provide a
maximum of 1-2 mA current. For this reason, we place a driver, such as the ULN2803, or a
power transistor between the microcontroller and the relay
1. Another widely used relay is the solid-state relay. In this relay, there is no coil, spring,
or mechanical contact switch.
2. The entire relay is made out of semiconductor materials. Because no mechanical parts
are involved in solid-state relays, their switching response time is much faster than
that of electromechanical relays.
3. Another problem with the electromechanical relay is its life expectancy. The life cycle
for the electromechanical relay can vary from a few hundred thousands to few million
operations.
4. Wear and tear on the contact points can cause the relay to malfunction after a while.
Solid-state relays have no such limitations. Extremely low input current and small
packaging make solid-state relays ideal for microprocessor and logic control
switching.
5. They are widely used in controlling pumps, solenoids, alarms, and other power
applications. Some solid-state relays have a phase control option, which is ideal for
motor-speed control and light-dimming applications.
Another popular switch is the reed switch. When the reed switch is placed in a magnetic field,
the contact is closed. When the magnetic field is removed, the contact is forced open by its
spring. The reed switch is ideal for moist and marine environments where it can be
submerged in fuel or water. They are also widely used in dirty and dusty atmospheres since
they are tightly sealed.
Optoisolator
1. In some applications we use an optoisolator (also called optocoupler) to isolate two
parts of a system. An example is driving a motor. Motors can produce what is called
back EMF, a high voltage spike produced by a sudden change of current as indicated
in the V = Ldi/dt formula.
2. In situations such as printed circuit board design, we can reduce the effect of this
unwanted voltage spike (called ground bounce) by using decoupling capacitors (see
Appendix C).
3. In systems that have inductors (coil winding), such as motors, decoupling capacitor or
a diode will not do the job. In such cases we use optoisolators. An optoisolator has an
LED (light-emitting diode) transmitter and a photosensor receiver, separated from
each other by a gap.
4. When current flows through the diode, it transmits a signal light across the gap and
the receiver produces the same signal with the same phase but a different current and
amplitude.
5. Optoisolators are also widely used in communication equipment such as modems.
This allows a computer to be connected to a telephone line without risk of damage
from power surges.
6. The gap between the transmitter and receiver of optoisolators prevents the electrical
current surge from reaching the system.
Stepper motors
1. A stepper motor is a widely used device that translates electrical pulses into
mechanical movement. In applications such as disk drives, dot matrix printers, and
robotics, the stepper motor is used for position control. Stepper motors commonly
have a permanent magnet rotor (also called the shaft) surrounded by a stator
2. There are also steppers called variable reluctance stepper motors that do not have a
PM rotor.
3. The most common stepper motors have four stator windings that are paired with a
center-tapped common
4. This type of stepper motor is commonly referred to as a. four-phase or unipolar
stepper motor.
1. How much movement is associated with a single step? This depends on the internal
construction of the motor, in particular the number of teeth on the stator and the rotor.
The step angle is the minimum degree of rotation associated with a single step.
Various motors have different step angles.
2. The term steps per revolution. This is the total number of steps needed to rotate one
complete rotation or 360 degrees (e.g., 180 steps x 2 degrees = 360).
3. It must be noted that perhaps contrary to one’s initial impression, a stepper motor
does not need more terminal leads for the stator to achieve smaller steps. All the
stepper motors discussed in this section have 4 leads for the stator winding and 2
COM wires for the center tap. Although some manufacturers set aside only one lead
for the common signal instead of two, they always have 4 leads for the stators. Next
we discuss some associated terminology in order to understand the stepper motor
further.
Motor speed
The motor speed, measured in steps per second (steps/s), is a function of the switching rate.
By changing the length of the time delay loop, we can achieve various rotation speeds.
Holding torque
The following is a definition of holding torque: “With the motor shaft at standstill or zero
rpm condition, the amount of torque, from an external source, required to break away the
shaft from its holding position. This is measured with rated voltage and current applied to the
motor.” The unit of torque is ounce-inch (or kg-cm).
Wave drive 4-step sequence
In addition to the 8-step and the 4-step sequences discussed earlier, there is another sequence
called the wave drive 4-step sequence.
Example 5-10
A switch is connected to pin P2.7. Write a program to monitor the status of SW and perform
the following:
1. If SW = 0, the stepper motor moves clockwise.
2. If SW = 1, the stepper motor moves counterclockwise.
Example 5-11
A switch is connected to pin P2.7. Write a C program to monitor the status of SW and
perform the following:
1. If SW = 0, the stepper motor moves clockwise.
2. If SW = 1, the stepper motor moves counterclockwise.
1. A direct current (DC) motor is another widely used device that translates electrical
pulses into mechanical movement. In the DC motor we have only + and – leads.
Connecting them to a DC voltage source moves the motor in one direction.
2. By reversing the polarity, the DC motor will move in the opposite direction. One can
easily experiment with the DC motor.
3. For example, small fans used in many motherboards to cool the CPU are run by DC
motors. By connecting their leads to the + and – voltage source, the DC motor moves.
The DC motor rotation for clockwise (CW) and counterclockwise (CCW) rotations.
1. The speed of the motor depends on three factors: (a) load, (b) voltage, and (c) current.
For a given fixed load we can maintain a steady speed by using a method called pulse
width modulation (PWM).
2. By changing (modulating) the width of the pulse applied to the DC motor we can
increase or decrease the amount of power provided to the motor, thereby increasing or
decreasing the motor speed. Notice that, although the voltage has a fixed amplitude, it
has a variable duty cycle.
3. That means the wider the pulse, the higher the speed. PWM is so widely used in DC
motor control that some microcontrollers come with the PWM circuitry embedded in
the chip. In such microcontrollers all we have to do is load the proper registers with
the values of the high and low portions of the desired pulse, and the rest is taken care
by the microcontroller.
4. This allows the microcontroller to do other things. For microcontrollers without
PWM circuitry, we must create the various duty cycle pulses using software, which
prevents the microcontroller from doing other things.
5. The ability to control the speed of the DC motor using PWM is one reason that DC
motors are preferable over AC motors.
6. AC motor speed is dictated by the AC frequency of the voltage applied to the motor
and the frequency is generally fixed. As a result, we cannot control the speed of the
AC motor when the load is increased. As was shown earlier, \\e can also change the
DC motor’s direction and torque.
Example 5-12
Refer to the figure in this example. Write a program to monitor the status of the switch and
perform the following:
1. If P2.7 = 1, the DC motor moves with 25% duty cycle pulse.
2. If P2.7 = 0, the DC motor moves with 50% duty cycle pulse.
Example 5-13
Two switches are connected to pins P2.0 and P2.1. Write a C program to monitor the status of
both switches and perform the following: SW2(P2.7) SW1(P2.6)
1. DC motor moves slowly (25% duty cycle).
2. DC motor moves moderately (50% duty cycle).
3. DC motor moves fast (75% duty cycle).
4. DC motor moves very fast (100% duty cycle).
5.9 8051 interfacing with 8255: Programming the 8255, 8255 interfacing, C
programming for 8255
In this section we study the 8255 chip, one of the most widely used I/O chips. We first
describe its features and then show the connection between the 8031/51 and 8255 chips.
RESET
This is an active-high signal input into the 8255 used to clear the control register. When
RESET is activated, all ports are initialized as input ports. In many designs this pin is
connected to the RESET output of the system bus or grounded to make it inactive. Like all
1C input pins, it should not be left unconnected.
While ports A, B, and C are used to input or output data, it is the control register that must be
programmed to select the operation mode of the three ports. The ports of the 8255 can be
programmed in any of the following modes.
1. Mode 0, simple I/O mode. In this mode, any of the ports A, B, CL, and CU can
be programmed as input or output. In this mode, all bits are out or all are in. In
other words, there is no such thing as single-bit control as we have seen in
PO – P3 of the 8051. Since the vast majority of applications involving the 8255
use this simple I/O mode, we will concentrate on this mode in this chapter.
2. Mode 1. In this mode, ports A and B can be used as input or output ports with
handshaking capabilities. Handshaking signals are provided by the bits of port
C.
3. Mode 2. In this mode, port A can be used as a bidirectional I/O port with hand
shaking capabilities whose signals are provided by port C. Port B can be used
either in simple I/O mode or handshaking mode 1.
4. BSR (bit set/reset) mode. In this mode, only the individual bits of port C can
be programmed.
Example 5-14
Find the control word of the 8255 for the following configurations:
1. All the ports of A, B, and C are output ports (mode 0).
2. PA = in, PB = out, PCL = out, and PCH = out.
Solution:
(a) 1000 0000 = 80H (b) 1001 0000 = 90H
The 8255 chip is programmed in any of the 4 modes mentioned earlier by sending a byte
(Intel calls it a control word) to the control register of the 8255. We must first find the port
addresses assigned to each of ports A, B, C, and the control register. This is called
mapping the I/O port.
the 8255 is connected to an 8031/51 as if it is RAM memory. Notice the use of RD and WR
signals. This method of connecting an I/O chip to a CPU is called memory-mapped I/O, since
it is mapped into memory space. In other words, we use memory space to access I/O devices.
For this reason we use instructions such as MOVX to access the 8255. In Chapter 14 we used
MOVX to access RAM and ROM. For an 8255 connected to the 8031/51 we must also use
the MOVX instruction to communicate with it.
Outcomes
CO5: Analyse Interfacing of 8051 Microcontroller for different I/O devices and 8255
Microcontroller. [L4, MODULE 5]