Microcontroller › AVR › 4×4 Keypad Debounce
- This topic has 2 replies, 2 voices, and was last updated 9 years, 3 months ago by Setebwer.
-
AuthorPosts
-
June 15, 2015 at 7:21 am #3713SetebwerParticipant
Hello. I'd need some help with debouncing a keypad.
KEYPAD_DDR = DDRC
KEYPAD_PORT = PORTC
I've tried debouncing number 0 in 29th line but It doesn't work.
Can someone help me out please?
Cheers,
#define F_CPU 3686400UL
#define PERGES 300 //Pergesmentesiteshez#include<avr/io.h>
#include<util/delay.h>
#include"keypad.h"
#include"lcd.h"int main(void)
{KEYPAD_DDR=0b00001111; //upper 4 bits are declared input and lower 4 bits are declared output(4×4 Keypad is connected)
KEYPAD_PORT=0b11111111;//lower 4 bits are given high value and pull-up are enabled for upper 4 bits
lcd_init();
unsigned char keypad;while(1)
{
//prints("hello");
keypad=keypad_beolvas();if(keypad!=0xff)
{
switch(keypad)
{
case 0: while(!(KEYPAD_PIN & (1<<PC4))) ;
_delay_ms(PERGES); //pergés mentesítés
prints("0");
break;
case 1:
_delay_ms(PERGES); //pergés mentesítés
prints("1");
break;
case 2:
_delay_ms(PERGES); //pergés mentesítés
prints("2");
break;
case 3:
_delay_ms(PERGES); //pergés mentesítés
prints("3");
break;
case 4:
_delay_ms(PERGES); //pergés mentesítés
prints("4");
break;
case 5:
_delay_ms(PERGES); //pergés mentesítés
prints("5");
break;
case 6:
_delay_ms(PERGES); //pergés mentesítés
prints("6");
break;
case 7:
_delay_ms(PERGES); //pergés mentesítés
prints("7");
break;
case 8:
_delay_ms(PERGES); //pergés mentesítés
prints("8");
break;
case 9:
_delay_ms(PERGES); //pergés mentesítés
prints("9");
break;
case 10:
_delay_ms(PERGES); //pergés mentesítés
prints("*");
break;
case 11:
_delay_ms(PERGES); //pergés mentesítés
prints("#");
break;
case 12:
_delay_ms(PERGES); //pergés mentesítés
prints("A");
break;
case 13:
_delay_ms(PERGES); //pergés mentesítés
prints("B");
break;
case 14:
_delay_ms(PERGES); //pergés mentesítés
prints("C");
break;
case 15:
_delay_ms(PERGES); //pergés mentesítés
prints("D");
break;
}
}
}
return 0;
}June 17, 2015 at 6:51 am #12991Ashutosh BhattParticipantpls clerify your question? what is problem?
June 18, 2015 at 7:31 am #12999SetebwerParticipantMy goal is to do software debounce. I've made this code that's working only for * 0 # D buttons. So while I'm pushing * MCU is waiting. How should I modify this code for debouncing 1, 2 ,3, 4, 5, 6, 7, 8, 9, A, B, C buttons as well?
int main(void)
{
while(1)
{
…
if(keypad==0) // When zero is pushed…
{
while(!(PINC&(1<<PC5))); //Waiting while zero is pushed
_delay_ms(50);
}
}
}
My 4×4 keypad hardware connections to AVR
DDRC=0b00001111; //upper 4 bits are declared input and lower 4 bits are declared output(4×4 Keypad is connected)
PORTC=0b11111111;//lower 4 bits are given high value and pull-up are enabled for upper 4 bits -
AuthorPosts
- You must be logged in to reply to this topic.