10x4 matrix keyboard using only portB


Closed Thread
Results 1 to 20 of 20

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Darel be patient next release will be with "PORTB change interrupts". For that I need to build a new hardware prototype and it will take few days.
    I had to fix the bug you pointed out quickly, otherwise I could not sleep!

    Regards

    Al.
    All progress began with an idea

  2. #2


    Did you find this post helpful? Yes | No

    Default

    If I am looking at this correctly, the one drawback to this design is that you can't detect multiple keypresses in the sam row, right? In fact, holding two keys down in the same row could cause the wrong character code to be generated. Like holding down 1,1,and 1,8 gives you the code for 1,9, right? Not trying to nitpick. Just wanted to make sure I understood the advantages and disadvantages to the design.
    Tim Barr

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


    Did you find this post helpful? Yes | No

    Default

    Yes Tim, this is the price you have to pay for the extra keys!

    If the spacing of the keypad is done properly than chances to press two contiguous keys at the same time are really rare, but since number of keys available is no more an issue, you can dedicate one key to delate the possible unwanted input.

    Al.
    All progress began with an idea

  4. #4
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    I believe that a protocol is possible to detect simultaneous key presses, BUT it would fail if both keys were pressed at exactly the same time (incredibly unlikely though). However, if it did occur -- the procedure would return the key that equated to the binary sum of the two keys held down.

    You would only need microseconds of a difference between the keys being pressed to come up with something that works.

    Trent Jackson
    Last edited by T.Jackson; - 19th November 2008 at 06:48.

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,143


    Did you find this post helpful? Yes | No

    Default

    Since we are talking about mechanical switch, that micro seconds might be to short time in my opinion. Debouncing is needed to read the switch correctly.

    Ioannis

  6. #6
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Moreover ...

    I think if the columns were each given a unique, physical delay, say using an RC circuit -- you'd eliminate the possibility of two keys ever being processed as one.

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


    Did you find this post helpful? Yes | No

    Default

    Following T.Jackson suggestion, I removed the auto-repeat, now multiple keys have to close exactly at the same time to be decoded as the sum. This has been accomplished introducing a WHILE WEND which detect when you release the key.

    To follow the code.

    Al.

    Code:
    '****************************************************************
    '*  Name    : 60 Keys_Kpad.BAS                                  *
    '*  Author  : [a.ratti]                                         *
    '*  Notice  : Copyright (c) 2008                                *
    '*          : All Rights Reserved                               *
    '*  Date    : 20/11/2008                                        *
    '*  Version : 2.2                                               *
    '*  Notes   :           Micro used: Pic 16F84a                  *
    '*          : The software will decode any matrix keypad 4 x n  *
    '*          :    where n is any columns number from 1 to 15     *
    '****************************************************************
    
    TrisA = %00000000
    TRISB = %11111111
    
    Define OSC 4
    
    '--- EEprom ASCII code assignment to define keys response ---------
    
    '------------------- First Row --------------------
    Eeprom 1,[49,50,51,52,53,54,55,56,57,48,43,40,94,91,27]' (1,1)-(1,15)
    
    '--------------------Second Row --------------------
    Eeprom 16,[65,66,67,68,69,70,71,72,73,74,45,41,37,93,26]' (2,1)-(2,15)
    
    '--------------------- Third Row ------------------
    Eeprom 31,[75,76,77,78,79,80,81,82,83,84,47,64,36,60,62]' (3,1)-(3,15)
    
    '--------------------- Fourth Row ------------------
    Eeprom 46,[85,86,87,88,89,90,46,58,59,61,42,35,38,32,13]' (4,1)-(4,15)
    '------------------------------------------------------------------
    
    
    
    '--------------------------- Set variables and pins --------------------
    
    LED         VAR PortA.0     ' Heart beating led
    Buz         var PortA.1     ' got character acknowledgement
    Tx          var PortA.2     ' Serial out
    RTS         var portA.3     ' Ready to sent when low
    T9600       con 2           ' baud rate = 9600
    
    UCase       var byte
    KeyFlag     var byte
    KbOut       var Byte    [2] ' Buffer Array 
    
    high Tx                     ' purge serial line (True Mode)
    High RTS                    ' disable RTS
    low Buz                     ' Bepper off
    
    KeyFlag = 0                 ' reset variable
    Ucase = 0                   ' set uppercase
    
    
    '-------------------------- Main program -------------------------------
    
     Loop:
     if KeyFlag>0 then           'If <> 0 then Tx ASCII character and Beep
     Low RTS                     'RTS flag enabled
     pause 20
     
     if KbOut[1]=26 then Loop    'Skip ascii code 26
     
     If KbOut[1]=>65 then        'Skip ascii code <> character 
     KbOut[0] = KbOut[1] + UCase 'If UCase = 0 then UpperCase 
     else
     KbOut[0] = KbOut[1]
     endif
     
     '---------------------------------------------------------------------
     Serout Tx,T9600,[KbOut[0]]  ' Tx ascii character 
     '----- Choose one of the two serout comand DON'T SELECT BOTH !!! -----
     'Serout Tx,T9600,[#KbOut[0]]  ' Tx ascii code 
     '---------------------------------------------------------------------
     
     High RTS                   ' RTS flag disabled
     high buz                   ' Beep on 
     pause 30                   ' time duration of the beep
     low Buz                    ' Bepper off
     pause 150
     endif
     pause 50                   ' Heart beating frequency
     toggle Led                 ' Heart beating
     
     while KeyFlag>0            ' stop auto repeat
     KeyFlag = PortB
     KeyFlag=KeyFlag & %00001111
     wend 
     
     '----------------------------- KeyScan routine ------------------------
     
     KeyFlag=0                  ' reset flag variable
     
     '------------------------ First Row - keys from 1 to 15  --------------
     TRISB = %11101111
     PortB =16
     If PortB>16 then           ' one key of the first row has been pressed
     KeyFlag=PortB 
     KeyFlag=KeyFlag & %00001111  ' decode to which column the key belongs 
     Gosub GetChar
     goto Loop
     endif
     
     '------------------------ Second Row - keys from 16 to 30 -------------
     TRISB = %11011111
     PortB =32
     If PortB>32 then           ' one key of the second row has been pressed
     KeyFlag=PortB
     KeyFlag=KeyFlag & %00001111
     KeyFlag = KeyFlag +15      ' decode to which column the key belongs
     gosub GetChar
     goto Loop
     endif
     
     '----------------------- Third Row - keys from 31 to 45 ---------------
     TRISB = %10111111
     PortB =64
     If PortB>64 then           ' one key of the third row has been pressed
     KeyFlag=PortB
     KeyFlag=KeyFlag & %00001111
     KeyFlag = KeyFlag +30      ' decode to which column the key belongs
     gosub GetChar
     goto Loop
     endif
     
     '------------------------ Fourth Row - keys from 46 to 60 -------------
     TRISB = %01111111
     PortB =128
     If PortB>128 then          ' one key of the fourth row has been pressed
     KeyFlag = PortB
     KeyFlag=KeyFlag & %00001111
     KeyFlag = KeyFlag +45      ' decode to which column the key belongs
     gosub GetChar
     endif
     
     goto Loop
     
     '------------------------ End of keyscan routine ----------------------
     
     
     '----------------------------------------------------------------------
     '---------------- Select Uppercase or LowCase letters -----------------
     '------ (Ucase = 32 then lowerCase)  (UCase = 0 then UpperCase) -------
     '----------------------------------------------------------------------
     GetChar: ' Read ASCII code from eeprom & set UCase or LCase
     Read KeyFlag, KbOut[1]
     If  KbOut[1]=26 then
     If UCase=0 then
     Ucase=32
     else
     UCase=0
     endif
     endif
     return
     
     
     end
    All progress began with an idea

  8. #8


    Did you find this post helpful? Yes | No

    Default

    I found this reference on another forum that was very interesting. I had never heard of Charlieplexing before but this is really cool. It not only applies to multiplexing outputs, but inputs as well. Since the guy that came up with this works at Maxim, there are even some Maxim parts that use charlieplexing to drive LEDs. It looks like aratti's design may be a variant of charlieplexing.
    Tim Barr

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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