Hi Steve,

Some time ago you modified your code for pbp243 (if you remember)
Meanwhile I have updated to 2.50

After playing with your code I have a strange behavior
If I want to serout something in the main loop it is not working
any idea how to fix this



INCLUDE "KeyPad.bas"
myvar var byte

start:
Hserout ["test",10,13] 'does not do anything
@ READKEYPAD _myvar
hserout ["Key=",dec myvar,13,10]
if myvar =1 then
Hserout ["test2",10,13] 'does work if button 1 pressed
endif
goto start



Quote Originally Posted by mister_e View Post
Here's a simple INCLUDE file wich allow to scan any matrix KeyPad format on any PORT you decide. Yeah i know, a bit code hungry but simple to use and it's free...

The defaults setings are
  1. Keypad ROW are connected to PORTB<3:0>
  2. Keypad COL are connected to PORTB<7:4>
  3. Debounce delay = 200 mSec
  4. No auto-repeat
  5. Keypad type 4X4

Code example using the default setting
Code:
    INCLUDE "KeyPad.bas"         
    myvar                    var byte

start:
    @ READKEYPAD _myvar
    hserout ["Key=",dec myvar,13,10]
    goto start
NOT MUCH!
If you decide to change default settings, here's the DEFINEs list
Code:
        DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
        DEFINE KEYPAD_ROW_PORT   PORTB    ' ROW port = PORTB
        DEFINE KEYPAD_ROW_BIT    4        ' ROW0 = PORTB.4
        DEFINE KEYPAD_COL        4        ' 4 COL keypad
        DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
        DEFINE KEYPAD_COL_BIT    0        ' COL0 = PORTB.0
        DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
        DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature
When using the auto-repeat feature, the delay is the debounce delay (DEBOUNCEMS)

Code example #2: Using a 8X4 keypad
Code:
    INCLUDE "KeyPad.bas"         

    '                      
    '    Hardware connection
    '    ===================
    DEFINE KEYPAD_ROW        8       ' 8 row 
    define KEYPAD_ROW_PORT   PORTB   '   on PORTB
    DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
    DEFINE KEYPAD_COL        4       ' 4 col 
    DEFINE KEYPAD_COL_PORT   PORTA   '   on PORTA
    DEFINE KEYPAD_COL_BIT    0       '      <3:0>
    DEFINE KEYPAD_DEBOUNCEMS 200     ' debounce delay = 200 mSec
    define KEYPAD_AUTOREPEAT 1       ' use auto-repeat
    
    '
    '    Serial Communication definition
    '    ===============================
    DEFINE HSER_TXSTA 24h            ' enable transmit, BRGH=1
    DEFINE HSER_SPBRG 129            ' 9600 Bauds

    '   
    '    Variables definition 
    '    ===================
    myvar                    var byte

    '    ---------------------------------[Program Start]----------------------------------------------
start:
    @ READKEYPAD _myvar
    hserout ["Key=",dec myvar,13,10]
    goto start
It set the according TRIS register for you everytime you call the MACRO.. kinda bullet-proof

Everything is explain in the attach file... don't forget to rename it