In this tutorial, we will learn how to interface a switch(push button) with ATMEGA16 using AVR studio. In the previous video, we learnt how to interface LEDs with ATMEGA16 using AVR studio.
The push-button is a component that connects two points in a circuit when you press it. The example turns on an LED when you press the button. Here we have connected two push button to PORT C in PC0 & PC1. And for LEDs connection please refer my previous blog.
Components Required:-
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRB=0b11111111;
int S1;
int S2;
while(1)
{
S1=PINC&0b00000001;
S2=PINC&0b00000010;
if(S1==0b00000001)
{
PORTB=0b00000001;
_delay_ms(100);
}
if(S2==0b00000010)
{
PORTB=0b00000010;
_delay_ms(100);
}
}
}
After generating the hex file from AVR Studio, flash it in the chip and the following output can be seen.
Thank You
Thinking?
To know more visit us at http://www.karkhana.club/
The push-button is a component that connects two points in a circuit when you press it. The example turns on an LED when you press the button. Here we have connected two push button to PORT C in PC0 & PC1. And for LEDs connection please refer my previous blog.
Components Required:-
- AVR Controller(Atmega16)
- LEDs
- Push Button
- Connecting Wires
- USBASP Programmer
#include<avr/io.h>
#include<util/delay.h>
void main()
{
DDRB=0b11111111;
int S1;
int S2;
while(1)
{
S1=PINC&0b00000001;
S2=PINC&0b00000010;
if(S1==0b00000001)
{
PORTB=0b00000001;
_delay_ms(100);
}
if(S2==0b00000010)
{
PORTB=0b00000010;
_delay_ms(100);
}
}
}
After generating the hex file from AVR Studio, flash it in the chip and the following output can be seen.
Thank You
Thinking?
Join our hands-on training courses.
Comments