LED and Switch Interface
LED and Switch Interface
Switches and LEDs are the most widely used input/output devices of the 8051.
SWITCH INTERFACING:
CPU accesses the switches through ports. Therefore these switches are connected
to a microcontroller. This switch is connected between the supply and ground terminals.
A single microcontroller (consisting of a microprocessor, RAM and EEPROM and
several ports all on a single chip) takes care of hardware and software interfacing of the
switch.
These switches are connected to an input port. When no switch is pressed, reading
the input port will yield 1s since they are all connected to high (Vcc). But if any switch is
pressed, one of the input port pins will have 0 since the switch pressed provides the path
to ground. It is the function of the microcontroller to scan the switches continuously to
detect and identify the switch pressed.
The switches that we are using in our project are 4 leg micro switches of
momentary type.
Vcc
P2.0
Gnd
LED INTERFACING:
This current limiting resistor is connected to protect the port pins from sudden
flow of high currents from the power supply.
Thus in order to glow the LED, first there should be a current flow through the
LED. In order to have a current flow, a voltage difference should exist between the LED
terminals. To ensure the voltage difference between the terminals and as the positive
terminal of LED is connected to power supply Vcc, the negative terminal has to be
connected to ground. Thus this ground value is provided by the microcontroller port pin.
This can be achieved by writing an instruction “CLR P1.0”. With this, the port pin P1.0 is
initialized to zero and thus now a voltage difference is established between the LED
terminals and accordingly, current flows and therefore the LED glows. LED and switches
can be connected to any one of the four port pins.
Vcc
P1.0
Light-emitting diodes are elements for light signalization in electronics. They are
manufactured in different shapes, colors and sizes. For their low price, low consumption
and simple use, they have almost completely pushed aside other light sources- bulbs at
first place. They perform similar to common diodes with the difference that they emit
light when current flows through them.
It is important to know that each diode will be immediately destroyed unless its current is
limited. This means that a conductor must be connected in parallel to a diode. In order to
correctly determine value of this conductor, it is necessary to know diode’s voltage drop
in forward direction, which depends on what material a diode is made of and what colour
it is. Values typical for the most frequently used diodes are shown in table below: As
seen, there are three main types of
LEDs. Standard ones get ful
brightness at current of 20mA. Low
Current diodes get ful brightness at ten
times lower current while Super Bright diodes produce more intensive light than Standard
ones.
Since the 8051 microcontrollers can provide only low input current and since their pins
are configured as outputs when voltage level on them is equal to 0, direct connectining to
LEDs is carried out as it is shown on figure (Low current LED, cathode is connected to
output pin).
There is nothing simpler than this! This is the simplest way of controlling appearance of
some voltage on microcontroller’s input pin. There is also no need for additional
explanation of how these components operate.
If complete safety is needed, radical measures should be taken! The circuit, shown on the
figure (RS flip-flop), changes logic state on its output with the first pulse triggered by
contact bounce. Even though this is more expensive solution (SPDT switch), the problem
is definitely resolved! Besides, since the condensator is not used, very short pulses can be
also registered in this way. In addition to these hardware solutions, a simple software
solution is commonly applied too: when a program tests the state of some input pin and
finds changes, the check should be done one more time after certain time delay. If the
change is confirmed it means that switch (or pushbutton) has changed its position. The
advantages of such solution are obvious: it is free of charge, effects of disturbances are
eliminated too and it can be adjusted to the worst-quality contacts.