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);
- }
- }
Code and Explanation will be updated soon..