Professional Documents
Culture Documents
Unit 4 - INTERFACING OF INPUTOUTPUT DEVICES WITH 8051
Unit 4 - INTERFACING OF INPUTOUTPUT DEVICES WITH 8051
4.1 Interfacing of LED, Switch, Relay, and buzzer with 8051 and its programming in C.
4.2 Interfacing of LED 7-segment display and 16 x 2 LCD with 8051 and its programming in
C.
4.3 Interfacing of ADC0808 with 8051 and its programming in C.
4.4 Interfacing of DAC0808 with 8051 and its programming in C to generate square,
triangular and saw tooth waveforms.
4.1 Interfacing of LED, Switch, Relay, and buzzer with 8051 and its programming in C.
Description:
LEDs are most commonly used in many applications for indicating the output. They find
huge range of applications as indicators during test to check the validity of results at different
stages. They are very cheap and easily available in a variety of shape, color and size.
The principle of operation of LEDs is very easy. A simple LEDs also servers as a basic
display devices, it On and OFF state express meaning full information about a device. The
common available LEDs have a 1.7v voltage drop that means when we apply above 1.7V, the
diode conducts. The diode needs 10mA current to glow with full intensity.
LEDs can be interfaced to the microcontroller in either common anode or common cathode
configuration. Here the LEDs are connected in common anode configuration because the
common cathode configuration consumes more power.
Algorithm:
• Start
• Generate delay.
• On the LED
• Generate delay.
• Repeat forever.
• End
Interfacing Diagram of LED –
Or
Program -
Switch -
A switch is an electrical component that can break an electrical circuit, interrupting the
current or diverting it from one conductor to another. A switch may be directly manipulated
by a human as a control signal to a system, or to control power flow in a circuit.
Interfacing Switch
Fig. 1 shows how to interface the switch to microcontroller. A simple switch has an open
state and closed state. However, a microcontroller needs to see a definite high or low
voltage level at a digital input.
A switch requires a pull-up or pull-down resistor to produce a definite high or low voltage
when it is open or closed. A resistor placed between a digital input and the supply voltage is
called a “pull-up” resistor because it normally pulls the pin’s voltage up to the supply.
Interfacing Switch with 8051
We now want to control the LED by using switches in 8051 Development board. It
works by turning ON a LED & then turning it OFF when switch is going to
LOW or HIGH.
The 8051 Development board has eight numbers of point LEDs, connected with
I/O Port lines (P0.0 – P0.7) to make port pins high. Eight switches, connected
with I/O port lines (P2.0 – P2.7) are used to control eight LEDs.
Buzzer Interfacing:
Following diagram shows the interfacing of microcontroller with buzzer.
When a push button is pressed, the buzzer will get ON and OFF (number of times set in the
code) and then stops.
The port P0 of the microcontroller is connected to buzzer. This type of connection is possible,
if the current requirements of the buzzer is not more than 20mA.
The output is in current source mode so that buzzer will turn ON when the output of the port
is logic LOW. Switch is connected to port P2 which remains at logic HIGH by pull up
resistor.
In some electronic applications we need to switch or control high voltages or high currents. In
these cases we may use electromagnetic or solid state relays. For example, it can be used to
control home appliances using low power electronic circuits.
Principle
Current flowing through the coil of the relay creates a magnetic field that attracts a lever and
changes the switch contacts. The coil current can be on or off so relays have two switch
positions and most have double throw (changeover) switch contacts.
Construction and working
Relays are made up of an electromagnet and a set of contacts generally based on Single Pole
Double Throw (SPDT) or Double Pole Double Throw (DPDT) switching method. It has 3
pins to perform a function –
COM = Common, always connect to NC; it is the moving part of the switch.
NC = Normally Closed, COM is connected to this when the relay coil is off.
NO = Normally Open, COM is connected to this when the relay coil is on.
EXTRA –
• A relay should not be directly connected to a microcontroller, it needs a driving
circuit due to the following reasons.
• A microcontroller will not able to supply current required for the proper working of a
relay. The maximum current that A89C51 microcontroller can sink is 15mA while a
relay needs about 50 – 100mA current.
• A relay is activated by energizing its coil. Microcontroller may stop working by the
negative voltages produced in the relay due to its back emf.
RELAY INTERFACING DIAGRAM -
Suppose we want to operate a relay using microcontroller with the use of button. When we
press button microcontroller will operate the relay.
Relay is connected to the microcontroller’s pin P2.0 (Port 2 and pin 0).
5. Interfacing of 7 segment Display to Microcontroller:
A seven-segment display uses Light Emitting Diodes to release light energy in photons.
The production emits light to show digits in all seven segments, with the eighth segment
being a decimal point. While the phenomenon happens, bear in mind that an LED is a solid-
state optical p-n junction diode.
Circuit Principle
Seven segment displays internally consist of 8 LEDs. In these LEDs, 7 LEDs are used to
indicate the digits 0 to 9 and single LED is used for indicating decimal point. Generally seven
segments are two types, one is common cathode and the other is common anode.
Common cathode –
In common cathode, all the cathodes of LEDs are tied together and labeled as com. and the
anode are left alone.
Common anode –
In common anode, seven segment display all the anodes are tied together and cathodes are
left freely. Below figure shows the internal connections of seven segment Display.
Introduction –
In order to read the physical data from real world and process under CPU in
the digital form we need Analog to Digital converter.
There are many source of physical data values like temperature, pressure, current,
voltage, distance sensor which produce an Analog signal in 0-20ma or 0-5V or 0-
10V.
To read this type of Analog data from real world we need to convert into digital
format.
ADC is the Analog to Digital converter, which converts analog data into digital
format; usually it is used to convert analog voltage into digital format.
Analog signal has infinite no of values like a sine wave or our speech, ADC
converts them into particular levels or states, which can be measured in numbers as
a physical quantity.
Ex-
Telephone modem is one of the examples of ADC, which is used for internet, it
converts analog data into digital data, so that computer can understand, because
computer can only understand Digital data.
One of the most commonly used ADC is ADC0808. ADC 0808 is a Successive
approximation type with 8 channels i.e. it can directly access 8 single ended analog
signals.
Features : ADC0808/ADC0809 :
Easy Interface to All Microprocessors
Operates Ratiometrically or with 5 VDC or Analog Span Adjusted Voltage
Reference
No Zero or Full-Scale Adjust Required
8-Channel Multiplexer with Address Logic
0V to VCC Input Range
Pin Diagram –
Or
IN0-IN7: Analog Input channels
MSB
In these systems microcontroller generates output which is in digital form but the
controlling system requires analog signal as they don't accept digital data thus
making it necessary to use DAC which converts digital data into equivalent analog
voltage.
FEATURES OF DAC
The range of voltage power supply will be ±4.5V to ±18VN
Non inverting digital i/ps are compatible with CMOS & TTL
The settling time is very fast 150 ns
Highest power dissipation will be 1000 mW
The digital data input is 8-bit parallel
Input slew rate is high speed 8 mA/μs
The match of Full-scale current is ±1 LSB
Low power utilization is 3 mW at ±5V
The range of operating temperature will be 0ºC-to- +75ºC
Pin Diagram –
OR
The IC gets the parallel 8-bit information from a microcontroller and changes
into an analog signal as an output.
The output from the digital to analog or DAC can be an existing quantity as
well as this required to be changed into a voltage parameter for applying in
several applications very simply.
So for changing the present parameter to voltage parameter, an operational
amplifier is utilized in the circuit above.
In addition, it includes some features like low current supply, inner
compensated i/p off-set voltage. i/p impedance, is high, settling time is fast,
harmonic distortion is low.
Applications of IC DAC0808
The applications of IC DAC0808 include the following.
Conversion of Audio
Electrical measurements
Analog circuits as well as digital circuits
And many more hobbyist applications