Hi, I'm portuguese and I'm making a alarm clock project with ATmega644 and a 4 digit 7 segment display. When I power up my circuit, it give me the current time, I did this through RTC module and it works perfectly. Now I want that while I press the button -PB0 - he enter in the mode set_alarm, with hours and minutes to zero, so far so good. The part that doesn't work is: while this button(PB0) is pressed, I want use PB1 and PB2 buttons to set the alarm hours and alarm minutes. But when I press one of these two buttons, the respective display changes to the next number but immediately returns to zero and I dont know why. Check my code , if there are some parts of the rest of the code that you wanna see, let me know, I only paste the part that I think you need to see. The debounce code I see the "Software debouncing of buttons" pdf from Snigelen and it works fine. And help me please, thanks!
int main(void) { inic(); // DS1307_Lock(true); // Modo24h(); // Time_Set(2,25,1); Get_Time(); while (1) { if( !(PINB & (1<<PB0)) ) { set_alarm(); //goes to set_alarm } else { digits_clock(); //Show clock } } } (...) void digits_clock() { PORTC = 0b00010000; display_num(Tempo[2]); _delay_ms(6.1); PORTC = 0b10000000; display_num(Tempo[3]); _delay_ms(6.1); PORTC = 0b01000000; display_num(Tempo[4]); _delay_ms(6.1); PORTC = 0b00100000; display_num(Tempo[5]); _delay_ms(6.1); } void digits_alarm() { PORTC = 0b00010000; display_num(minutos%10); _delay_ms(6.1); PORTC = 0b10000000; display_num(minutos/10); _delay_ms(6.1); PORTC = 0b01000000; display_num(horas%10); _delay_ms(6.1); PORTC = 0b00100000; display_num(horas/10); _delay_ms(6.1); } void set_alarm() { debounce(); if (button_down(BUTTON2_MASK)) //PB1 pressed { minutos ++; } if (button_down(BUTTON3_MASK)) //PB2 pressed { horas ++; } digits_alarm(); }