Inconsistent output on a 4x4 matrix keypad


Results 1 to 13 of 13

Threaded View

  1. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Alternative...
    Code:
    include "C:\PBP_PROG\INCLUDE_ROUTINES\KeyPad.bas"
    
    define OSC 20
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 129 ' 9600 Baud @ 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    
    DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
    DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
    DEFINE KEYPAD_ROW_BIT    0        ' ROW0 = PORTB.4
    DEFINE KEYPAD_COL        4        ' 4 COL keypad
    DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
    DEFINE KEYPAD_COL_BIT    4        ' COL0 = PORTB.0
    DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
    DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature 
    
    INTCON2.7=0
    kKey    var byte
    
    Start:
        @ READKEYPAD _kKey
        hserout ["Key=",dec kkey,13,10]
        goto start
    Just modify the include to suite your requirement
    kEYpAD.BAS... AVAILABLE BELLOW
    http://www.picbasic.co.uk/forum/showthread.php?t=3250

    and IN YOUR serout LINE...

    Code:
    SEROUT serpin,N2400,[#key,#B0]'Send key value out PortA.1
    AND now that some know you experiment a Write/Read/Modify behaviour... use your existing code but modify it like

    Code:
    getkeyu:' Wait for all keys up
        LATB = 0 ' All output-pins low
        TRISB = $f0 ' Bottom 4-pins out, top 4-pins in
    @   nop
        IF ((PORTB >> 4) != $f) THEN getkeyu'If keys down, loop
        PAUSE 50 ' Debounce key-input
    
    getkeyp:' Wait for keypress
        FOR row = 0 TO 3 ' 4 rows in keypad
            LATB = 0 ' All output-pins low
            TRISB = (DCD row) ^ $ff ' Set one row pin to output
    @       nop
            col = PORTB >> 4 ' Read columns
            IF col != $f THEN gotkey' If any keydown, exit
            NEXT row
        GOTO getkeyp ' No keys down, go look again
    What happen now ?
    Last edited by mister_e; - 22nd November 2006 at 19:16.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Matrix Keypad routine
    By mister_e in forum Code Examples
    Replies: 134
    Last Post: - 18th September 2022, 20:30
  2. 4x4 keypad Help
    By aaliyah1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th October 2010, 16:34
  3. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  5. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 21:25

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