Arduino sprintf()Arduino sprintf

Matrix 4×4 keypad interfacing with pic microcontroller is another one of the most wide problem which we often face and in today’s tutorial we are going to explain the 4×4 keypad interfacing with pic16f877a microcontroller. It makes very special problem to not even decode the matrix 4×4 keypad but also to open the door of all kind of matrix scanning you can do in assembly language. Let’s jump into the implementation of pic microcontroller based keypad interfacing in assembly language

Components Required:

  • PIC16F877A microcontroller
  • 4×4 matrix keypad
  • Breadboard
  • Jumper wires

Connections:

  • Keypad: rows to RB0-RB3, columns to RC0-RC3

Key Concepts:

  • Keypad scanning
  • Assembly language programming
  • Input/output interfacing

PIC Assembly code for Keypad interfacing

Here is a complete code for interfacing the 4×4 keypad with PIC16f877A microcontroller.

LIST P=16F877A
INCLUDE<P16F877A.INC>

ORG 0
GOTO START

ORG 4
START:
BSF STATUS, RP0      ; Select bank 1
MOVLW B'00000000'    ; Set PORTB as output
TRISB
MOVLW B'11110000'    ; Set PORTC as input
TRISC
CLRF COUNT           ; Initialize COUNT
CLRF TEMP            ; Initialize TEMP
LOOP:
MOVLW 0x0F
MOVWF COUNT1
ROW:
BCF PORTB, 0
BCF PORTB, 1
BCF PORTB, 2
BCF PORTB, 3
BSF PORTB, COUNT    ; Set output to current row
COL:
BTFSS PORTC, 0
GOTO COL1
BTFSS PORTC, 1
GOTO COL2
BTFSS PORTC, 2
GOTO COL3
BTFSS PORTC, 3
GOTO COL4
GOTO LOOP
COL1:
MOVLW COUNT
ADDWF COUNT, F       ; Update TEMP with current row and column
MOVLW .50            ; Delay for debounce
CALL DELAY
GOTO LOOP
COL2:
MOVLW COUNT
ADDWF COUNT, F
ADDWF COUNT, F       ; Update TEMP with current row and column
MOVLW .50
CALL DELAY
GOTO LOOP
COL3:
MOVLW COUNT
ADDWF COUNT, F
ADDWF COUNT, F
ADDWF COUNT, F       ; Update TEMP with current row and column
MOVLW .50
CALL DELAY
GOTO LOOP
COL4:
MOVLW COUNT
ADDWF COUNT, F
ADDWF COUNT, F
ADDWF COUNT, F
ADDWF COUNT, F      ; Update TEMP with current row and column
MOVLW .50
CALL DELAY
GOTO LOOP

DELAY:
MOVWF TEMP1
LOOP1:
MOVLW .250
MOVWF COUNT1
LOOP2:
NOP
DECFSZ COUNT1, F
GOTO LOOP2
DECFSZ TEMP1, F
GOTO LOOP1
RETURN

COUNT EQU 20h
TEMP EQU 21h
TEMP1 EQU 22h
COUNT1 EQU 23h

END


Code language: PHP (php)

Key Functions:

  • START: Initializes PORTB and PORTC and starts the main program loop
  • LOOP: Scans the keypad and updates TEMP with the current keypress
  • ROW: Sets the output to the current row
  • COL: Checks the current column for a keypress
  • DELAY: Delays for debounce

Tips:

  • Adjust the delay time as needed for your specific application.
  • Modify the code to handle the specific characters or functions that your keypad uses.

This code-centric guide demonstrates how to interface a 4×4 matrix keypad with a PIC microcontroller using assembly language programming. By following the provided code and connections, you can create a functional keypad interface for various applications.

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.