Switches are the basic electronic component that allow circuit ON or OFF. It breaks the circuit or make the circuit at a time.
- In the above circuit diagram, SPST switch has been connected to P3.0 pin of 8051 microcontroller and LED Bargraph has been used to test the binary counter on LEDs. When you press the switch and then release it, the counter will start automatically. This may not possible on software and but, properly can be implemented on hardware.
2. Switch counter
Interfacing:

- In the above circuit diagram, SPST switch has been connected to P3.0 pin of 8051 microcontroller and LED Bargraph has been used to test the binary counter on LEDs. When you press the switch and then release it, the counter will start automatically. This may not possible on software and but, properly can be implemented on hardware.
Code:
1.Basic switch
#include "REG52.h"
#define LED P2
sbit swt2=P3^0; //switch1
void main()
{
while(1)
{
if(swt2==0)
LED=0xFF;
else
LED=0x00;
}
}
2. Switch counter
#include"REG52.h"
sbit sw=P3^0; //switch
#define LED P2
int count=0,i;
void main()
{
sw=1; //internally 1
while(1)
{
if(sw==0) //external value of switch i.e. if it is pressed
{
LED=count; //switch
count++;
for (i=0;i<5000;i++);
if (count==255)
{
count=0;
}
}
}
}
Comments
Post a Comment