Interfacing Switch and LED with 8051
Interfacing Switch and
LED with 8051
This
article is meant for beginners in the field of micro-controllers When I started
with micro-controllers as everyone I also need to learn how to interface a
switch with micro-controller.
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.
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.
Software Tools:
1. RIDE Compiler (Evaluation version)
2. WINISP Down loader (Free version )
Hardware:
1. P89C51
2. Push button switch
3. micro-controller board
Program:
#include<reg51.h>
sbit LED=P0^7; //port declaration
sbit SW1=P0^0;
sbit SW2=P0^1;
void main()
{
while(1)
{
if(SW1==0 || SW2==0) //if the SW1 or SW2 is pressed
{
LED=1;
}
else
LED=0;
}
}