7-Segment and Keypad interface


A keypad is a set of buttons arranged in a block which usually bear digits, symbols and usually a complete set of alphabetical letters. If it mostly contains numbers, it can also be called a numeric keypad. Keypads are found on many alphanumeric keyboards and on other devices such as calculators, push-button telephones, combination locks, and digital door locks, which require mainly numeric input.

In this tutorial, a 3X4 keypad is used to get numeric data and display it on 7-segment display. 3X4 keypad contains 3 columns and 4 rows (12 switch) which periodically scanned by a micro-controller to check if any key is pressed. The number of the pressed key is displayed on the 7-segment.

 

keypad

7448 IC is used to drive the 7-segment and to reduce the number of pins used out of MCU. If you like, you can connect the 7-segment directly to the micro-controller across current limiting resistors (330 ohm, the resistors are not shown in the schematic).

 


Source Code:


;Name:7-Segment and Keypad Int                        ;

;Author: Abdulla M. A. Zyarah                                ;

;Notice: Copyright (c) 2008 Abdulla M. A. Zyarah -           ;

; All Rights Reserved                                                                  ;

;Date: 21-Auguest-2008                                       ;

;*****************************************************;

 PROCESSOR 16F877A
 INCLUDE  <P16F877A.INC>
 __CONFIG _XT_OSC & _PWRTE_ON & _WDT_OFF & _CP_OFF & _LVP_OFF

 ;******************************************;
 ;   INITIALIZATION                         ;
 ;******************************************;

 CBLOCK H'20'
 KEY
 ENDC

 ORG  H'00'
 GOTO INTI
 ORG  H'04'
INTI
 BANKSEL TRISB
 CLRF TRISB
 MOVLW B'00000111'
 MOVWF TRISD
 BANKSEL PORTB
 CLRF PORTB
 CLRF PORTD
 GOTO START
 ;*****************************************;
 ;   MAIN                                  ;
 ;*****************************************;

ROW
 INCF KEY
 BTFSS PORTD,0
 GOTO FOUND

 INCF KEY
 BTFSS PORTD,1
 GOTO FOUND

 INCF KEY
 BTFSS PORTD,2
 GOTO FOUND
 GOTO NEWROW

;***********************************************;
;  SELECT NEW ROW                               ;
;***********************************************;

NEWROW
 BSF  PORTD,3
 RLF  PORTD
 BTFSC STATUS,0
 GOTO ROW
 GOTO SCAN

;**********************************************;
;   FOUND                                      ;
;**********************************************;

FOUND
 RETURN

;***********************************************;
;    CHECK SWITCHS                              ;
;***********************************************;

SCAN
 CLRF KEY
 BSF  STATUS,0  ; SET THE CARRY FLAG
 BCF  PORTD,4   ; SELECT THE FIRST ROW
 GOTO ROW

;*********************************************;
;   NO. DISPLAY                               ;
;*********************************************;

NUMBER 
 ADDWF PCL,1
 NOP
 RETLW B'00000001'
 RETLW B'00000010'
 RETLW B'00000011'
 RETLW B'00000100'
 RETLW B'00000101'
 RETLW B'00000110'
 RETLW B'00000111'
 RETLW B'00001000'
 RETLW B'00001001'
 RETLW B'00001010'
 RETLW B'00000000'
 RETLW B'00001010'
 

;*************************************************;
;    SHOW                                         ;
;*************************************************;

SHOW
 MOVFW KEY 
 CALL NUMBER
 MOVWF PORTB
 RETURN
 

START 
 MOVLW B'11111111'
 MOVWF PORTD
 CALL SCAN
 CALL SHOW
 GOTO START

 END