keypad 4x3


Closed Thread
Results 1 to 17 of 17

Thread: keypad 4x3

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default keypad

    Hello

    Thank you for your help, I change this way:
    getkeyp:'----------------------------------------- Wait for keypress
    FOR row = 0 TO 3 ' 4 rows in keypad
    PORTB = 0 ' All output-pins low
    TRISB = (DCD row) ^ $ff ' Set one row pin to output
    col = PORTB >> 3 ' Read columns
    IF col != $f THEN gotkey ' If any keydown, exit
    NEXT row
    GOTO getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 – 16

    key = (row * 3) + (NCD (col ^ $8f))




    '------RB6--RB5--RB4--
    ' | | |
    'RB0----1----2----3---row1
    ' | | |
    'RB1----4----5----6---row2
    ' | | |
    'RB2----7----8----9---row3
    ' | | |
    'RB3----*----0----#---row4
    ' | | |
    '-----col1--col2--col3


    LOOKUP key,["1","4","7","*","2","5","8","0","3","6","9","# "],skey

    LOOKUP key,["147*2580369#"],skey


    '8f = %10001111 = LED,col1,col2,col3,row4,row3,row2,row1


    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
    @ DEVICE pic16F628, WDT_ON
    @ DEVICE pic16F628, PWRT_OFF
    @ DEVICE pic16F628, BOD_ON
    @ DEVICE pic16F628, MCLR_ON
    @ DEVICE pic16F628, LVP_OFF
    @ DEVICE pic16F628, CPD_OFF
    @ DEVICE pic16F628, PROTECT_OFF


    Include "modedefs.bas"
    DEFINE OSC 4

    col VAR BYTE ' Keypad column
    row VAR BYTE ' Keypad row
    key VAR BYTE ' Key value
    i var byte
    led var PortB.7
    serpin VAR PortA.3 ' Serial output pin
    CMCON = 7 ' PortA = digital I/O
    VRCON = 0 ' Voltage reference disabled
    OPTION_REG.7 = 0 ' Enable PORTB pull-ups

    loop:
    GOSUB getkey ' Get key from keypad
    SEROUT2 serpin,84,[skey,10,13] ' Send key value out PortA.3
    GOTO loop

    getkey:
    high led
    PAUSE 50 ' Debounce key-input

    getkeyu:'----------------------------------------- Wait for all keys up

    PORTB = 0 ' All output-pins low
    TRISB = $f0 ' Bottom 4-pins out, top 4-pins in 1111 0000
    IF ((PORTB >> 4) != $f) THEN getkeyu ' If keys down, loop
    PAUSE 50 ' Debounce key-input

    getkeyp:'----------------------------------------- Wait for keypress

    FOR row = 0 TO 3 ' 4 rows in keypad
    PORTB = 0 ' All output-pins low
    TRISB = (DCD row) ^ $ff ' Set one row pin to output
    col = PORTB >> 4 ' Read columns
    IF col != $f THEN gotkey ' If any keydown, exit
    NEXT row
    GOTO getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 - 16
    key = (row * 3) + (NCD (col ^ $f))
    LOOKUP Key,["147*2580369#"],sKey ' 1 4 7 * 2 5 8 0 3 6 9 #
    'LOOKUP Key,["*","7","4","1","0","8","5","2","#","9","6","3 "],sKey
    PAUSE 50
    low led
    RETURN ' Subroutine over

    END

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default

    Jonas2

    And it still does not work?

  3. #3
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default keypad

    not yet, and the keys are shifted

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default

    You are using pull up resistors for the inputs so col will be 1111 when no key pressed. If you press number 1 then it will be 1011 so at ****2 1011 xor 1111 will become 0100 and key=(0*3)+(NCD(0100))

    which is 3 and on your lookup the third number is 7 so change the 7 to 1 and that one will be correct.

    If you wire

    '------RB4--RB5--RB6--
    ' | | |
    'RB0----1----2----3---row1
    ' | | |
    'RB1----4----5----6---row2
    ' | | |
    'RB2----7----8----9---row3
    ' | | |
    'RB3----*----0----#---row4
    ' | | |
    '-----col1--col2--col3

    then

    the lookup table is

    LOOKUP key,["123456789*0#"],skey which is a bit neater.

    If you press number 1 then it will be 1110 so at ***2 1110 xor 1111 will become 0001 and key=(0*3)+(NCD(0001))which is 1 and on your lookup the first number is 1 so that one is correct.


    Lets try again with number 8 now we have 1101 which becomes 0010 and key=(2*3)+(NCD(0010))which is 8 and on your lookup the eighth number is 8that one is correct.

    so these are the changes to make

    col = PORTB >> 4 ' Read columns ****** ************** 1
    IF col != $f THEN gotkey ' If any keydown, exit
    NEXT row
    GOTO getkeyp ' No keys down, go look again

    gotkey: ' Change row and column to key number 1 – 16

    key = (row * 3) + (NCD (col ^ $f)) ******************** 2




    '------RB4--RB5--RB6--
    ' | | |
    'RB0----1----2----3---row1
    ' | | |
    'RB1----4----5----6---row2
    ' | | |
    'RB2----7----8----9---row3
    ' | | |
    'RB3----*----0----#---row4
    ' | | |
    '-----col1--col2--col3


    'LOOKUP key,["1","4","7","*","2","5","8","0","3","6","9","# "],skey

    LOOKUP key,["123456789*0#"],skey ******************** 3

    Do you understand the maths and logic now? XOR always intrigued me along with bitwise operators. Why did anyone even think of this was my first thought. After a while I have found them useful.

    Steve

  5. #5
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default keypad

    Hello

    I still have not solved my problem, I tried different configuration
    and impossible to get what I want?

    Do you have other examples of management programs 4x3 keypad.

    Thank you
    Attached Files Attached Files

  6. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Do you have other examples of management programs 4x3 keypad.
    Why don't you use the universal keypad project? See it @ http://www.picbasic.co.uk/forum/showthread.php?t=10420

    Al.
    All progress began with an idea

  7. #7
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default

    In your program you have the rows and columns the wrong way round and also can we resolve wether it is a 3x4 or 4x4 keypad because in your program you have 16 digits in your lookup table.

    It looks to me as if you have not read my last post?

    Steve

  8. #8
    Join Date
    Feb 2006
    Location
    france
    Posts
    47


    Did you find this post helpful? Yes | No

    Default keypad

    Hello EarlyBird2

    Thank you for your help and it works well.
    Attached Images Attached Images  

Similar Threads

  1. 4x4 keypad Help
    By aaliyah1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th October 2010, 16:34
  2. 4x3 keypad and an LCD.. need help.
    By taisen83 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 6th January 2009, 09:34
  3. Keypad input test
    By Kalind in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th October 2008, 04:00
  4. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  5. 4x3 keypad
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 16th April 2006, 08:50

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts