Switch and LED with Starter AVR Revision as of 15:51, 5 April 2016 by Vaibhav Katkar (Talk | contribs)
Basic
Hookup
Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#define LED 5 | |
#define SWITCH 3 | |
int main(void) | |
{ | |
DDRD |= (1<<LED); // Configure PD5 as output to connect Led | |
DDRD &= ~(1<<SWITCH); // Configure PD3 as input to connect switch | |
PORTD = 0x08; // Enable The PullUps of PORTC. | |
while(1) | |
{ | |
while(((PIND)&(1<<SWITCH))==0u) // Read the switch status and display it on Led | |
{ | |
PORTD |= (1<<LED); | |
} | |
PORTD &= ~(1<<LED); | |
} | |
return 0; | |
} |