MIC Unit 05
MIC Unit 05
C Program:-
#include< reg51.h>
unsigned char d;
void main(void)
{
while(1)
{
for(d=0; d<255; d++)
{
P1 = d;
}
for(d=255; d>0; d--)
{
P1 = d;
}
November 8, 2023 1
Unit 05:Interfacing With 8051 MIC (5ETC01)
}
}
Question 2: Draw the interfacing of DAC 0808 with 8051 & write an 8051 C program to
generate a Sign Wave.
Solution:
C Program:-
#include<reg51.h>
sfr DAC = 0x80; //Port P0 address
November 8, 2023 2
Unit 05:Interfacing With 8051 MIC (5ETC01)
void main()
{
int sin_value[12] = {128,192,238,255,238,192,128,64,17,0,17,64};
int i;
while(1){
//infinite loop for LED blinking
for(i = 0; i<12; i++){
DAC = sin_value[i];
}
}
}
Question 2: Draw the interfacing of DAC 0808 with 8051 & write an 8051 C program to
generate a Staircase Wave.
Solution:
November 8, 2023 3
Unit 05:Interfacing With 8051 MIC (5ETC01)
Question 3: What is Opto-isolator? What is the advantage of using it for interfacing the
devices
Solution:
• An opto-isolator, also known as an optocoupler, is an electronic component that
provides electrical isolation between two separate electrical circuits using light. It
typically consists of a light-emitting diode (LED) and a photosensitive transistor or
photodiode enclosed in a single package.
• Here's how it works:
1. Input Side: The input side of the opto-isolator consists of an LED. When a
voltage is applied to the LED's anode (positive side) and cathode (negative side),
the LED emits light. The amount of light emitted is directly proportional to the
input voltage applied.
2. Output Side: The output side contains a photosensitive transistor or photodiode.
When light from the LED falls on the phototransistor or photodiode, it conducts
electricity, allowing current to flow through the output circuit. The output circuit
is electrically isolated from the input circuit, ensuring that there is no direct
electrical connection between them.
• Advantages of using opto-isolators for interfacing devices:
1. Electrical Isolation: Opto-isolators provide complete electrical isolation between
the input and output circuits. This isolation prevents the transfer of electrical noise,
voltage spikes, and ground loops from one circuit to the other. It helps protect
sensitive components and digital devices from potential damage or interference.
2. Safety: Opto-isolators are commonly used to provide safety in high-voltage and
high-current applications. They protect operators and sensitive equipment by
ensuring that there is no direct electrical connection between potentially hazardous
or noisy environments and control circuits.
3. Compatibility: Opto-isolators can be used to interface devices with different
voltage levels or signal types. They allow you to connect circuits operating at
different voltage potentials without risk of damaging the connected components.
4. Noise Immunity: Opto-isolators are immune to electromagnetic interference
(EMI) and radio-frequency interference (RFI). They can be used in noisy industrial
environments without experiencing signal degradation.
5. High Reliability: Opto-isolators have no moving parts and are solid-state devices,
which makes them reliable and durable. They have a long operational life and are
less prone to wear and tear.
6. Voltage and Current Level Shifting: Opto-isolators can be used to shift voltage
and current levels between different parts of a circuit, making them versatile for a
wide range of applications.
7. Reduced Cross-Talk: By preventing direct electrical connections, opto-isolators
minimize the risk of cross-talk and interference between circuits.
November 8, 2023 4
Unit 05:Interfacing With 8051 MIC (5ETC01)
C Program:-
November 8, 2023 5
Unit 05:Interfacing With 8051 MIC (5ETC01)
Question 5: Draw the interfacing of a Stepper Motor to 8051 through Opto-isolator. A Switch
is connected on pin P2.7. Write a C program to monitor the status of SW & perform, a) If SW
= 0, the stepper motor moves clockwise & (b) If SW = 1, it moves counter clockwise
Solution:-
C Program:-
November 8, 2023 6
Unit 05:Interfacing With 8051 MIC (5ETC01)
November 8, 2023 7
Unit 05:Interfacing With 8051 MIC (5ETC01)
November 8, 2023 8
Unit 05:Interfacing With 8051 MIC (5ETC01)
3. Control Lines:
- VSS (Ground):Connect VSS to ground (GND).
- VDD (Supply Voltage):Connect VDD to +5V.
- V0 (Contrast Control): Connect V0 to a potentiometer for contrast control, or you
can connect it to ground if you don’t need contrast adjustment.
- A (Anode) and K (Cathode): Connect A to +5V and K to ground for backlighting if
your LCD has a backlight.
Question 8 : Draw & explain in brief about the interfacing of (a) Opto-isolator & b) Relay to
any port pin of 8051.
Solution :-
a) Opto-isolator:-
November 8, 2023 9
Unit 05:Interfacing With 8051 MIC (5ETC01)
• The contacts can be normally open (NO) or normally closed (NC). In the
NC type, the contacts are closed when the coil is not energized. In the NO,
the contacts are open when the coil is unenergized.
• There can one or more contacts. For example, we can have SPST (single
pole, single throw), SPDT (single pole, double throw), and DPDT (double
pole, double throw) relays.
• The voltage and current needed to energize the coil. The voltage can vary
from a few volts to 50 volts, while the current can be from a few mA to 20
mA. The relay has a minimum voltage, below which the coil will not be
energized
• 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.
November 8, 2023 10
Unit 05:Interfacing With 8051 MIC (5ETC01)
Question 11 : Draw the interfacing of a 4 x 4 Matrix Key board to 8051 & Give the Flow
chart to Read a “key pressed” from keyboard
Solution:-
November 8, 2023 11