CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

keypad 4x4 problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

keypad 4x4 problem
PostPosted: Wed Jul 22, 2009 6:52 am     Reply with quote

Hello !
I'm using keypad 4x4 which is connected to PIC 18F4550 and LCD 4x20.
In my program I use drivers for keypad and LCD from PCM programmer. There is link for 4x4 keypad driver :
http://www.ccsinfo.com/forum/viewtopic.php?t=28022&start=14
Everything is OK ( compiling), but when I press any button on keypad this number is shown on display more times.. for example: for ONE press on ONE button of keypad (for ex: number 5), there is on display 5 or 4 or 3 or 2 or 1 same pressed number. Same problem is for all buttons on keypad.

example

Keypad (ONE press no. 2) ----> on LCD is shown: 2
Keypad (if I press again 2)--> ON LCD is shown sometimes 22 or 222 or 222222.. etc

There is link of keypad which I'm using:
http://www.mikroe.com/en/tools/keypad/

Please help
Thank you
P.S. sorry my english is not so good....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 12:00 pm     Reply with quote

Did you put the keypad and the LCD on the same pins ? If so, you can't
do that. The flex lcd driver and the keypad driver won't work if they
share the same pins. Put them on different pins.
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 12:44 pm     Reply with quote

No, the pins of LCD and the pins of keypad are not the same.
LCD is on PORTB & PORTE (B4-B7 & E0-E2 ) and the keypad is on the PORTD.

Can this problem fix in software ?? to use some delay_ms() or something else ?

Thank you !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 22, 2009 1:25 pm     Reply with quote

1. Post your test program that calls the functions in the keypad driver.
The program must be small and compile with no errors.

2. Also, the connector for the keypad should have Pin 1 marked with a
little triangle symbol. Look for that triangle. Make sure that you
understand the pin numbers on the connector. Post a list of
connections between the keypad connector and the PIC.

3. Do you have pull-up resistors on the Row pins ?
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 4:35 am     Reply with quote

1.
Code:
#include <18F4550.h>
#fuses HSPLL, PLL5, CPUDIV1, NOWDT, PUT, BROWNOUT, NOLVP
#use delay (clock=48000000)
#include <keypad1.c> // same as
// http://www.ccsinfo.com/forum/viewtopic.php?t=28022&start=14
// just pins changed
#include <Flex_LCD420.c>

void main() {
   char k;

   lcd_init();
   kbd_init();

   lcd_putc("\fReady...\n");

   while (TRUE) {
      k=kbd_getc();
      if(k!=0)
        if(k=='*')
          lcd_putc('\f');
        else
          lcd_putc(k);
   }
}

2.There are pull up resistors (10kOhm) on rows.
//Keypad connection:
#define row0 PIN_D4
#define row1 PIN_D5
#define row2 PIN_D6
#define row3 PIN_D7
#define col0 PIN_D0
#define col1 PIN_D1
#define col2 PIN_D2
#define col3 PIN_D3
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Thu Jul 23, 2009 7:08 am     Reply with quote

You need to do several things

1. Debounce the keys
2. Every time the user presses the key, it must be released for another operation. or in other words disable multiple presses.

hope this helps,

thanks
arunb
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 10:29 am     Reply with quote

arunb,
Look at the keypad driver code given in the link in his post.
The code already has a debounce feature in it.
Code:

#define KBD_DEBOUNCE_FACTOR 33 // Set this number to apx n/333 where
// n is the number of times you expect
// to call kbd_getc each second
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR)



cile,
Quote:
#use delay (clock=48000000)

This is a very high clock speed. The original CCS keypad driver was
tested at 20 MHz maximum. However, the driver has a parameter
that can be adjusted for the oscillator frequency.

The ratio of 48 MHz to 20 MHz is:
48 / 20 = 2.4

The old debounce value (for 20 MHz operation) is 33:
Code:
#define KBD_DEBOUNCE_FACTOR 33   


So, multiply the old "debounce factor" by 2.4 to get the new value:
Code:
#define KBD_DEBOUNCE_FACTOR 79   


Edit the keypad driver file, re-compile, and see if it now works.
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

PostPosted: Thu Jul 23, 2009 1:17 pm     Reply with quote

Ok, thank you, I will try tomorrow , I can not do it now.
I will post what happened
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

PostPosted: Fri Jul 24, 2009 7:13 am     Reply with quote

I have tested but still same problem !
any advice ??
thank you !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 24, 2009 11:05 am     Reply with quote

Quote:
2.There are pull up resistors (10kOhm) on rows.
//Keypad connection:
#define row0 PIN_D4
#define row1 PIN_D5
#define row2 PIN_D6
#define row3 PIN_D7
#define col0 PIN_D0
#define col1 PIN_D1
#define col2 PIN_D2
#define col3 PIN_D3

The keypad schematic does not label its pins as "rowx" and "colx".
It calls them RB0 to RB7.
http://www.mikroe.com/pdf/keypad_board_schematic.pdf

Post a list of connections, similar to the one above, but use the pin names
from the keypad schematic instead of "rowx" and "colx".
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Sat Jul 25, 2009 4:15 am     Reply with quote

Quote:

Look at the keypad driver code given in the link in his post.
The code already has a debounce feature in it.


I did not notice the debounce feature..thanks

It seems the key presses are repeating, if so the keys have to be disabled after each press, when the key is released the key can be enabled again.

thanks
arunb
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 7:10 am     Reply with quote

Hello,

There is link, where is schematic of my final project. You will see on schematic how is made jack for kepyad.
http://rapidshare.com/files/260219348/picture.JPG

I think, maybe the buttons on keypad are bad.?!?!

Thank you !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 26, 2009 2:18 pm     Reply with quote

I was able to duplicate your problem. I fixed it by increasing the
debounce value to this:
Code:
#define KBD_DEBOUNCE_FACTOR 200

I didn't experiment to try to fine-tune it to the minimum value that will
work. I just dropped in 200 and it started working.

I've never liked the "debounce factor" method that CCS uses in kbd.c.
It's not clean enough. You have to estimate (or physically determine)
the amount of time it takes to execute the keypad routine, and then
manually calculate the debounce factor. It would be better to require
a fixed delay such as delay_ms(1), in the loop that calls the keypad
routines and then use a fixed value for the debounce factor (1 or 3).
Then you wouldn't have to do this calculation every time you change
the oscillator frequency or PIC series.
cile



Joined: 10 May 2009
Posts: 17

View user's profile Send private message

PostPosted: Fri Aug 07, 2009 5:37 am     Reply with quote

Hello. I could not answer before. I have put 150 debounce factor, and it seems better. I did not test with 200, but I will try and report.

Thank you for help !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group