Monday, 3 September 2018

8051: Switch Interface Code


Description:

Interfacing switch with 8051.We now want to control the LED by using switches in 8051Development board. It works by turning ON a LED & then turning it OFF when switch is going to LOW or HIGH.


Code:
#include<reg51.h>
sbit sw=P2^0;
sbit led=P2^1;
void delay(int n);
void delay(int n)
{
        int i,j;
        for(i=0;i<n;i++)
        {
        for(j=0;j<100;j++);
        }
}
void main()
{
while(1)
{
if(sw==0)
{
led=1;
            delay(100);

}
else
{
led=0;

}
}
}



Circuit Diagram:



No comments:

Post a Comment