USE OF PUSH BUTTON WITH AVR ATMEGA32,In this article you will learn what is push button and how we can use push button with AVR microcontroller Atmega32. How the push button is used for controlling of any device such as LED. Here we will also learn the use of “if and else” statements in C language.
WHAT IS PUSH BUTTON?
Push button is basically a small controlling device that is pressed to operate any electrical device. In this article we use push button with AVR microcontroller Atmega32 to give you a basic of idea how to develop codes for controlling device.
DEVELOP THE CODE
First we have to develop the code by using Atmel studio 6. We will write code in C language in which we will use push button as a controlling device for LED. When we press the push button LED will glow and when we release the push button LED will stop blinking.
Now open Atmel studio 6, choose the “New project” and select “GCC C Executable Project”. After selecting device (Atmega32), click “OK”. A new window will open where you can write your code.
To control the blinking of LED by using push button, the code is given below:
CODE TO CONTROL THE BLINKING OF LED VIA PUSH BUTTON
In this code we use two registers Data direction register (DDR) and PORT register. DDR command shows that whether the direction of pin is termed as input or output. PORT register is an output register which shows status of pin; either it is high or low.
Push button is connected to the fifth pin of PORTC while LED is connected to the fourth pin of PORTD. When we press the push button LED will glow otherwise it will remain OFF.
#ifndef F_CPU
#define F_CPU 16000000UL //clock speed is 16MHz
#endif
#include <avr/io.h>
#include <util/delay.h>
int main(void) //main starts
{
DDRD = DDRD | ( 1<<4) ; //Make pin 4 of port D as a output
DDRC = DDRC & ~(1<<5) ; // Make pin 5 of port C as a input
while (1) //initialize while loop
{
if(PINC & (1<<5) ) //if PIN5 of port C is high
{
PORTD = PORTD | ( 1<<4) ; //PIN4 of port D is high
}
else //otherwise
{
PORTD = PORTD & ~( 1<<4) ; //PIN4 of port D will remain low
}
} // while loop ends
} //main end

SCHEMATIC
We design the schematic on proteus. We use Atmega32, crystal, capacitors, resistors, LED and push button from the built-in library of Proteus. Notice that the Vcc and ground pins of Atmega32 are connected by default so there is no need to connect them until or unless you are working in the real world.

After designing the circuit make necessary changes by double clicking on crystal and Atmega32 a dialog box will appear now set the frequency of crystal and Atmega32, which is 16MHz and set the fuse bits of Atmega32.

Again double click on Atmega32 a dialog box will appear. Go to the option of program file, selects your required HEX file and click “OK”.

Now the final step is to press the play button on the bottom left corner of proteus window. The following circuit shows, as we press the pushbutton the LED will glow.

This is all about how to use push button with ATMEGA32 AVR MICROCONTROLLER. This is all effort has been made by our content writer Farida Ahmad. Thanks to her for sharing valuable knowledge with us. Kindly spread this information with others by clicking on social media sharing button shown below. Thanks 🙂
Button press led on again button press led off. I need this program.
i have AVR Studio8 but this tutorial ist avaible?