|
|
View previous topic :: View next topic |
Author |
Message |
omid_juve
Joined: 25 Oct 2012 Posts: 8
|
problem with flex_kbd ??? |
Posted: Tue Oct 30, 2012 8:52 am |
|
|
dear sir
Please read my easy program. I want to show a key pressed by keypad
on lcd with flex_kbd.c but it doesn't write anything. But when i use kbd.c driver and put the keypad on PortB everything is fine, so i think something is wrong with the driver. Can you please check it.
Code: |
#include <flex_kbd.c>
#define LCD_ENABLE_PIN PIN_E3
#define LCD_RS_PIN PIN_E2
#define LCD_RW_PIN PIN_F1
#define LCD_DATA4 PIN_D3 ////
#define LCD_DATA5 PIN_D2 ////
#define LCD_DATA6 PIN_D1 ////
#define LCD_DATA7 PIN_D0 ////
#include <lcd.c>
void main()
{
char c;
port_b_pullups(0XFF);
lcd_init();
kbd_init();
lcd_putc("ready");
while(TRUE)
{
c = kbd_getc();
if (c!='\0')
lcd_putc(c);
}
///////////////////////////////////////////////////////////////////////////
//// Flex_KBD.C ////
//// Generic keypad scan driver ////
//// ////
//// kbd_init() Must be called before any other function. ////
//// ////
//// c = kbd_getc(c) Will return a key value if pressed or /0 if not ////
//// This function should be called frequently so as ////
//// not to miss a key press. ////
//// ////
///////////////////////////////////////////////////////////////////////////
//Keypad connection:
#define col0 PIN_c2
#define col1 PIN_c3
#define col2 PIN_c4
#define row0 PIN_c5
#define row1 PIN_b7
#define row2 PIN_b6
#define row3 PIN_b5
// Keypad layout:
char const KEYS[4][3] = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
#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
void kbd_init() {
}
short int ALL_ROWS (void)
{
if (input (row0) & input (row1) & input (row2) & input (row3))
return (0);
else
return (1);
}
char kbd_getc( ) {
static byte kbd_call_count;
static short int kbd_down;
static char last_key;
static byte col;
byte kchar;
byte row;
kchar='\0';
if(++kbd_call_count>KBD_DEBOUNCE_FACTOR) {
switch (col) {
case 0 : output_low(col0);
output_high(col1);
output_high(col2);
break;
case 1 : output_high(col0);
output_low(col1);
output_high(col2);
break;
case 2 : output_high(col0);
output_high(col1);
output_low(col2);
break;
}
if(kbd_down) {
if(!ALL_ROWS()) {
kbd_down=false;
kchar=last_key;
last_key='\0';
}
} else {
if(ALL_ROWS()) {
if(!input (row0))
row=0;
else if(!input (row1))
row=1;
else if(!input (row2))
row=2;
else if(!input (row3))
row=3;
last_key =KEYS[row][col];
kbd_down = true;
} else {
++col;
if(col==3)
col=0;
}
}
kbd_call_count=0;
}
return(kchar);
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Tue Oct 30, 2012 11:03 am |
|
|
First. Please do not post any CCS programs or drivers. It's against forum policy and everyone who bought the compiler has copies.
2nd. The driver does work fine,has for years.
3rd. Your program is not complete, we don't know the PIC you're using.There could easily be a conflict with the pins you've chosen with other peripherals( say the ADC,UART,etc.) that requires you to disable those devices.
4th. It's a good idea to toggle an LED in these simpler programs to verify the PIC is running as you could have an LCD wiring problem or other issue.
hth
jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 30, 2012 11:47 am |
|
|
Actually the flex_kbd driver was posted by Ahmed in the code library.
It's not CCS code.
The most common problem with keypad driver is that you forgot to put
pull-up resistors on the row pins. Each row pin must have this circuit:
Code: |
10K
+5v ---/\/\/\/---
|
|
PIC pin ------------o---------- Keypad row pin
|
That requires a total of 4 pull-up resistors. You can also use 4.7K phms
or some other value.
You might say that you have enabled PortB pull-ups, but one of your
row pins is on Port C, so you still need to add a pull-up to Pin C5:
Code: |
#define row0 PIN_c5
#define row1 PIN_b7
#define row2 PIN_b6
#define row3 PIN_b5 |
|
|
|
|
|
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
|