m
Line 1: Line 1:
 
+
In this tutorial, we will interface a simple switch and a LED with AVR Micrcontroller.
 
[[Category:AVR Tutorials]]
 
[[Category:AVR Tutorials]]
  

Revision as of 16:57, 6 June 2015

In this tutorial, we will interface a simple switch and a LED with AVR Micrcontroller.

Code

#include <avr/io.h>
#define SW 0   
#define LED 1
int main(void)
{     
   DDRB &= ~(1<<SW);  //switch as input
   DDRB |= (1<<LED); //led as output  
   while(1)
   {
	   if ((PINB&(1<<SW)) == 1)
	   PORTB |= (1<<LED);
	   PORTB &= ~ (1<<LED);
   }
}

Schematic

Schematic AVR Interfacing Switches & LEDS.JPG

Code and Explanation will be updated soon..