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

Flexible Keypad Driver

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Ahmed



Joined: 07 Mar 2006
Posts: 19

View user's profile Send private message

Flexible Keypad Driver
PostPosted: Mon Mar 13, 2006 3:48 pm     Reply with quote

This is a modification of CCS keypad driver (KBDD.c) with flexible pins connections.

Code:
///////////////////////////////////////////////////////////////////////////
////                             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_E1
#define col1 PIN_A5
#define col2 PIN_C0
#define row0 PIN_E0
#define row1 PIN_C2
#define row2 PIN_C1
#define row3 PIN_E2

// 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);
}
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

Anyone can modify this excellent flex code to 4x4 keyboard ?
PostPosted: Thu Oct 05, 2006 7:03 am     Reply with quote

Anyone can modify this excellent flex code to 4x4 keyboard ?

#device <All_Members>
#include <Thank_you>
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 05, 2006 11:59 am     Reply with quote

This has already been done. It's at this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=28022&start=14
jruibarroso



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

Can you separate this code in "driver" code and &q
PostPosted: Sun Oct 08, 2006 9:02 am     Reply with quote

Can you separate this code in "driver" code and "main" code

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 08, 2006 10:27 am     Reply with quote

In the link given above, the driver is all the code between the two
dashed lines:

Code:

//=======================

// driver code is in here.

//=======================


The main() code is above and below the dashed lines.
40inD



Joined: 30 Jul 2007
Posts: 112
Location: Moscow, Russia

View user's profile Send private message

PostPosted: Wed Aug 01, 2007 3:07 am     Reply with quote

I suggest to output_float the "row" pins in the end of scan procedure if you use this driver in interrupt routine. In some cases interrupt works only 1 time w/out this.
ankur_rustagi12



Joined: 29 Mar 2009
Posts: 3

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

PostPosted: Fri Apr 03, 2009 6:31 am     Reply with quote

I changed the pin config to B0 to B6

but when i am running the above programme it is showing the following
errors:

Warning [361] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 27.5 function declared implicit int
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 27.12 undefined identifier "PIN_C3"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 27.29 undefined identifier "PIN_C4"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 27.46 undefined identifier "PIN_C5"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 27.63 undefined identifier "PIN_C6"
Warning [361] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 47.10 function declared implicit int
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 47.21 undefined identifier "PIN_C0"
Warning [361] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 48.1 function declared implicit int
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 48.13 undefined identifier "PIN_C1"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 49.13 undefined identifier "PIN_C2"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 63.10 undefined identifier "false"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 69.12 undefined identifier "PIN_C3"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 71.17 undefined identifier "PIN_C4"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 73.17 undefined identifier "PIN_C5"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 75.17 undefined identifier "PIN_C6"
Error [192] C:\Documents and Settings\Ankur\Desktop\Ankur\pic\keypad.c; 78.12 undefined identifier "true"


help me out...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 03, 2009 11:44 am     Reply with quote

You're using the Hi-Tech C compiler. Code on this forum will not work
with that compiler. Please go to the Hi-Tech forum and use their sample code:
http://forum.htsoft.com/all/ubbthreads.php
ankur_rustagi12



Joined: 29 Mar 2009
Posts: 3

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

PostPosted: Fri Apr 03, 2009 11:03 pm     Reply with quote

yup..that may be the reason..
So if i uninstall the hi-tech compiler and install ccs compiler and compile in mplab ide environment...then will this program work???...will it work???
Scythe



Joined: 05 Mar 2010
Posts: 5

View user's profile Send private message

PostPosted: Fri May 28, 2010 11:31 am     Reply with quote

I need to ask something. I read a lot about this code but I understand if you use this library with port_b_pullups(true), you don't need additional resistors for pull up the rows. You can directly connect rows and cols to b port. Am I wrong ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 28, 2010 12:08 pm     Reply with quote

That's correct.
GabrielVinicios



Joined: 27 May 2011
Posts: 2

View user's profile Send private message MSN Messenger

PostPosted: Fri Sep 13, 2013 5:28 pm     Reply with quote

My library for doing this follow below:

Code:

/*    gv_teclado.c
My library can be used in keypads 3x4 with those numbers:

1 2 3
4 5 6
7 8 9
* 0 #
But you can change those characters the way you want.

EXEMPLE OF USE:

char c;
do{
c=le_teclado();
}while (c=='\0');

The function returns '\0' when no key is pressed.

*/

#define COL1 PIN_B0
#define COL2 PIN_B1
#define COL3 PIN_B2
#define LIN1 PIN_B3
#define LIN2 PIN_B4
#define LIN3 PIN_B5
#define LIN4 PIN_B6

char le_teclado(){
//seleciona coluna1
output_high(COL1);
output_low(COL2);
output_low(COL3);

if (input(LIN1)==1){
   return '1';
}

if (input(LIN2)==1){
   return '4';
}


if (input(LIN3)==1){
   return '7';
}

if (input(LIN4)==1){
   return '*';
}




//seleciona coluna2
output_low(COL1);
output_high(COL2);
output_low(COL3);

if (input(LIN1)==1){
   return '2';
}

if (input(LIN2)==1){
   return '5';
}


if (input(LIN3)==1){
   return '8';
}

if (input(LIN4)==1){
   return '0';
}

//seleciona coluna3
output_low(COL1);
output_low(COL2);
output_high(COL3);

if (input(LIN1)==1){
   return '3';
}

if (input(LIN2)==1){
   return '6';
}


if (input(LIN3)==1){
   return '9';
}

if (input(LIN4)==1){
   return '#';
}

return '\0';


}
criss_m



Joined: 09 Mar 2006
Posts: 9
Location: Chile

View user's profile Send private message MSN Messenger

PostPosted: Tue May 20, 2014 3:02 am     Reply with quote

Its very strange:

i am trying to use the following pins in a SOIC 18F258:
i use flex LCD in same pins (plus PINC7)

#define COL1 PIN_A0
#define COL2 PIN_A1
#define COL3 PIN_A2

#define LIN1 PIN_C3
#define LIN2 PIN_C4
#define LIN3 PIN_C5
#define LIN4 PIN_C6

LCD seems to work fine , but keypad does not work ...
I tried putting pull up resistors in the rows ... but no luck either...

Any ideas ???
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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