• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

KeyPad Design problem

Status
Not open for further replies.

manba

New Member
Hi, there..

I'm designing a 3x4 KeyPad with LCD. I'm using pic16f877a and PICBasic.

The program take the number from the keypad and disply the number on the LCD"Key= num".If no number pressed the LCD disply "Key= 0"

The problem is: only the numbers of the first column are displied on the LCD.

I tried to solve the problem but i couldn't. plz help me.:confused::confused:


Code:
DEFINE OSC 20
'**** LCD ****
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 8
DEFINE LCD_BITS 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 40
Key VAR WORD
'**** KeyPad *****
TRISD = %11110000
'**** VAR_KEY ****
OLD_RESULT VAR BYTE
KEY_RESULT VAR BYTE
KEYPRESS var byte
FLAG VAR BIT

'**** MAIN program ****
PAUSE 500
LCDOUT $FE,1
MAIN:
CALL MAIN_LCD
CALL MAIN_KEY
GOTO MAIN


'**** LCD Subprogram ****
MAIN_LCD:
Key = OLD_RESULT
LCDOUT $FE,$80
LCDOUT "Key = ",DEC Key
RETURN



'**** Keypad Subprogram ****
MAIN_KEY:
    CALL SCANKEY  
    IF KEY_RESULT = OLD_RESULT THEN MAIN  'same character
    IF KEY_RESULT = 0 THEN MAIN          'non is pressed
    RETURN                      ' will replace with (RETURN)   
'**** Scan Key Subprogram ****
SCANKEY:
    KEYPRESS = 0
PORTD = %0100                      ' Chose colum 1
    CALL ROW
    IF FLAG = 1 THEN FIRST_COLUM
PORTD = %0010                      ' Chose colum 2
    CALL ROW
    IF FLAG = 1 THEN SECOND_COLUM
PORTD = %0001                      ' Chose colum 3
    CALL ROW
    IF FLAG = 1 THEN THIRD_COLUM
    KEY_RESULT = 0
    RETURN
FIRST_COLUM:
    LOOKUP KEYPRESS,[1,4,7,10],KEY_RESULT
    OLD_RESULT = KEY_RESULT
    RETURN
SECOND_COLUM:
    LOOKUP KEYPRESS,[2,5,8,0],KEY_RESULT
    OLD_RESULT = KEY_RESULT
    RETURN
THIRD_COLUM:
    LOOKUP KEYPRESS,[3,6,9,11],KEY_RESULT
    OLD_RESULT = KEY_RESULT
    RETURN
ROW:
    FLAG = 1
    IF PORTD.4 = 1 THEN EXIT_ROW
    KEYPRESS = KEYPRESS + 1
    IF PORTD.5 = 1 THEN EXIT_ROW
    KEYPRESS = KEYPRESS + 1
    IF PORTD.6 = 1 THEN EXIT_ROW
    KEYPRESS = KEYPRESS + 1
    IF PORTD.7 = 1 THEN EXIT_ROW
    KEYPRESS = KEYPRESS + 1
    FLAG = 0
EXIT_ROW:
    RETURN
END
 

Attachments

Last edited:

Pommie

Well-Known Member
Most Helpful Member
Try setting KEYPRESS to zero at the start of the row subroutine. At the moment you only zero it for column one.

Mike.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top