row -> col and col -> row


Results 1 to 6 of 6

Threaded View

  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.

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