I have a problem with my code
I'm trying to solve the bouncing button problem and I did it, but I am stuck in debouncing() function[look down].
Every time I press the button PINB0 is changed(that is ok), it also changes PINB2 values but ONLY ONCE and then comes back to function stays there, even if I'm not pressing a button.
So I can't do anything outside the function debouncing().
I'm using atmega32A with 16MHz OSC.
Connect a button to GND.
#define F_CPU 16000000ul #include <avr/io.h> #include <util/delay.h> bool button_push() { int pin_value; pin_value = PIND & (1<<PIND2); if ((pin_value != 0)) { return true; }else{ return false; } } bool debouncing() { int count; if (button_push()) { count = 0; while (count < 100) { if (button_push()) { count = 0; } count++; } return true; } return false; } int main(void) { DDRD &= ~(1<<PIND2); PORTD |= (1<<PIND2); DDRB |= (1<<PINB0) | (1<<PINB2); PORTB |= (1<<PINB0) | (1<<PINB2); while (1) { if (debouncing()) { PORTB ^= (1<<PINB0); } PORTB |= (1<<PINB2); _delay_ms(100); PORTB &= ~(1<<PINB2); } }