Matrix keyboard for up to 32 keys


Closed Thread
Results 1 to 2 of 2
  1. #1
    Pedro Pinto's Avatar
    Pedro Pinto Guest

    Default Matrix keyboard for up to 32 keys

    Hello
    For scan a keyboard with up to 16 keys we use this code from Melabs,
    I need it for up to 32 keys. It is possible with this construct, and how?

    Thanks
    Regards
    Pedro


    Code:
    ' PicBasic Pro program to display key number on LCD
    ' Define LOADER_USED to allow use of the boot loader.
    ' This will not affect normal program operation.
    Define	LOADER_USED	1
    
    ' Define LCD connections
    Define  LCD_DREG        PORTD
    Define  LCD_DBIT        4
    Define  LCD_RSREG       PORTE
    Define  LCD_RSBIT       0
    Define  LCD_EREG        PORTE
    Define  LCD_EBIT        1
    
    ' Define program variables
    col     var     byte            ' Keypad column
    row     var     byte            ' Keypad row
    key     var     byte            ' Key value
    
            OPTION_REG.7 = 0        ' Enable PORTB pullups
            ADCON1 = 7              ' Make PORTA and PORTE digital
            Low PORTE.2             ' LCD R/W low (write)
            Pause 100               ' Wait for LCD to start
            Lcdout $fe, 1, "Press any key"  ' Display sign on message
    
    loop:   Gosub getkey            ' Get a key from the keypad
            Lcdout $fe, 1, #key     ' Display ASCII key number
            Goto loop               ' Do it forever
    
    ' Subroutine to get a key from keypad
    getkey:
            Pause 50                ' Debounce
    
    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 any keys down, loop
    
            Pause 50                ' Debounce
    
    getkeyp:
            ' Wait for keypress
            For col = 0 to 3        ' 4 columns in keypad
                    PORTB = 0       ' All output pins low
                    TRISB = (dcd col) ^ $ff ' Set one column pin to output
                    row = PORTB >> 4        ' Read row
                    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
    
            End

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Using mister-e's Matrix Keypad module you can have 64 keys if you want.
    Requires 2 full 8-bit ports, 8 rows, 8 columns.

    OR ... 8 rows, 4 columns = 32 keys
    OR ... 4 rows, 8 columns

    It's essentially an extension of the meLabs keypad example with more features.

    Matrix Keypad routine
    http://www.picbasic.co.uk/forum/showthread.php?t=3250
    <br>
    DT

Similar Threads

  1. 10x4 matrix keyboard using only portB
    By aratti in forum Code Examples
    Replies: 19
    Last Post: - 16th November 2011, 09:39
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 16:10
  3. reading and conecting 10x6 matrix keyboard
    By ustredna in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 9th August 2006, 03:04
  4. LCD + keyboard matrix minimal I/O
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st June 2006, 19:49
  5. Matrix keyboard problem
    By MegaADY in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 9th May 2005, 18:50

Members who have read this thread : 1

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