I am a beginner of the micro-controller and I have the kit for AVR. I am currently using an ATMega16 to learn the basics. I have tried a few simple experiments with this micro-controller using LED's. Now I wanted to do some hardware interfacing and I found an interesting project.
I want to use 6 push buttons for counting to 2500 and display it on the multiplexed seven segment LED's. 3 buttons for counting upwards, i.e., (100's, 10's and 1's). For instance, if I have to display 1532, I will press 100's button 15 times, 10's button 3 times and 1's button twice. Similarly, for counting down, I want to use 3 buttons. I have tried some code that makes use of conditional statements for checking the pin status but none of them seem to work.
Please help me out with this as I have been stuck on this for quite a while. It seems to be the issue with "debouncing" but I am not entirely sure about that concept.
I am trying to count the number of times the switch has been pressed (PB0) and when it reaches 5, I want to turn ON an LED(PD0). The below code does not work.
int main(void) { unsigned char count=0; TCCR0 = (1<<WGM01)|(1<<CS02)|(1<<CS00); // Timer0 Mode 2: CTC-Prescaler 1024 TCNT0 = 0; OCR0 = (((XTAL / 1024.0)*10e-3)-1); // For 10ms TIMSK = 1<<OCIE0; // enable T0 interrupt DDRB = 0x00; // PB0 input PORTB = 0x00; // external pullup DDRD = 0x01; // PD0 LED output PORTD = 0x00; // LEDs off sei(); while(1) { // main loop if(!(PINB & _BV(PB0))) { count++; if(count>=5) { PORTD|= (1<<PD0); // SET LED on keypress _delay_ms(10); count = 0; } } } }