This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

8x2 Matrix keypad interface with TM4C123GH6PZ

Other Parts Discussed in Thread: TM4C123GH6PZ

Hi..i'm interfacing 8x2 keypad with TM4C123GH6PZ..i done coding for 20x4  LCD.i have accessed the gpio pins like this..

#define E 1 /*PH0*/
#define RS 2 /*PH1*/
#define LCDDATA (*((volatile unsigned long *)0x400043FC)) /*PortA*/
#define LCDCMD (*((volatile unsigned long *)0x400273FC))/*portH*/

i didn't not use the GPIO  function for writing the data to LCD.

now i suppose to interface with 8x2 keypad.8 port pins as input n two port pins as output...i'm getting confusion ..i have done my coding like this..Is this correct way to do???

#include "inc/lm4f232h5qc.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "string.h"
#include "lcd.h"

#define cols (*((volatile unsigned long *)0x400253FC)) /*portf*/
#define rows (*((volatile unsigned long *)0x400273FC)) /*portE*/

#define col0  cols^0
#define col1  cols^1
#define col2  cols^2
#define col3  cols^3
#define col4  cols^4
#define col5  cols^5
#define col6  cols^6
#define col7  cols^7

#define row0  rows^0
#define row1  rows^1

int main(void)
{
char c;
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
GPIO_Config();

while(1){
while(!(c = READ_Keypad()));

LCDDV_enWrLCDDat(c);
LCD_Delay(200);
while(!(c = READ_Keypad()));

}

}

char READ_Keypad(void)
{
cols= 0xff;

rows = 0x02;

if((col0 ) == 0){LCD_Delay(8);while((col0 ) == 0); return '6';}

if((col1) == 0){LCD_Delay(8);while((col1) == 0); return '6';}
if((col2) == 0){LCD_Delay(8);while((col2) == 0); return '7';}
if((col3) == 0){LCD_Delay(8);while((col3) == 0); return '8';}
if((col4) == 0){LCD_Delay(8);while((col4) == 0); return '9';}
if((col5)== 0){LCD_Delay(8);while((col5)== 0); return '0';}
if((col6) == 0){LCD_Delay(8);while((col6) == 0); return 'E';}
if((col7)== 0){LCD_Delay(8);while((col7) == 0); return 'D';}

rows = 0x01;


if((col0 ) == 0){LCD_Delay(8);while((col0 ) == 0); return '1';}

if((col1) == 0){LCD_Delay(8);while((col1) == 0); return '2';}
if((col2) == 0){LCD_Delay(8);while((col2) == 0); return '3';}
if((col3) == 0){LCD_Delay(8);while((col3) == 0); return '4';}
if((col4) == 0){LCD_Delay(8);while((col4) == 0); return '5';}
if((col5)== 0){LCD_Delay(8);while((col5)== 0); return 'B';}
if((col6) == 0){LCD_Delay(8);while((col6) == 0); return 'U';}
if((col7)== 0){LCD_Delay(8);while((col7) == 0); return 'M';}

return 0;


}

Please help me..

  • Hi,

    Please see at this page the package MatrixKeypadPeriodic.zip - read/understand/modify yours - take into account a better solution is to use 4x4 keyboard since uses less pins. 

    Petrei

  • hi.. my application needs 8x2 keypad...In that code they are accessing the pins through register..but i need to access pins through GPIO..many  functionality need to do by using this keypad.first i need to make sure that whether  keypad is working or not..so i'm checking through above code...

  • Hi,

    Is this a homework project with imposed requirement to use a 8x2 keyboard? If yes, doit as it is, but such thing is really weird and there is no technical argument to use such and not to use 4x4  - at least does not teach you to adopt good technical reasoning for a solution.

    As for the fact the example uses direct register - well, can be converted easily to API use. Important things to follow: use the timer to periodically check the keyboard routine, do debouncing as it is done there. Another problem is with two key pressed simultaneously - you must avoid more than one key pressed.

    Take into account that in normal C language, "^" symbol is used for exclusive OR operation and not for pin designation - that notation (cols^6 is for pin/bit 6 in cols port/variable, used in some old 8-bits microcontrollers like 8051/AVR - take care what you read from the internet, since not all C code can be used from one micro to another one (that will compile correctly but will not work since the meaning is another one). 

    Petrei