You are on page 1of 22

UNIT – 04

INTERFACING OF INPUT/OUTPUT 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.

1. LED Interfacing to Microcontroller:

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.

The following circuit describes “how to glow the LEDs”.

Algorithm:

• Start

• Declare port line as output

• Off the LED initially

• Generate delay.

• On the LED

• Generate delay.

• Repeat forever.

• End
Interfacing Diagram of LED –

Or
Program -

#include<reg51.h> //header file//


void delay_ms(unsigned int time) //This Function is used to cause delay between LED
ON and OFF events
{
unsigned int i, j;
for (j=0; j<time; j++)
for(i=0; i<113; i++);
}
void main() //the program execution stat point//
{
//unsigned int i; //data type//
while(1) //for continuous loop//
{
P0=0x55; //send the hexa value to the port0//
delay_ms(500);
P0=0xAA; //send the hexa value to the port0//
delay_ms(500);
}
}

2. SWITCH Interfacing to Microcontroller:

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.

3. BUZZER Interfacing to Microcontroller:


Buzzer is a electronic device that converts the electronic signal into buzzing noise, that is
applied to it.
It can be used as electronic bell or as quiz buzzer in many applications around us.

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.

4. Relay Interfacing to Microcontroller:


Relays are electrically operated switches that open and close the circuits by receiving
electrical signals from outside sources.

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 -

Interface of relay with microcontroller:


As relays have operating voltages of 6V/12V but microcontroller’s pin output voltage is 5V
so we can’t operate relay directly with the microcontroller’s pin voltage. So we need to
operate relay via transistor’s switch method.

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.

Cathodes of all the LEDs are connected together.

Anode of an individual LED is given +5V ( Logic 1) to glow it.

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.

Anodes of all the LEDs are connected together.


Cathode of an individual LED is given 0V( Logic 0) to glow it.
Interfacing of LED 7-segment with 89C51

6. Interfacing of 16 X 2 LCD display with Microcontroller: in


PDF
4.3 Interfacing of ADC0808 WITH 8051 & its
programming in C.

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

Key Specifications of ADC0808


 Resolution 8 Bits
 Single Supply 5 VDC
 Low Power 15 mW
 Conversion Time 100 µs

Pin Diagram –

Or
 IN0-IN7: Analog Input channels

 D0-D7: Data Lines

 A, B, C: Analog Channel select lines; A is LSB and C is

MSB

 OE: Output enable signal

 ALE: Address Latch Enable

 EOC: End of Conversion signal

 Vref+/Vref-: Differential Reference voltage input

 Clock: External ADC clock input


Interfacing of ADC 0808 with Microcontroller

Interfacing of ADC 0808 with Microcontroller

The total no of lines required are-


1. Data lines-8
2. ALE - 1
3. SOC - 1
4. EOC - 1
5. Output Enable - 1
6. ADD A to ADD C-3
 So for interfacing ADC 0808 with 8051 microcontroller, total 15
port lines are required.
 Port P2 is used to read data by connecting it to ADC 0808 data bus.
 Port P1 is used to remaining handshaking signals such as OE, ALE,
SOC, EOC, ADD A, B etc.
 SOC pin is connected to P1.0.
 ALE & OE is commonly connected to P1.1
 Address pins A, B, C are connected to P1.2, P1.3, and P1.4 & EOC
is connected to P1.5.
 The input pins DB0 – DB7 are connected to Port 2 of 8051.

4.4 Interfacing of DAC 0808 WITH 8051 & its


programming in C.
 The digital-to-analog converter (DAC) is a device widely used to convert digital
pulses to analog signals.
 Microcontroller are used in wide variety of applications like for measuring and
control of physical quantity like temperature, pressure, speed, distance, etc.

 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 –

 Pin1 (NC)- No connection


 Pin2 (GND)-Ground Pin
 Pin3 (VEE)-Negative (-ve) power supply
 Pin4 (IO)-Input/Output signal pin
 Pin5 (A1)- MSB (Digital i/p bit-1)
 Pin6 (A2)-Digital i/p bit-2
 Pin7 (A3)-Digital i/p bit-3
 Pin8 (A4)-Digital i/p bit-4
 Pin9 (A5)-Digital i/p bit-5
 Pin10 (A6)-Digital i/p bit-6
 Pin11 (A7)-Digital i/p bit-7
 Pin12 (A8)-Digital i/p bit-8 (Least Significant Bit)
 Pin13 (VCC)-Positive (+ve) power supply
 Pin14 (VREF+)-Positive (+ve) reference voltage
 Pin15 (VREF-)-Negative (-ve) reference voltage
 Pin16 (Compensation)-Compensation capacitor pin
Interfacing of ADC 0808 with Microcontroller

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

You might also like