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 support@ccsinfo.com

Sharing/multiplexing GLCD (128X64) data pin with keypad

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



Joined: 10 Jul 2011
Posts: 54

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

Sharing/multiplexing GLCD (128X64) data pin with keypad
PostPosted: Sat Nov 22, 2014 12:15 am     Reply with quote

Hello every one,

I search in this forum and google for LCD and keypad multiplexing.

I found 4X20 and 2X16 lcd display are multiplexed with 4X4 keypad.

They used 4 data pins of lcd with 4 pins of keypad (also use diode), and the rest 4 pins of keypad are connected to another pins of micro controller.

As GLCD (128X64) used 8 data pins for operation, can I use these 8 data pins for 4X4 keypad ?

Or any other solution for Glcd and keypad, so that we can minimize the I/O pins requirement for this.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19338

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 1:55 am     Reply with quote

The way the multiplexing is done, is that with the diodes, when there is no input drive on a 'line' of the keypad (from the other pins), the 'output' side of the keypad does nothing - the diode allows it to go high or low whatever is happening on the keypad. This allows these four lines of the keypad to be used when this is the case, for other things like driving an LCD. This approach can be applied to any line, provided it is not 'in use' when the keypad is being scanned.
So, potentially, yes. You could use four of the LCD data lines as the lines to read the keypad. You could save another pin, if instead of using four output pins on the PIC to drive the LCD, you used two lines feeding a 2-4 line decoder. Then (being sneaky), used a bit of logic, so this is only enabled when both the GLCD CS lines are low. Done like this you could have a keypad using only two extra wires.
However remember this means that the timing of your code _must_ ensure that keypad scans and LCD I/O are always done at separate times.
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 8:54 am     Reply with quote

If you want to be really,really sneaky( and frugal), you only need ONE wire to read a 4by4 kpd! By proper selection of resistors on the row and columns of the kpd you create a 'resistive divider', then read a key pressed' by reading the analog voltage.
Of course you need a free analog input pin on the PIC.
This was done a long,long time ago when techs had to be 'creative'.

just another way to do it.

hth
jay
anglab



Joined: 27 Sep 2010
Posts: 4

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 6:39 pm     Reply with quote

Hi,

I use this schematic and driver.

Code:

PIC      KBD    GLCD
18F4620  4X4    AG-12864
------------------------
RD0 R1   ROW1   DB0
RD1 R2   ROW2   DB1
RD2 R3   ROW3   DB2
RD3 R4   ROW4   DB3
RD4 |<   COL1   DB4
RD5 |<   COL2   DB5
RD6 |<   COL3   DB6
RD7 |<   COL4   DB7
RE0             RS
RE1             W/R
RE2             E
RB5             CS1
RB6             CS2
RB7             RES

R1-R4 10k, +5V, RD0-3
|< - Diode 1N4148




Code:

///////////////////////////////////////////////////////////////////////////
////   KBD_4X4.c                                                       ////
////                                                                   ////
////   Keyboard driver V 1.0                                           ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////

//Keypad connection:
#define row0 PIN_D0
#define row1 PIN_D1
#define row2 PIN_D2
#define row3 PIN_D3

#define col0 PIN_D4
#define col1 PIN_D5
#define col2 PIN_D6
#define col3 PIN_D7

// Keypad layout:
char const KEYS[4][4] =
{{'7','8','9','X'},
 {'4','5','6','-'},
 {'1','2','3','+'},
 {'S','0','C','='}};

short int ALL_ROWS (void)
{
if(input (row0) & input (row1) & input (row2) & input (row3))//All rows' are "1"
    return (0);
    else
    return (1);
}
//******************************************************************************
char kbd_getc()
{
 set_tris_d(0x0F);
// output_d(0xFF);
static short int kbd_down;
static char last_key;
static BYTE col;
BYTE kchar;
BYTE row;
kchar='\0';

for (col=0;col<5;++col)   
  {     
   switch (col)
     {
      case 0:
        output_low(col0);
        output_high(col1);
        output_high(col2);
        output_high(col3);
        break;   
      case 1:
        output_high(col0);
        output_low(col1);
        output_high(col2);
        output_high(col3);
        break;
      case 2:
        output_high(col0);
        output_high(col1);
        output_low(col2);
        output_high(col3);
        break;
      case 3:
        output_high(col0);
        output_high(col1);
        output_high(col2);
        output_low(col3);
      break;
       case 4:
        output_high(col0);
        output_high(col1);
        output_high(col2);
        output_high(col3);
      break;
     }
   delay_us(10);   
   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;
        }
     }
  }
    delay_ms(30);//
  return(kchar);
}

freedom



Joined: 10 Jul 2011
Posts: 54

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

PostPosted: Tue Dec 02, 2014 12:03 pm     Reply with quote

Thanks anglab

which GLCD driver did you use?

Would you like to provide me diode polarity in this circuit.
anglab



Joined: 27 Sep 2010
Posts: 4

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 12:51 pm     Reply with quote

I use HDM64GS12.c driver.
Connection schematic.




Last edited by anglab on Tue Dec 02, 2014 5:04 pm; edited 1 time in total
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