row -> col and col -> row


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302

    Default row -> col and col -> row

    I have the below code and work.
    But ,when i push the number 4 show 3 , when i push the number 7 show 3 , when i push the number 2 show 4
    when i push the number 3 show 7
    How to make the row -> col and col -> row to show right;

    Code:
        Col VAR BYTE                 ' Keypad column
        Row VAR BYTE                 ' Keypad row
        Key VAR BYTE                 ' Key value
    
        Lcdout $fe, 1, "Press any key"          ' Display sign on message
        
    Loop:
        Gosub getkey                            ' Get a key from the keypad  
        Lcdout $fe,1, #key
        goto loop
    
    GetKey: 
        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
        IF ((PORTB >> 4) != $f) THEN getkeyu    ' If keys down, loop
        PAUSE 50                                ' Debounce key-input
    
    GetKeyp:                                    ' Wait for keypress
        FOR col = 0 TO 3                        ' 4 rows in keypad
        PORTB = 0                               ' All output-pins low
        TRISB = (DCD col) ^ $ff                 ' Set one row pin to output
        row = PORTB >> 4                        ' Read columns
        IF row != $f THEN gotkey                ' If any keydown, exit
        NEXT col
        GOTO getkeyp                            ' No keys down, go look again
    
    GotKey:                                     ' Change row and column to key number 1 - 16
        key = (col * 4) + (NCD (row ^ $f))
    
        RETURN                                  ' Subroutine over
    Last edited by savnik; - 12th April 2007 at 15:08.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    I have the below code and work.
    How to make the row -> col and col -> row
    SWAP col,row

  3. #3
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    SWAP col,row
    I swap col with row with no succes

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    I swap col with row with no succes
    Maybe do a search on 'matrix keypad'

  5. #5


    Did you find this post helpful? Yes | No

    Default

    This is how I read a 16 matrix membrane switch. All horizonal rows connected to PORTC 1,2,3,4 outputs. All vertical columns connected to PORTB 1,2,3,4 inputs held high by resistor network. This example just shows eight readings:

    PORTC = 255 'MAKE SURE ALL OUTPUTS ARE HIGH

    START:
    LOW PORTC.1
    PAUSE 1
    IF PORTB.1 = 0 THEN ONE
    IF PORTB.2 = 0 THEN TWO
    IF PORTB.3 = 0 THEN THREE
    IF PORTB.4 = 0 THEN FOUR
    HIGH PORTC.1
    PAUSE 1

    LOW PORTC.2
    PAUSE 1
    IF PORTB.1 = 0 THEN FIVE
    IF PORTB.2 = 0 THEN SIX
    IF PORTB.3 = 0 THEN SEVEN
    IF PORTB.4 = 0 THEN EIGHT
    HIGH PORTC.2

    Pauses are added to slow down the process. Without them we experienced intermittant problems (probably from capacitance in the membrane switch). Hope this helps.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. keypad 4x3
    By jonas2 in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 15th July 2009, 06:34
  2. problem with my code
    By civicgundam in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd February 2008, 01:52
  3. cant get my Lcd to work using Pic18f452
    By civicgundam in forum General
    Replies: 13
    Last Post: - 7th October 2007, 00:13

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