circuit connection

Project 17 – Interface with 4×4 keypad and 2×16 LCD

PROJECT 17

INTERFACE WITH 4×4 keypad and 2×16 LCD

Back to Project 16                                                                                         Go to SK40C Tutorial Page

This 16-button keypad provides a useful human interface component for micro controller projects. Convenient adhesive backing provides a simple way to mount the keypad in a variety of applications. Matrix keypads use a combination of four rows and four columns to provide button states to the host device, typically a micro-controller. Underneath each key is a push button, with one end connected to one row, and the other end connected to one column.

In order for the micro-ocontroller to determine which button is pressed, it first needs to pull each of the four column either low or high one at a time, and then poll the states of the four rows. Depending on the states of the rows, the micro controller can tell which button is pressed. You can download the Keypad 4×4 user manual from here.

In this tutorial, you will learn on how to display the character on LCD by pressing  the 4×4 keypad button.

———————————————————————————————————————————————————-

COMPONENT NEEDED

———————————————————————————————————————————————————-

lcd280x3731 x LCD (2×16)- Blue Backlight

keypad-4x4-3158-280x3734×4 Keypad

Jumper(male-male)1 x  Male to Male Jumper Wires

———————————————————————————————————————————————————-

CONNECTION

———————————————————————————————————————————————————-
Connection in between SK40C and 4×4 keypad are only required 9 wires which are 5V(VDD) and Port C0-C7. Additional 4 of 10k ohm resistors were used to pull out the 4 columns of the keypad..

a) Circuit connection

      

                                                               b) Actual circuit connection

c) Schematic

———————————————————————————————————————————————————-

ADDITIONAL INFORMATION

———————————————————————————————————————————————————-
4×4 Keypad pin can directly connect to microcontroller or keypad decoder IC for decode purpose. However, DIY scanning of keypad consumes a lot of understanding in programming and more program space. The better way to interface a keypad to the PIC is to use a keypad encoder in between the keypad and the microcontroller. One of the Keypad Encoder is theMMC74C922. Simply hook up all the row and the column pins directly to the encoder and it will output a HIGH pulse on the Data Available pin whenever a key is pressed. After that, the encoder will output 4 bits of data to the PIC.

Feature

  •  Ultra-thin design
  •  Adhesive backing
  •  Excellent price/performance ratio
  •  Easy interface to any microcontroller
  •  Example programs provided for the BASIC

Key Specifications

  •  Maximum Rating: 24 VDC, 30 mA
  •  Interface: 8-pin access to 4×4 matrix
  •  Operating temperature: 32 to 122 °F(0 to 50°C)
  •  Dimensions:64x62x8 mm

Application Ideas

  • Security systems
  •  Menu selection
  •  Data entry for embedded systems

———————————————————————————————————————————————————-

CODE OVERVIEW

———————————————————————————————————————————————————-
system.h

In this part of the source code, the pins which were connected to the columns and the rows of the 4×4 keypad were initialized at here.

keypad.c

This part of source code will determined which 4×4 keypad button being pressed.

e.g:

KP_R1 = 0;
KP_R2 = 1;
KP_R3 = 1;
KP_R4 = 1;
__delay_us(30);

It will test whether the 1st row of the keypad being pressed or not. If not, it will goto to 2nd row to check for the button pressed. If the button of the 1st row was being pressed, it will test which column is the location.

if (KP_C1 == 0)  return ‘1’;
if (KP_C2 == 0) return ‘2’;
if (KP_C3 == 0) return ‘3’;
if (KP_C4 == 0) return ‘A’;

If the 1st column, it will return 1 in ASCII form. If  it was 2nd column, 2 in ASCII form being return. Same go to column 3 and 4.

return 0xFF;

If the keypad does not being pressed, this function will return 0xFF to the function which will used it.

unsigned char keypad_wait();

This function will test whether the keypad button being pressed or not.

do{c_pressed_key = keypad_read();}while (c_pressed_key == 0xFF);

If the keypad_read() function does not return anything(return 0xFF only) to the c_pressed_key, it will wait at here until it accept one of the 16 characters on the keypad from keypad_read().

return c_pressed_key;

Return the accepted data(character in ASCII form) back to main function.

MAIN PROGRAM

unsigned char key_get;

It is an unsigned char variable used to store the data get from the 4×4 keypad.

TRISC = 0b00001111;

Initialize the PORTC<7:4> as output, PORTC<3:0> as input

lcd_initialize();

Please refer here for the SK40C with lcd tutorial.


while(1)

While loop used in here in order the micro-controller can always read the data from the keypad

LED1 = 1;

LED2 = 0;

Set  the LED1 and LED2 light up and off at first respectively.

lcd_putstr(”   Enter Word:”);

Display Enter Word on the first row of the 16×2 lcd

lcd_2ndline();

Go to 2nd row of the 16×2 lcd

for(unsigned int i = 0; i < 17; i++)

This loop used in order for the LCD to displayed 16 characters

key_get = keypad_wait();

The variable key_get will store the data from keypad_wait() function.

LED1  ^= 1;

LED2  ^= 1;

The led will be toggle each time for the button of the keypad being pressed. Either LED1 on and LED2 off or vice versa.

lcd_clear();

Clear the LCD

———————————————————————————————————————————————————-

RESULT

———————————————————————————————————————————————————-

 

The LCD will display the character of the keypad as you pressed the button. It will showed 16 characters and if you pressed the keypad further more, the 16   characters will be clear and started again from the first column of the 2nd row on the16x2 LCD.

Back to Project 16                                                                                        Go to SK40C Tutorial Page

———————————————————————————————————————————————————-

ATTACHMENT

1. P17_SK40C_4x4keypad_user manual.pdf
2. P17_SK40C_4x4keypad.zip

Buy

, ,

Related Post

20160330_085520-e1459299689529-400x323

Control and Monitor via SMS Part 2

ciku-7-400x347

Simple steps to control Stepper Motor using 2Amp Motor Driver Shield and CIKU

18f4550arrowclock

PIC16F VS PIC18F:Analysis of PIC Mid-Range 8 bit family and Advanced 8-bits Family

DSC00191.000

SK40C vs CT-UNO

14 thoughts on “Project 17 – Interface with 4×4 keypad and 2×16 LCD

  1. Hi guy,

    I still can’t display the output at LCD as shown on your tutorial above .
    Error pop pup in output shown like below this text;

    //*** Error 12″keypad.c” Line 29(10,11); Underlined identifier RC6

    require your help to resolve .

  2. Resistors need only be .25W (1/4 W) as they are only pullups. No need to buy the 5W HUGE resistors currently linked to in the post.

  3. Hi, I’m trying to use this with a 18f4520. My hardware layout is identical. I’m just wondering is the system.h section a seperate header file and does it require an #include “system.h” call. Also, the file keypad.c, is that seperate to the main program or can it be included?
    Thanks in advance

  4. Great post. I used to be checking constantly this blog and I’m impressed!

    Extremely helpful information specially the final section 🙂 I care for such info a lot.
    I used to be looking for this certain information for a very lengthy time.
    Thanks and good luck.

  5. hy ,,,i want to ask u how the connection and coding (c++) for keypad 4×4 and uart with 2 different lcd 16×2???

Leave a Reply

Your email address will not be published. Required fields are marked *