Matrix Keypad routine


Closed Thread
Results 1 to 40 of 135

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Fixed!!

    Hi Darrel

    Thanks for the assistance :-)
    The LOOKUP change was the easiest solution !

    originally I had this
    Code:
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
    
    LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress
    And I just changed the line to this
    Code:
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
       LOOKUP myvar,[0,"D#0*C987B654A321"],myvar
    Thanks a million , it saves me having to redo my dev board design or re-wiring the keypad :-) YAY

    Kind regards
    Dennis

  2. #2
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Fail enought times and you start to learn!

    HI all,
    I have been playing with this wonderful piece of code for many hours. Really cool code. I was having problems with one row of the keypad but the rest was working enough for me to proceed filling in the gaps and learning the lessons from the thread. I bring this up because I have been caught on it before, you would have thought I'd have learned....

    The row in question would freeze the operation of the circuit. Upon looking closely at the datasheet, I my eye caught the LOW VOLTAGE PROGRAMMING option. A faint voice in my head reminded me that we were not friends (the option, not the voice). Yep, that was it. Disabled it in meLabs programmer and... you guessed it... runs just like it was suppose to. Who'd a thought it?

    Hope that this saves someone else some head banging. Some gotchas I have to keep reminding myself about.
    Bo

  3. #3
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Converting in Steve's include

    Hi all,

    I have managed to get Steve's (Mister E) KeyPad.bas to remap and do what I would like to accomplish. Thanks again Steve for writing it and you others for explaining it. Really handy!

    Here's the question: Where in KeyPad.bas would you insert the "LOOKUP myvar,... " so that you only had to do it once and not burn up a bunch of space? In my case, I would save the original, and rename the converter custom version to something appropriate.

    From what I can decipher, (which is embarrassingly meager), the include file sets up a macro if you choose to use "@ READKEYPAD _YourVar". It gets the result from the subroutine "KeypadScan".

    Am I right that the "LOOKUP..." would go just before the "ReadCol:"
    subroutine to allow the remapping to occur each time you look for a key?

    Thanks
    Bo

  4. #4
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Appologies

    I'm sorry to the list....

    After I posted that last question, it hit me like a brick... That was being really immature... I knew what I wanted to happen, but I hung when I saw a bit of code that was confusing to me. I had an idea what might work but instead of trying to test it myself, I defaulted to asking the list. Very poor.. I should have at least tried something and done some of my own work first instead of asking others to do it for me.

    My feeble assumption proved so far to be correct, by adding the LOOKUP into what I now call KeyPadRM.bas (the RM for ReMap), and making sure to save it as a .bas, I can eliminate many redundant lines of code. The edit is at the end of Steve's code:
    Code:
    ......
                until row>(KB_ROW-1)                           
            if (single_scan=0) AND (KEY=0) then ScanKeypad     ; Row scan finished?
      LOOKUP  Key,[0,1,2,3,10,4,5,6,11,7,8,9,12,15,14,16,13],Key ; ReMap Edit  
          RETURN                                                 ; any key pressed?      
    ReadCol:
        KeyTemp=kb_col_PORT>>kb_col_Bit                        ; Read Column state
        KeyTemp=KeyTemp & kEYMASK                              ; Keep only wanted bits
        return
    
    JumpOverKeyScan:
    Any corrections of my understanding are welcome.
    Bo

  5. #5


    Did you find this post helpful? Yes | No

    Default Hey Bo

    I think that's fantastic :-)

    Thank you !

    I'm not sure why you're running yourself down like that , you should give yourself a pat on the back !

    I think that the list is a great place for when you get to the point of confusion and whether or not someone replies at least you have jotted down your thoughts either for tohers to give advice or give you a different angle or even you realising that there is another angle on a problem or solution :-)

    I have also had the same issues, having to reload the same code or think about more efficient ways to change my bits of code to use the results from the keypad routine more efficiently.

    Now .. a quick question .. did you just add the lookup line in the place you have pointed out in the code stub you posted ? So the 'looked-up' keypress now is held in MYVAR ?

    Kind regards

    Dennis

  6. #6
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Hi Dennis
    I'm really not putting myself down as much as it sounds, more like venting so that others can see the process. I feel strongly that one should close the loop when something is learned. Otherwise, no one can gain from it. I get very frustrated when I run into an open loop never get to find out what was resolved. The main point on my thoughts were the realization that I could have written a snippet and tested my idea quicker than I could have written up the question. That's pretty sad. Time to start moving from milk to meat..

    In answer to your question, the snippet of code that I posted is exactly what I used. The variable was converted in that line and returned just as if that line was never inserted.

    Bo

  7. #7
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    I made a simple schematic for testing my remote control stalk near the steering wheel, from Renault.
    I use "KeyPad_2.bas" , addapted to my hardware :
    Code:
        ;
        ;    Default settings
        ;    ================
    KB_ROW        = 2                                      ; 2 ROW keypad
    KB_ROW_PORT   = PORTB                                  ; Keypad ROW on PORTB
    KB_ROW_BIT    = 0                                      ; ROW0 = PORTB.0
    KB_COL        = 3                                      ; 3 COL keypad
    KB_COL_PORT   = PORTA                                  ; Keypad Col on PORTA
    KB_COL_BIT    = 0                                      ; COL0 = PORTA.0
    DebounceDelay = 0x41                                   ; debounce delay 41mSec
    SINGLE_SCAN   = 0                                      ; Scan ;till a key is pressed   
    KEYPAD_AUTOREPEAT = 1
    The code it's verry simple :
    Code:
    @ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_OFF, LVP_OFF
    
       Define   OSC 4           ' 4MHz 
       CMCON = 7                ' Disable on-chip comparator, PORTA in digital mode
       OPTION_REG.7=1
    
    include "c:\pbp\MYKEY.BAS" ' see http://www.picbasic.co.uk/forum/showthread.php?t=3250
    
    main:
    gosub keypadscan
    gosub check
    goto main
    
    
    check:
    select case key 
    CASE 1  
    portb.2 = 1
    pause 5000
    portb.2 = 0
       
    case 2    
    portb.3 = 1
    pause 5000
    portb.3 = 0
    
    case 3    
    portb.4 = 1
    pause 5000
    portb.4 = 0   
    
    case 4    
    portb.5 = 1
    pause 5000
    portb.5 = 0
    
    case 5    
    portb.6 = 1
    pause 5000
    portb.6 = 0
    
    case 6    ; track +
    portb.7 = 1
    pause 5000
    portb.7 = 0
    
    end select
    Return
    But....
    Allways LED's on PortB.2 and PortB.3 are ON ! What I am doing wrong ?!? Thanks in advance for reply !
    Attached Images Attached Images  

Similar Threads

  1. calculator-like code entry with matrix keypad and display
    By Dennis in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 16th December 2009, 22:58
  2. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  3. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 21:25
  4. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 03:54
  5. very basic matrix keypad question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th July 2006, 21:33

Members who have read this thread : 2

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