now you have to need know about what is push Button
Push Button Is a switch When you press the push button LED will glow and when you release the push button LED will stop blinking.
now we will go to program i hope you read How to make the LED Blink
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRC |= (1<<PC0); //Nakes first pin of PORTC as Output
DDRD &= ~(1<<PD0);//Makes firs pin of PORTD as Input
while(1) //infinite loop
{
if(PIND & (1<<PD0) == 1) //If switch is pressed
{
PORTC |= (1<<PC0); //Turns ON LED
_delay_ms(3000); //3 second delay
PORTC &= ~(1<<PC0); //Turns OFF LED
}
}
}
Explain
Push switch Circuit Diagram |
Circuit Diagram Description
As described in the first tutorial 16 MHz crystal is used to provide clock to the Atmega32 microcontroller. 10µF capacitor and 10KΩ resistor is used to provide Power On Reset (POR) during the startup of microcontroller. LED is connected to the first pin of PORTC (PC0) of the microcontroller and a resistor is used to limit current through it. Push Button Switch is connected to the first pin of PORTD (PD0) of the microcontroller and a pull down resistor is provided to make the input LOW whenever the switch remain unpressed.
Proteus simulation video
No comments