Interfacing Switch

INTERFACING A SWITCH

Switch are mechanical devices that make or break the electrical connection. For interfacing a switch, we need to initialize a port as a input and check the logic level of the particular port. If logic 1 is present on the port means that switch is closed  and if logic 0 is present, switch is open.Proteus_simulation

 

Example:

This example turns the led connected to PB0 and switch at PA0 is made on.

#include<avr/io.h>

#include<util/delay.h>

int main()

{

DDRA=0x00;

DDRB=0x01;

while(1)

{

if((PINA  & 0x01))

{PORTB=0x01;

else

PORTB =0x00;

}

}

}

Video Reference

Share