banner



Where Repair Linear Keypad Board

Keypads are widely used input devices being used in various electronics and embedded projects. They are used to accept inputs in the form of numbers and alphabets, and feed the aforementioned into organization for further processing. In this tutorial we are going to interface a 4x4 matrix keypad with PIC16F877A.

Before going into the particular logic and larn how to apply the keypad, we will need to know few things.

Why we need 4x4 Keypad:

Typically nosotros employ single I/O pin of a microcontroller unit to read the digital signal, like a switch input. In few applications where 9, 12, xvi keys are needed for input purposes, if we add together each cardinal in a microcontroller port, we will end upward using 16 I/O ports. This 16 I/O ports are not only for reading I/O signals, but they can exist used as peripheral connections too, similar ADC supports, I2C, SPI connections are too supported by those I/O pins. As those pins are connected with the switches/keys, we can't utilise them but only equally I/O ports. This is makes no sense at all. And then, how to reduce pin count? The respond is, using a hex keypad or matrix keypad; we can reduce pin counts, which associate 4x4 matrix keys. It will utilize viii pins out of which 4 connected in rows and 4 continued in columns, therefore saving 8 pins of the microcontroller's.

How 4x4 Matrix Keypad works:

4x4 Matrix Keypad Pinout

In the upper image a matrix keypad module is shown at the left. On the right the internal connection is shown equally well equally port connectedness. If nosotros see the port there are 8 pins, first 4 from left to right are X1, X2, X3, and X4 are the rows, and concluding four from left to correct are Y1, Y2, Y3, Y4 are four columns. If we make 4 rows or 10 side equally output and make them logic low or 0, and make the 4 columns every bit input and read the keys nosotros will read the switch printing when contributor Y gets 0.

Same thing will happen in n ten n matrix where n is the number. That tin can be 3x3, 6x6 etc.

At present merely think that one is pressed. Then the one is situated at X1 row and Y1 cavalcade. If X1 is 0, then the Y1 will exist 0. By the same way we can sense each key in the X1 row, by sensing column Y1, Y2, Y3 and Y4. This matter happens for every switch and we will read the position of the switches in the matrix.

Each green circles is the switch and they both are connected together in the same way.

In this tutorial we volition interface the cardinal board with post-obit specifications-

  1. We will use internal pull upwards
  2. We will add cardinal de-bounce option

But when the switches are non pressed we need to brand the Y1, Y2, Y3 and Y4 as high or 1. Otherwise we can't discover the logic changes when the switch is existence pressed. But we couldn't make it by codes or program due to those pins are used as input, not output. And so, we volition use an internal operation register in the microcontroller and operate those pins every bit weak pull upwardly enabled mode. By using this, there will be a logic high enable fashion when it is in the default state.

Also, when we printing cardinal at that place are spikes or dissonance are generated with switch contacts, and due to this multiple switch press happens which is non expected. So, nosotros will first observe the switch press, wait for few milliseconds, again check whether the switch is still pressed or non and if the switch is still pressed we will accept the switch press finally otherwise not. This is called every bit de-bouncing of the switches.

We volition implement this all in our lawmaking, and make the connection on breadboard.

Also check how to interface 4x4 keypad with other Microcontrollers:

  • Keypad Interfacing with Arduino Uno
  • 4x4 Matrix Keypad Interfacing with 8051 Microcontroller
  • 4x4 Keypad Interfacing with ATmega32 Microcontroller
  • Raspberry Pi Digital Lawmaking Lock on Breadboard

Fabric Required:

  1. Breadboard
  2. Pic-kit 3 and development surround in your PC, i.due east MPLABX
  3. Wires and connectors
  4. Graphic symbol LCD 16x2
  5. 20Mhz Crystal
  6. 2 pcs 33pF ceramic disc cap.
  7. iv.7k resistor
  8. 10k preset (variable resistor)
  9. 4x4 Matrix keypad
  10. A 5 V adapter

Circuit Diagram:

4x4 Matrix Keypad Interfacing Circuit diagram with PIC Microcontroller

4x4 Matrix Keypad Interfacing with PIC Microcontroller

We will connect the crystals and the resistor in the associated pins. Besides, we will connect the LCD in 4 bit mode beyond PORTD. Nosotros continued the hex keypad or matrix keypad across the port RB4.

If you lot are new to Film and so offset with Getting started with PIC Microcontroller: Introduction to Flick and MPLABX

Programming Explanation:

Complete code for interfacing Matrix Keypad with PIC Microcontroller is given at the end. Code is easy and self-explanatory. Keypad library is only thing to exist understood in the code. Here nosotros take used keypad.h and lcd.h Library to interface the keypad and 16x2 LCD. Then lets see what is happening inside that.

Inside the keypad.h we volition see that we have used ninety.h header which is default register library, the crystal frequency is divers for the use for the use of delay used in kepad.c file. We divers the keypad ports at PORTRB register and defined private pins equally row (10) and columns (Y).

Nosotros too used two functions one for the keypad initialization which will redirect the port as output and input, and a switch press scan which volition return the switch printing status when called.

          #include <xc.h>                    #define _XTAL_FREQ 200000000 //Crystal Frequency, used in delay          #define X_1    RB0          #define X_2    RB1          #ascertain X_3    RB2          #define X_4    RB3          #define Y_1    RB4          #define Y_2    RB5          #define Y_3    RB6          #ascertain Y_4    RB7          #define Keypad_PORT          PORTB          #define Keypad_PORT_Direction     TRISB                    void InitKeypad(void);          char switch_press_scan(void);        

In the keypad.c we will see that below function volition render the fundamental press when the keypad scanner function not return 'n'.

          char switch_press_scan(void)                       // Get key from user          {                      char key = 'n';              // Assume no key pressed                      while(fundamental=='n')              // Wait untill a primal is pressed                      key = keypad_scanner();   // Scan the keys again and once again                      return key;                  //when key pressed and then return its value          }        

Below is the keypad reading function. In each pace we volition make the row X1, X2, X3, and X4 as 0 and reading the Y1, Y2, Y3 and Y4 status. The filibuster is used for the debounce effect, when the switch is still pressed we volition return the value associated with it. When no switch are pressed we will render 'n '.

          char keypad_scanner(void)                    {                                X_1 = 0; X_2 = 1; X_3 = 1; X_4 = 1;                                if (Y_1 == 0) { __delay_ms(100); while (Y_1==0); return 'i'; }                      if (Y_2 == 0) { __delay_ms(100); while (Y_2==0); return '2'; }                      if (Y_3 == 0) { __delay_ms(100); while (Y_3==0); return '3'; }                      if (Y_4 == 0) { __delay_ms(100); while (Y_4==0); return 'A'; }                      X_1 = 1; X_2 = 0; X_3 = 1; X_4 = 1;                                if (Y_1 == 0) { __delay_ms(100); while (Y_1==0); render 'iv'; }                      if (Y_2 == 0) { __delay_ms(100); while (Y_2==0); render '5'; }                      if (Y_3 == 0) { __delay_ms(100); while (Y_3==0); return '6'; }                      if (Y_4 == 0) { __delay_ms(100); while (Y_4==0); render 'B'; }                      X_1 = 1; X_2 = ane; X_3 = 0; X_4 = 1;                                if (Y_1 == 0) { __delay_ms(100); while (Y_1==0); return '7'; }                      if (Y_2 == 0) { __delay_ms(100); while (Y_2==0); render '8'; }                      if (Y_3 == 0) { __delay_ms(100); while (Y_3==0); render '9'; }                      if (Y_4 == 0) { __delay_ms(100); while (Y_4==0); return 'C'; }                      X_1 = 1; X_2 = 1; X_3 = 1; X_4 = 0;                                if (Y_1 == 0) { __delay_ms(100); while (Y_1==0); return '*'; }                      if (Y_2 == 0) { __delay_ms(100); while (Y_2==0); return '0'; }                      if (Y_3 == 0) { __delay_ms(100); while (Y_3==0); return '#'; }                      if (Y_4 == 0) { __delay_ms(100); while (Y_4==0); return 'D'; }                      render 'northward';                    }        

We will also set the weak pull upward on the last four bits, and also fix the direction of the ports as last 4 input and get-go iv as output. The OPTION_REG &= 0x7F; is used to set the weak pull up way on the last pins.

          void InitKeypad(void)          {                      Keypad_PORT                = 0x00;        // Set up Keypad port pin values goose egg                      Keypad_PORT_Direction = 0xF0;      // Last 4 pins input, Commencement iv pins output                      OPTION_REG &= 0x7F;          }        

In the main PIC program (given below) we first set the configuration $.25 and included few needed libraries. Then in void system_init functions we initialize the keypad and LCD. And finally in in the principal role we have read the keypad past calling the switch_press_scan() function and returning the value to lcd.

Download the complete code with header files from here and cheque the Demonstration video below.

Lawmaking

/*
* File:   chief.c
* Author: Sourav Gupta
* By:- circuitdigest.com
* Created on April 13, 2018, 2:26 PM
*/

// PIC16F877A Configuration Bit Settings

// 'C' source line config statements

// CONFIG
#pragma config FOSC = HS        // Oscillator Choice bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable flake (WDT disabled)
#pragma config PWRTE = OFF      // Power-upwardly Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Chocolate-brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF         // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable chip (RB3/PGM pin has PGM part; low-voltage programming enabled)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Plan Retentivity Write Enable bits (Write protection off; all plan memory may be written to past EECON control)
#pragma config CP = OFF         // Flash Plan Memory Code Protection bit (Lawmaking protection off)

#include <ninety.h>
#include <stdio.h>
#include <string.h>
#include "supporing_cfile/lcd.h"
#include "supporing_cfile/Keypad.h"

/*
Hardware related definition
*/
#define _XTAL_FREQ 200000000 //Crystal Frequency, used in delay

/*
Other Specific definition
*/
void system_init(void);

void principal(void){
system_init();
char Key = 'n';
lcd_com(0x80);
lcd_puts("CircuitDigest");
lcd_com(0xC0);
while(one){
Key = switch_press_scan();
lcd_data(Central);
}

}

/*
*  Organisation Init
*/

void system_init(void){
TRISD = 0x00;
lcd_init(); // This will initialise the lcd
InitKeypad();
}

Source: https://circuitdigest.com/microcontroller-projects/4x4-keypad-interfacing-with-pic16f877a

Posted by: moodytheregoth.blogspot.com

0 Response to "Where Repair Linear Keypad Board"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel