Matrix Keypad routine - Page 4


Closed Thread
Page 4 of 4 FirstFirst 1234
Results 121 to 135 of 135
  1. #121


    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

  2. #122
    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

  3. #123
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    575


    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  

  4. #124
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    575


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Problem solved...by moving ALL rows and columns to PortB ...
    Code:
        ;    Default settings
        ;    ================
    KB_ROW        = 4                                      ; 4 ROW keypad
    KB_ROW_PORT   = PORTB                                  ; Keypad ROW on PORTB
    KB_ROW_BIT    = 0                                      ; ROW0 = PORTB.0
    KB_COL        = 4                                      ; 4 COL keypad
    KB_COL_PORT   = PORTB                                  ; Keypad Col on PORTB
    KB_COL_BIT    = 4                                      ; COL0 = PORTB.4
    DebounceDelay = 0x200                                  ; debounce delay 200mSec
    SINGLE_SCAN   = 0                                      ; Scan ;till a key is pressed

  5. #125
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Hi Guys ,

    Well this keyboard matrix routine has been here a while and works well.

    but if you need to place a 1 row or column port pin on another port out of sequence then you have a problem.

    I face this as i changed from 16f1947 to 18f67k22 on the pcb , where the 16f1947 has portF.0 , and 18f67k22 does not
    as you guessed a row pin was on Portf.0

    PORTF.0 -3 was row ,portb 0-3 was column , so no problem with the column port , but row0 wont work on an non existent port
    so the new row0 port was connected to a spare pin at portG.4

    PortG.4 TRES direction was set to output prior to keypad.bas include used , but could have been set in in the keypad.bas section of code after the asm that sets the TRES for the colume and row ports assigned


    I used the port offset value to point portG.4 , when it was selecting row0 , and set the POrtG.4 =1 prior as per steves comments
    the offset value 12 is worked out 12 port locations past portF0

    i also did not care if portF.0 TRES were set to output as per steves routine , but if this was an issue , removing the ASM code that sets the TRES in keypad.bas and do it as per normal would have been ok


    I hope this helps someone that has a similar problem

    cheers

    Sheldon

    Code section prior to change
    =====================

    Code:
    ScanKeypad:
            key=0                                              ; no key is press
            row=0                                              ; begin scan @ ROW0
            col=0                                              ; and COL0
                   
            kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
            repeat                                             
                
              
                  ROWBIT=ROW+KB_ROW_BIT                    ; point to a ROW bit
                  kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit
    after code change
    ==============

    Code:
    ScanKeypad:
            key=0                                              ; no key is press
            row=0                                              ; begin scan @ ROW0
            col=0                                              ; and COL0
            PORTG.4 = 1                                        ; Setup row-0 = 1 
            
            kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
            repeat                                             
                
                if row = 0  then 
                   Rowbit = 12                                 ; offset amount for row 0  from PortF.0 to point to PortG.4 
                 else  
                  ROWBIT=ROW+KB_ROW_BIT                        ; point to a ROW bit
                endif   
                  kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit

  6. #126
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Need help desperately!!!

    handy key fifo for this routine to keep 5 key strokes deep

    Code:
     
      if key >0  then 
           
       for Key_count  = 4 to 1 step - 1 
           Key_value(Key_count) = Key_value( Key_count - 1)
       next Key_count     
     
        Key_Value(0) = Key
       
       endif

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


    Did you find this post helpful? Yes | No

    Default Re: Need help desperately!!!

    How can I use this include for something like this ???
    Code:
    main:
    @ READKEYPAD _myvar
    gosub check
    goto main
    
    check:
    select case myvar
    
    case 1  
    porta.0 = 1 ; WHILE CASE 1 PORTA.0 = 1, THEN PORTA.0 = 0
    Thanks !

  8. #128
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Code:
    CASE 1  
      Porta.0 = 1
      WHILE myVar = 1
        @ READKEYPAD _myvar
      WEND
      PortA.0 = 0
    /Henrik.

  9. #129
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    575


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Thank You!

    LE : But don't work.
    Press button 1 of matrix ; led 1 = OFF ; end pressing button 1 ; led 1 = ON untill press ANOTHER button ...say button 2.
    But pressing button 2 don't turn ON led2 ; just another press and release of button 2 turn correspondent led (2) ON.
    Attached Images Attached Images  
    Last edited by fratello; - 12th July 2015 at 19:39.

  10. #130
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    In your first post you indicated that you wanted PortA.0 high while the myVar was equal to 1 - is that not what's happening with the code?
    How do you want it to work and what does the code look like?

  11. #131
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    575


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Thanks for support , Mr.Henrik !
    What I want :
    - porta.x = ON while correspondent button.x is pressed.
    How work :
    - press button x ; do nothing ; release button x - porta.x=ON ; remain ON while press ANOTHER button(say y) ...But this new button(y) don't turn correspondent porta.y ON ; just turn OFF previous porta.x ; only after the release of the second press turn on correspondent porta.y...
    Attached Files Attached Files
    Last edited by fratello; - 12th July 2015 at 20:20.

  12. #132
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Hi,
    1) The documentations for the keypad routine says that myVar should be a BYTE, you have it declared as a WORD. Don't think it matters but ....
    2) There's no RETURN at the end of the Check subroutine.
    3) The routine has some sort of AutoRepeat feature, I don't know if that is perhaps messing with you - I've never used the routine myself.
    4) The filename for the INCLUDE file says Keypad1, have you modifed it in any way?
    5) Do you have your LED's wired as in the schematic? Ie PortA.1 = 1 does actually turn on the LED?

    Which device?

    /Henrik.

  13. #133
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    575


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    1.I (re) declared myVar as byte .
    2.I added Return at the end of check.
    3.I use this in my keypad include :
    " SINGLE_SCAN = 0 ; Scan ;till a key is pressed
    KEYPAD_AUTOREPEAT = 1 "
    4.No, just portb allocation
    5.Yes.
    No change in how the code work ...

    Thanks again !

    LE : "SINGLE_SCAN" must be set to "1" for acting like I wish ...
    Thanks ! Regards !
    Last edited by fratello; - 12th July 2015 at 21:15.

  14. #134
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    HI
    ABOUT THE ROUTINE WRITTEN BY MR MISTER_E.
    I NEED HELP HOW TO MAKE THE NUMBERS ARE IN SERIES EXAMPLES 12345566
    AND THEN PRESS THE BUTTON # SEND VIA SERIAL A SEQUECIA.
    Code:
    #CONFIG
        __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF & _WRT_OFF   
    #ENDCONFIG
    
    DEFINE OSC 4 
    
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad2.bas"         
    
    '                      
    '    Hardware connection
    '    ===================
    
    DEFINE KEYPAD_ROW		4      
    DEFINE KEYPAD_ROW_PORT   	PORTC   
    DEFINE KEYPAD_ROW_BIT	0
    DEFINE KEYPAD_COL        	3
    DEFINE KEYPAD_COL_PORT   PORTC
    DEFINE KEYPAD_COL_BIT    	4
    DEFINE KEYPAD_DEBOUNCEMS 200     'debounce delay = 200 mSec
    define KEYPAD_AUTOREPEAT 1       'use auto-repeat
        
    ' LCD Display
    ' -----------
    ' Adjust these to suit your chosen LCD pinout
    '
    '----DEFINIR   LCD--------------------------------------------------------------
    DEFINE LCD_DREG PORTB     ' LCD data port
    DEFINE LCD_DBIT 4         ' LCD data starting bit
    DEFINE LCD_RSREG PORTB    ' LCD register select port
    DEFINE LCD_RSBIT 2        ' LCD register select bit
    DEFINE LCD_EREG PORTB     ' LCD enable port
    DEFINE LCD_EBIT 3         ' LCD enable bit
    DEFINE LCD_BITS 4         ' LCD data bus size
    DEFINE LCD_LINES 2        ' Number lines on LCD
    DEFINE LCD_COMMANDUS 5000 ' Command delay time in us
    DEFINE LCD_DATAUS 50      ' Data delay time in us
    
    mykey   VAR BYTE
    myvar   var byte
    array   var byte[5]
    index   var byte
    i       var byte
    word_v  var word
     
    LCDOUT $FE,1,  "  FONTE DIGITAL   "
    PAUSE 1000
    LCDOUT $FE,1
        '    ---------------------------------[Program Start]----------------------------------------------
    start:
        @ READKEYPAD _myvar
    	gosub lcddisp
        goto start
    
    lcddisp:
        LCDOUT $FE,$C0,DEC4 myvar 
        pause 60
        return
        end
    Attached Images Attached Images  

  15. #135
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,796


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    You may add the keypresses to an array using an index and then send the array over the serial port.

    Not tested but you get the idea:

    Code:
    string    var byte[9]
    index1    var byte
    
    start:
    For index1=0 to 8
    @ READKEYPAD _myvar
    	string[index1]=myvar
    next index1
    
    if myvar="#" then hserout [STR string\8]
    
    goto start
    Ioannis

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, 23:58
  2. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 14:16
  3. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 22:25
  4. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 04:54
  5. very basic matrix keypad question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th July 2006, 22:33

Members who have read this thread : 3

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