SlideShare a Scribd company logo
Keypad
Interfacing
Done by
Akhash Kumar
Sriram Prasad MI
Kamlesh Kumar R
Keypad Interfacing
4×4 matrix keypads are
commonly used keypads in
embedded applications. Such
keypads are seen in telephones
and other commonly seen
applications.
Advantages of Matrix Keypad
The advantage of a matrix
keypad is that the use of it
will allow the programmer
to reduce the number of
pins to be used. In a 4×4
matrix keypad
● THE CPUI ACCESSES BOTH
ROWS AND COLUMNS
THROUGH PARTS
● WHEN A KEY IS PRESSED A
ROW AND COLUMN MAKE A
CONTACT. OTHERWISE THERE
IS NO CONTACT BETWEEN
THEM.
Matrix keypad
Keypad interfacing
Debouncing
These are spurious spikes generated during keypress events. Normally
several spikes get generated during a key press because of the
mechanical contacts in the switch and it causes multiple spikes
Key-press Detection
FOR KEYPAD INTERFACING TWO PROCSSES SHOULD HAPPEN:
• KEY-PRESS DETECTON
• KEY-PRESS IDENTIFICATION
THERE ARE TWO WAYS BY WHICH THE PIC18 CAN PERFORM THE KEY
DETECTION.
• INTERRUPT METHOD
• SCANNING METHOD
INTERRUPT METHOD OF KEY PRESS
DETECTION
• Keypad connected to Port B
• Rows are connected to Port B high
• Columns are connected to Port B low.
Keypad interfacing
Scanning
Introduction
● In this method, To detect a
key , the microcontroller
grounds all the rows by
providing zero
Attachments
[ App wireframe, Screenshots, ]
Step 1
Assume we pressed a button
Keypad interfacing
Step 2
If it detects a logic 0 in
any one of the columns,
then a key press was
made in that column.
Step 3
The logic is that if a
button in that row
was pressed, then the
value written that row
will be reflected in the
corresponding column
(C2) as they are short
circuited.
Step 4
The procedure is followed
till C2 goes high when logic
high is written to a row. In
this case, a logic high to
the second row will be
reflected in the second
column.
CODE for
Interrupt
Method
D15H EQU D'100’; delay high byte of value
D15L EQU D'255’; low byte of value
COL EQU 0x08; holds the column found
DR15mH EQU 0x09; registers for 15 ma delay
DR15mL EQU 0x0A;
ORG 0x000000
Initialization
High priority Interrupt
ORG 0x000008
HI_ISR BTFSC INTCON,RBIP; Was it a PORTB change?
BRA RBIF_ISR; yes then go to ISR
RETFIE; else return
Main Function
ORG 0X00
CLRF TRISD; make PORTD output port
BCF INTCON2, RBPU; enable PORTB pull-up resistors.
MOVLW 0XF0; (Make PORTB high input ports
MOVWF TRISB; Take PORTB low output ports )
MOVWF PORTB; ground all rows
CPFSEQ PORTB; are all keys open
GOTO KEYOPEN; wait until keypad ready
KEYOPEN
0XFE =
1111 0000
MOVLW upper(KCODEO)
MOVWF TBLPTRU ; load upper byte of TBLPTR
MOVLW high(KCODEO)
MOVWF TBLPTRH ; load high byte of TBLPTR
BSF INTCON, RBIE; enable PORTB change interrupt
BSF INTCON, GIE; enable all interrupts globally
LOOP GOTO LOOP; wait for key press.
--key identification ISR
RBIF_ISR CALL DELAY; wait for debounce
MOVFF PORTB,COL ; get the column of key press
MOVLW 0XFE
MOVWF PORTB; ground row 0
CPFSEQ PORTB; Did PORTB change?
BRA ROW0; yes then row 0
MOVLW 0XFD;
MOVWF PORTB; ground row 1
CPFSEQ PORTA; Did PORTB change?
BRA ROW1; yes then row 1
0XFE =
1111 1110
0XFD =
1111 1101
MOVLW 0XFB;
MOVWF PORTB; ground row 2
CPFSEQ PORTB; Did PORTB change?
BRA ROW2; yes then row 2
MOVLW 0XF7;
MOVWF PORTB; ground row 3
CPFSEQ PORTB; Did PORTB change?
BRA ROW3; yes then row 3
GOTO BAD RBIF; no then key press too short
0XFB =
1111 1011
0XF7 =
1111 0111
ROW0 MOVLW Low (KCODEO); set TBLPTR start of row 0
BRA FIND; find the column
ROW1 MOVLW low (KCODE1); set TBLPTR= start of row I
BRA FIND; find the column
ROW2 MOVLW low (KCODE2); set TBLPTR = start of row 2
BRA FIND; find the column
ROW3 MOVLW low (KCODE3); set TBLPTR start of row 3
BRA FIND; find the column
BAD RBIF MOVLW 0x00; return null
GOTO WAIT; wait for key release
FIND MOVWF TBLPTRL; load low byte of TBLPTR
MOVLW 0XF0
XORWF COL ; invert high nibble
SWAPF COL, F; bring to low nibble
AGAIN RRCF COL; rotate to find column
BC MATCH ; column found, get the ASCII code
INCF TBLPTRL; else point to next col. address
BRA AGAIN; keep searching
0XF0 =
1111 0000
MATCH TBLRD*+; get ASCII code from table.
MOVFF TABLAT, PORTD; display pressed key on PORTD
WAIT MOVLM 0XF0;
MOVWF PORTB; reset PORTB
CPPSEQ PORTB; Did PORTB change?
BRA WAIT; yes then wait for key release.
BCF INTCON, RBIF; clear PORTB, change flag
RETFIE; return and wait for key press.
-------------delay
DELAY MOVLW D15mH; high byte of delay.
MOVWF DR15mH; store in register
D2: MOVLW D15mL; low byte of delay
MOVWF DR15mL; store in register
D1: DECF DR15mL, F; Stay until DR15ml becomes 0
BNZ D1
DECP DR15mH, F; loop until all DR15m= 0x0000
BNZ D2
RETURN
----key scan code look-up table
ORG 300H
KCODE0: DB '0','1', '2', '3'; ROW 0
KCODE1: DB '4','5', '6', '7'; ROW 1
KCODE2: DB '8','9', 'A', 'B'; ROW 2
KCODE3: DB 'C' ,'D', 'E', 'F'; ROW 3
Doubts
Keypad interfacing
Thank You

More Related Content

PPTX
Serial Communication in 8051
PDF
Blynk presentation
PPT
Arithmetic & logical operations in 8051
PPTX
What are Flip Flops and Its types.
PPT
Graph theory presentation
PPTX
PPTX
Serial Communication
PPTX
Architecture of 8051
Serial Communication in 8051
Blynk presentation
Arithmetic & logical operations in 8051
What are Flip Flops and Its types.
Graph theory presentation
Serial Communication
Architecture of 8051

What's hot (20)

PPTX
Latches and flip flop
PPT
Half adder & full adder
PDF
Signals and Systems Formula Sheet
PDF
Delays in verilog
DOC
Network lab manual
PDF
Ch 4 Emergence of IoT.pdf
PPTX
BCD to binary code converter
PPTX
COUNTERS(Synchronous & Asynchronous)
PPTX
Interfacing Stepper motor with 8051
PPTX
SHIFT REGISTERS
PDF
The LaTeX Workshop: Typesetting Mathematics with LaTeX
PDF
Asynchronous sequential circuit analysis
PPT
Memory & I/O interfacing
PPSX
Fixed point and floating-point numbers
DOC
Time and space complexity
PDF
Basics of digital verilog design(alok singh kanpur)
PDF
Arm instruction set
PPTX
Digital System Processing
PPS
gsm based led scrolling board ppt
PPTX
Direct memory access (dma)
Latches and flip flop
Half adder & full adder
Signals and Systems Formula Sheet
Delays in verilog
Network lab manual
Ch 4 Emergence of IoT.pdf
BCD to binary code converter
COUNTERS(Synchronous & Asynchronous)
Interfacing Stepper motor with 8051
SHIFT REGISTERS
The LaTeX Workshop: Typesetting Mathematics with LaTeX
Asynchronous sequential circuit analysis
Memory & I/O interfacing
Fixed point and floating-point numbers
Time and space complexity
Basics of digital verilog design(alok singh kanpur)
Arm instruction set
Digital System Processing
gsm based led scrolling board ppt
Direct memory access (dma)
Ad

Similar to Keypad interfacing (20)

PPTX
Keypad and dc motor
PPTX
Microcontroller- An overview
PDF
Microcontroladores: El microcontrolador 8051 con LCD 16x2
DOCX
Keypad interfacing 8051 -NANOCDAC
PDF
timers.pdf
PDF
Instruction types
PPT
Addressing mode and instruction set using 8051
PPTX
Instruction 8.pptx
PDF
Keypad Interfacing with 8051 Microcontroller
PPT
Chp6 assembly language programming for pic copy
PPTX
PIC Presentation_final updated.pptx
PPTX
[ASM]Lab7
PPT
Lcd & keypad
PPTX
Basic of Firmware & Embedded Software Programming in C
PPTX
ee2004Asg_five_SemB25 - Read-Only.pptx
PDF
lec15_x86procedure_4up.pdf
PPT
Arm Cortex material Arm Cortex material3222886.ppt
PPT
Counters.pptv,gg,l,flf,llggfb ldgmkgmlrm
DOCX
MES LAB MANUAL for engineering students.
PDF
Switch Control and Time Delay - Keypad
Keypad and dc motor
Microcontroller- An overview
Microcontroladores: El microcontrolador 8051 con LCD 16x2
Keypad interfacing 8051 -NANOCDAC
timers.pdf
Instruction types
Addressing mode and instruction set using 8051
Instruction 8.pptx
Keypad Interfacing with 8051 Microcontroller
Chp6 assembly language programming for pic copy
PIC Presentation_final updated.pptx
[ASM]Lab7
Lcd & keypad
Basic of Firmware & Embedded Software Programming in C
ee2004Asg_five_SemB25 - Read-Only.pptx
lec15_x86procedure_4up.pdf
Arm Cortex material Arm Cortex material3222886.ppt
Counters.pptv,gg,l,flf,llggfb ldgmkgmlrm
MES LAB MANUAL for engineering students.
Switch Control and Time Delay - Keypad
Ad

More from Akhash Kumar (10)

PDF
Neural network
PDF
Fake news
PDF
Internet of things
PDF
Logistic regression
PPTX
Brahma 2019 school finals
PPTX
Brahma school 2021 final cut
PPTX
Brahma school 2021 prelims cut
PPTX
Brahma 2019 school prelim
PDF
Shakespeare quiz - finals
PDF
Shakesphere quiz prelims
Neural network
Fake news
Internet of things
Logistic regression
Brahma 2019 school finals
Brahma school 2021 final cut
Brahma school 2021 prelims cut
Brahma 2019 school prelim
Shakespeare quiz - finals
Shakesphere quiz prelims

Recently uploaded (20)

PDF
Abrasive, erosive and cavitation wear.pdf
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PDF
Design Guidelines and solutions for Plastics parts
PPTX
Software Engineering and software moduleing
PPTX
Management Information system : MIS-e-Business Systems.pptx
PPTX
introduction to high performance computing
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Artificial Intelligence
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PDF
737-MAX_SRG.pdf student reference guides
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
Feature types and data preprocessing steps
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPT
Occupational Health and Safety Management System
Abrasive, erosive and cavitation wear.pdf
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Design Guidelines and solutions for Plastics parts
Software Engineering and software moduleing
Management Information system : MIS-e-Business Systems.pptx
introduction to high performance computing
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Artificial Intelligence
Fundamentals of safety and accident prevention -final (1).pptx
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
737-MAX_SRG.pdf student reference guides
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Visual Aids for Exploratory Data Analysis.pdf
Feature types and data preprocessing steps
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Occupational Health and Safety Management System

Keypad interfacing

  • 2. Keypad Interfacing 4×4 matrix keypads are commonly used keypads in embedded applications. Such keypads are seen in telephones and other commonly seen applications.
  • 3. Advantages of Matrix Keypad The advantage of a matrix keypad is that the use of it will allow the programmer to reduce the number of pins to be used. In a 4×4 matrix keypad
  • 4. ● THE CPUI ACCESSES BOTH ROWS AND COLUMNS THROUGH PARTS ● WHEN A KEY IS PRESSED A ROW AND COLUMN MAKE A CONTACT. OTHERWISE THERE IS NO CONTACT BETWEEN THEM.
  • 7. Debouncing These are spurious spikes generated during keypress events. Normally several spikes get generated during a key press because of the mechanical contacts in the switch and it causes multiple spikes
  • 8. Key-press Detection FOR KEYPAD INTERFACING TWO PROCSSES SHOULD HAPPEN: • KEY-PRESS DETECTON • KEY-PRESS IDENTIFICATION THERE ARE TWO WAYS BY WHICH THE PIC18 CAN PERFORM THE KEY DETECTION. • INTERRUPT METHOD • SCANNING METHOD
  • 9. INTERRUPT METHOD OF KEY PRESS DETECTION • Keypad connected to Port B • Rows are connected to Port B high • Columns are connected to Port B low.
  • 12. Introduction ● In this method, To detect a key , the microcontroller grounds all the rows by providing zero
  • 14. Step 1 Assume we pressed a button
  • 16. Step 2 If it detects a logic 0 in any one of the columns, then a key press was made in that column.
  • 17. Step 3 The logic is that if a button in that row was pressed, then the value written that row will be reflected in the corresponding column (C2) as they are short circuited.
  • 18. Step 4 The procedure is followed till C2 goes high when logic high is written to a row. In this case, a logic high to the second row will be reflected in the second column.
  • 20. D15H EQU D'100’; delay high byte of value D15L EQU D'255’; low byte of value COL EQU 0x08; holds the column found DR15mH EQU 0x09; registers for 15 ma delay DR15mL EQU 0x0A; ORG 0x000000 Initialization
  • 21. High priority Interrupt ORG 0x000008 HI_ISR BTFSC INTCON,RBIP; Was it a PORTB change? BRA RBIF_ISR; yes then go to ISR RETFIE; else return
  • 22. Main Function ORG 0X00 CLRF TRISD; make PORTD output port BCF INTCON2, RBPU; enable PORTB pull-up resistors. MOVLW 0XF0; (Make PORTB high input ports MOVWF TRISB; Take PORTB low output ports ) MOVWF PORTB; ground all rows CPFSEQ PORTB; are all keys open GOTO KEYOPEN; wait until keypad ready KEYOPEN 0XFE = 1111 0000
  • 23. MOVLW upper(KCODEO) MOVWF TBLPTRU ; load upper byte of TBLPTR MOVLW high(KCODEO) MOVWF TBLPTRH ; load high byte of TBLPTR BSF INTCON, RBIE; enable PORTB change interrupt BSF INTCON, GIE; enable all interrupts globally LOOP GOTO LOOP; wait for key press.
  • 24. --key identification ISR RBIF_ISR CALL DELAY; wait for debounce MOVFF PORTB,COL ; get the column of key press MOVLW 0XFE MOVWF PORTB; ground row 0 CPFSEQ PORTB; Did PORTB change? BRA ROW0; yes then row 0 MOVLW 0XFD; MOVWF PORTB; ground row 1 CPFSEQ PORTA; Did PORTB change? BRA ROW1; yes then row 1 0XFE = 1111 1110 0XFD = 1111 1101
  • 25. MOVLW 0XFB; MOVWF PORTB; ground row 2 CPFSEQ PORTB; Did PORTB change? BRA ROW2; yes then row 2 MOVLW 0XF7; MOVWF PORTB; ground row 3 CPFSEQ PORTB; Did PORTB change? BRA ROW3; yes then row 3 GOTO BAD RBIF; no then key press too short 0XFB = 1111 1011 0XF7 = 1111 0111
  • 26. ROW0 MOVLW Low (KCODEO); set TBLPTR start of row 0 BRA FIND; find the column ROW1 MOVLW low (KCODE1); set TBLPTR= start of row I BRA FIND; find the column ROW2 MOVLW low (KCODE2); set TBLPTR = start of row 2 BRA FIND; find the column ROW3 MOVLW low (KCODE3); set TBLPTR start of row 3 BRA FIND; find the column BAD RBIF MOVLW 0x00; return null GOTO WAIT; wait for key release
  • 27. FIND MOVWF TBLPTRL; load low byte of TBLPTR MOVLW 0XF0 XORWF COL ; invert high nibble SWAPF COL, F; bring to low nibble AGAIN RRCF COL; rotate to find column BC MATCH ; column found, get the ASCII code INCF TBLPTRL; else point to next col. address BRA AGAIN; keep searching 0XF0 = 1111 0000
  • 28. MATCH TBLRD*+; get ASCII code from table. MOVFF TABLAT, PORTD; display pressed key on PORTD WAIT MOVLM 0XF0; MOVWF PORTB; reset PORTB CPPSEQ PORTB; Did PORTB change? BRA WAIT; yes then wait for key release. BCF INTCON, RBIF; clear PORTB, change flag RETFIE; return and wait for key press.
  • 29. -------------delay DELAY MOVLW D15mH; high byte of delay. MOVWF DR15mH; store in register D2: MOVLW D15mL; low byte of delay MOVWF DR15mL; store in register D1: DECF DR15mL, F; Stay until DR15ml becomes 0 BNZ D1 DECP DR15mH, F; loop until all DR15m= 0x0000 BNZ D2 RETURN
  • 30. ----key scan code look-up table ORG 300H KCODE0: DB '0','1', '2', '3'; ROW 0 KCODE1: DB '4','5', '6', '7'; ROW 1 KCODE2: DB '8','9', 'A', 'B'; ROW 2 KCODE3: DB 'C' ,'D', 'E', 'F'; ROW 3