In this tutorial we check how to interface a push button to an Atmega8.
Here we will connect an external button to give input to a AVR. Button is connected to 5v if button pressed then delay of led lights changes if released then.here the program is configured in such a way that one pin B1 of Port B is configured as input and pin B0 as output.The input pin checks whether high or low is received and toggles the output pin.
Circuit Diagram
Program
#include <avr/io.h> #include <avr/delay.h> int main() { DDRB |= 1<<PINB0; DDRB &= ~(1<<PINB1); PORTB |= 1<<PINB1; while(1) { PORTB ^= 1<<PINB0; if(bit_is_set(PINB,1)) { _delay_ms(100); } else { _delay_ms(500); } } }
Use the same Makefile
Change the TARGET name with the file name of the above program
Use the commands in sequence
make elf make hex make flash
Switch in action
Happy Hacking 🙂