10x4 matrix keyboard using only portB


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    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.

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

  3. #3


    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

  4. #4
    Join Date
    Oct 2005
    Posts
    34


    Did you find this post helpful? Yes | No

    Default Re: 10x4 matrix keyboard using only portB

    Just Brilliant
    You can't teach an old dog new tricks, but I'm always willing to try.

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, 20:52
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 17:10
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 07:11
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 21:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 6th May 2005, 00: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