Line 1: Line 1:
  
 
[[Category:AVR Tutorials]]
 
[[Category:AVR Tutorials]]
 +
 +
=Code=
 +
<syntaxhighlight>
 +
#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);
 +
  }
 +
}
 +
</syntaxhighlight>
 
[http://exploreembedded.com/wiki/images/b/be/Schematic_AVR_Interfacing_Switches_%26_LEDS.pdf '''Schematic''']
 
[http://exploreembedded.com/wiki/images/b/be/Schematic_AVR_Interfacing_Switches_%26_LEDS.pdf '''Schematic''']
  
 
[[File:Schematic AVR Interfacing Switches & LEDS.JPG|680px]]
 
[[File:Schematic AVR Interfacing Switches & LEDS.JPG|680px]]
 
'''Code and Explanation will be updated soon..'''
 
'''Code and Explanation will be updated soon..'''

Revision as of 15:06, 20 November 2014


Code

  1. #include <avr/io.h>
  2. #define SW 0
  3. #define LED 1
  4. int main(void)
  5. {
  6. DDRB &= ~(1<<SW); //switch as input
  7. DDRB |= (1<<LED); //led as output
  8. while(1)
  9. {
  10. if ((PINB&(1<<SW)) == 1)
  11. PORTB |= (1<<LED);
  12. PORTB &= ~ (1<<LED);
  13. }
  14. }

Schematic

Schematic AVR Interfacing Switches & LEDS.JPG Code and Explanation will be updated soon..