SWITCH AND LED INTERFACING WITH THE MICROCONTROLLER:
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.
1. When the switch is open,
the total supply i.e., Vcc appears at the port pin P2.0
P2.0 = 1
When the switch is closed
i.e., when it is pressed, the total supply path is provided to ground. Thus the voltage value at the port
pin P2.0 will be zero.
P2.0 = 0
By reading the
pin status, the microcontroller identifies whether the switch is pressed or
not. When the switch is pressed, the corresponding related to this switch press
written in the program will be executed.
LED INTERFACING:
LED stands for Light Emitting Diode.
Microcontroller port pins
cannot drive these LEDs as these require high currents to switch on. Thus the
positive terminal of LED is directly connected to Vcc, power supply and the
negative terminal is connected to port pin through a current limiting resistor.
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.


No comments:
Post a Comment