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- Keypad ROW are connected to PORTB<3:0>
- Keypad COL are connected to PORTB<7:4>
- Debounce delay = 200 mSec
- No auto-repeat
- 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  
				
			
Bookmarks