Matrix Keypad routine


Closed Thread
Results 1 to 40 of 135

Hybrid View

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

    Default Matrix Keypad routine

    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
    Attached Files Attached Files
    Last edited by mister_e; - 7th February 2006 at 03:24.
    Steve

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

  2. #2
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Default Row / col resistor Values

    Hi Steve,

    What value do you use for the Pull Up resistors?

    What value do you use for the series resistors?

    Cheers
    J

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


    Did you find this post helpful? Yes | No

    Default

    Could be almost everything but usually i use 10K as pull-up, serie resistor could be remove but usualy 100-300 ohm is perfect.
    Steve

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

  4. #4
    Join Date
    Jul 2004
    Location
    CA
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,

    With the code that you have posted, Will this be able to recognize if the user presses more than one button at a time, or is it limited to only one button pushed at a time. If the later is true, then how can I implement a 4x4 matrix so that it allows multiple button pressed at one time .


    Srig

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


    Did you find this post helpful? Yes | No

    Default

    Hi Srig!

    Long time we didn't heard from you

    I do remember you asked that question awhile back but, sorry, only one button at the time for that one.

    But as pushing two button exacty at the same time is an impossible human thing, we can modify the actual one and add some feature to. It will have to check once a button is press, wait few ms, set a flag, then RESCAN the whole keyboard and see if things changed. Not impossible.

    I'll check what i can do with it somewhere next week. I have some project for some user here (those who pay for ) and i promise to deliver by the end of this weekend... Mister_E rule#1 : always respect delay even if i must stop to sleep, avoid beer and ladies.

    Sure i'll have an eye on it next week. See ya!
    Steve

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

  6. #6


    Did you find this post helpful? Yes | No

    Talking Problem code

    Serious very good to publish an example with this code that is very interesting, when trying to compile the code "KeyPad.txt" it generates an error.

    Greetings

    Leonard


    Quote Originally Posted by mister_e
    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

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


    Did you find this post helpful? Yes | No

    Default

    yeah.. read the last lines of my post...
    ... don't forget to rename it
    so the .txt have to be renamed .bas

    once it's done, i can't imagine it's not working. If so, let me know here!
    Steve

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

  8. #8


    Did you find this post helpful? Yes | No

    Talking Problem code

    Hello,

    It already renames it but it is not allowed to compile because it shows an error, try to compile you the code "KeyPad.txt to KeyPad.bas" and that doesn't work.

    Thank you
    -------------------------------------------------------------------

    Quote Originally Posted by mister_e
    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

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


    Did you find this post helpful? Yes | No

    Default

    what are/is the error(s) message you get?
    Steve

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

  10. #10


    Did you find this post helpful? Yes | No

    Talking Error code

    Hello Mister E,

    I attach him the image of the error that generates when trying to compile, I have attempted it with several pics but with none it is allowed to compile.

    Greetings

    Leonard

    Quote Originally Posted by mister_e
    what are/is the error(s) message you get?
    Attached Images Attached Images  
    Last edited by Leonardo; - 25th June 2006 at 01:37.

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink Da vinci code ....once more ???

    Hi, Leonardo

    Just copiying and pasting Steve's code gives ( lower left ) the following message :

    SUCCESS - 366 WORDS USED

    So, I think the problem is in your computer ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    probable cause.. there's 2 KeyPad.bas files opened in your editor as per your picture. It must be a MCS error... this 'feature' is not available in the MCSP version as i can't do it here... sorry.
    Last edited by mister_e; - 25th June 2006 at 11:35.
    Steve

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

  13. #13


    Did you find this post helpful? Yes | No

    Talking Code problem

    Hello Acetronis,

    It can place an image of the code when it compiles it, the truth not you that to make since has the it finishes version of the PBP.

    Greetings


    Quote Originally Posted by Acetronics
    Hi, Leonardo

    Just copiying and pasting Steve's code gives ( lower left ) the following message :

    SUCCESS - 366 WORDS USED

    So, I think the problem is in your computer ...

    Alain

  14. #14
    np123's Avatar
    np123 Guest


    Did you find this post helpful? Yes | No

    Default Input via Matrix Keypad and Output onto LCD

    I am new to PIC programming,, have been fiddling with BLINK.Bas
    and managed to make the LCD show a message "LED Blinking"
    just before the LED blinks.

    I am using the MCS PICBasic Pro for the sake of compiling and am using the
    DIY K149 Pic Micro Programmer to program my PIC16F877A.

    Now I was wondering how would I be able to use the Keypad as an input
    and display things on the LCD.

    I am sure my question is very newbie, but if someone could explain me
    how I could manage my inputs and storing into registers and then output
    it to whatever port pin etc., then it would be of great help.

    Thank you!
    Attached Files Attached Files

  15. #15
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Thanks

    Hello Mister E
    Great works for newbie, Thanks again.

    I config. keypad on portd of 877a, becoz portb is allready config on my dev. board V3(metrixmultimedia) for LCD rutine.

    its working fine for me.


    INCLUDE "KeyPad.bas"
    INCLUDE "MYLCD.BAS"
    myvar var byte

    start:
    @ READKEYPAD _myvar
    lcdout $fe,1
    lcdout " Key Value = ",DEC2 myvar
    goto start



    Thanks
    Attached Images Attached Images  

  16. #16
    Join Date
    Sep 2006
    Location
    Venezuela - Caracas
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    the file keypad.txt not download ... error in forum server

    need the file to text my keypad code

    can i help me?

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


    Did you find this post helpful? Yes | No

    Default

    seems to be a server problem since this morning (october 18/2006)

    drop me your e-mail address on my PM.
    Steve

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

  18. #18
    Join Date
    Sep 2006
    Location
    Venezuela - Caracas
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    keypad complied 100%,
    but in terminal i receive many keys without press any key

    my test:

    Code:
    Include "modedefs.bas"
    INCLUDE "KeyPad.bas"  
    
    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        3        ' 3 COL keypad
    DEFINE KEYPAD_COL_PORT   PORTB    ' COL port = PORTB
    DEFINE KEYPAD_COL_BIT    1        ' COL0 = PORTB.1
    DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
    DEFINE KEYPAD_AUTOREPEAT 0        ' use auto-repeat feature 
    
    Serial_Saida       Var     PORTC.2           'Pic 13  - >  Max232   10       
    myvar                    var byte
    
    Inicio:
        @ READKEYPAD _myvar
        Serout Serial_Saida, T2400, [#myvar, 13, 10] 
    goto Inicio

    Terrminal:

    Code:
    Received: 15
    Received: 15
    Received: 1
    Received: 3
    Received: 15
    Received: 15
    Received: 3
    Received: 2
    Received: 3
    ...... withou press any key

  19. #19


    Did you find this post helpful? Yes | No

    Default problem with serout and keypad routin Mister_E

    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

  20. #20
    da_cure_4_u's Avatar
    da_cure_4_u Guest


    Did you find this post helpful? Yes | No

    Default Scan

    I would like to scan a 4x4 keypad to use as a calculator on PIC16F88.

    anyone can help please???

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


    Did you find this post helpful? Yes | No

    Default

    Try something by yourself first.
    1. Download the Keypad Include file,
    2. Find LCDOUT in your manual,
    3. Use the example I gave in POST #1 and you're almost half done if you replace HSEROUT with LCDOUT.
    Steve

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

  22. #22


    Did you find this post helpful? Yes | No

    Default 4x4 keypad on an 184520 - newbie help

    Hi all

    Please would somebody be so kind as to shed some light on the problem I am experiencing.

    I am busy re-kindling my hobby and interest in PIC programming, I think these forums are an excellent resource, somehow all roads lead back here after many a google search and reading post after post and numerous articles.
    After 3 weeks of late nights and sore eyes and a lot of reading later I have finally gotten to a stage where I have a functional (perhaps a very under-utilized PIC 18F4530).
    After having blinked LED's and read switches and getting my LCD working I would like to implement a keypad as opposed to a bank of dip switches.

    I am trying to implement the keypad.bas file submitted by mister_e (Thanks mister e ... your code looks fantastic, I'm dying to use it properly :-)

    So here's where I'm at now....

    I am trying to connect a 4 x 4 matrix keypad to my 18F4520 PIC.

    Ultimately I would like to be able to be able to type in a number, end it with a # to signify completed input and then transmit the inputted number to another pic either wired or wireless.

    The keypad layout is as follows.
    my keypad matrix

    1 2 3 A
    4 5 6 B
    7 8 9 C
    * 0 # D


    I have connected the keypad to the pic as follows.

    Keypad PIC

    Column 0 PortA.0
    Column 0 PortA.1
    Column 0 PortA.2
    Column 0 PortA.
    Row 0 PortC.0
    Row 1 PortC.1
    Row 2 PortC.2
    Row 3 PortC.3

    10K pullups set on column inputs
    100 Ohm resistors in series with rows

    When I have the above configured my LCD just produces blocks

    If I remove either the pullups and/or the series resistors I just get "Key Value" 20 continuously appearing on the LCD and if I press a key on the keypad I get the "key Value" changing on the LCD but it is not the correct value according to my keypad.

    I could also use the whole of Port A but when I tried it but had the same results :-(

    Initially I tried to connect on PortB and had the same results, so I assumed it was because I was getting inputs from pin 39 and pin 40 of the pic where the PICkit 2 is connected for ICSP.

    I have attached my code below.

    Please could someone advise as to where I am going wrong or what I could look at to fix the problem !

    I think it could be a possible CONFIG problem or coding issue in my code.

    Any help would be greatly appreciated.

    Kind regards

    Dennis

    Code:
    '*************************************
    'LCD code for 16 X 2  HD4x lcd
    '*************************************
    
    'Ocsillator selections here
    OSCCON = $70            'Int CLK 8MHz
    OSCTUNE.6 = 1           'PLL 4x
    ADCON1= %00001111       '$0F = disable A/D converter
    'END of oscillator selections
    
    
    'Port IO directions and presets for port pins begin here
    'TRISA = %11111111       'All pins are outputs
    TRISA.0 = 1
    TRISA.1 = 1
    TRISA.2 = 1
    TRISA.3 = 1
    TRISB = %00000000           
    'TRISC = %00000000
    TRISC.0 = 1           
    TRISC.1 = 1
    TRISC.2 = 1
    TRISC.3 = 1
    
    TRISD = %00000000
    TRISE.0 = 0
    TRISE.1 = 0
    TRISE.2 = 0
    'End of Port IO directions and presets for port pins begin here
    
    'timer/oscillator defines 
    DEFINE OSC 32            '4x 8MHz
    'END of timer/oscillator defines
                          
    'variables begin here
    myvar var byte
    
    'LCD defines begin here   
    DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
    DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
    DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
    DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
    DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
    DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
    DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
    DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
    DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
    DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
    DEFINE LCD_DATAUS 200 		'delay in micro seconds
    'END of LCD DEFINES
    
    'KEYPAD 4x4 defines begin here
          DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
          DEFINE KEYPAD_ROW_PORT   PORTC    ' ROW port = PORTB
          DEFINE KEYPAD_ROW_BIT    0        ' ROW0 = PORTB.4
          DEFINE KEYPAD_COL        4        ' 4 COL keypad
          DEFINE KEYPAD_COL_PORT   PORTA    ' 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  
    'End of KEYPAD defines
    
    '*********************Includes******
    
    include "C:\PBP\SAMPLES\KeyPad.bas"
    'Includes end here
    
    'Code begins here
       Pause 500       ' Wait for LCD to startup
     
    start:
    @ READKEYPAD _myvar
    lcdout $fe, 1
    lcdout " Key Value = ",DEC2 myvar
    goto start

  23. #23


    Did you find this post helpful? Yes | No

    Default Solved !!

    My problem in the previous post here is now solved.
    The keypad is working.

    But I now am trying to solve 2 more problems

    1. I need the keypresses to reflect the correct label
    My matrix is
    1 2 3 A
    4 5 6 B
    7 8 9 C
    * 0 # D

    At the moment I get the following 1,2,3,4 as opposed to 1,2,3,A

    2. I would like to capture a number of keystrokes as I type them in for example 135 completing input with a #
    So the number stored will be the number decimal 135

    Any help or suggestions will be most appreciated.

    Kind regards

    Dennis
    For example keypress1

  24. #24
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,803


    Did you find this post helpful? Yes | No

    Default

    An idea would be to use the lookup command for your translation from numbers to numbers-ASCII conversion.

    Now about the numbers to assebly in a byte. What is the range of your input?

    0-255 or 0-999?

    Ioannis

Similar Threads

  1. calculator-like code entry with matrix keypad and display
    By Dennis in forum mel PIC BASIC Pro
    Replies: 35
    Last Post: - 16th December 2009, 22:58
  2. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 13:16
  3. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 21:25
  4. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 03:54
  5. very basic matrix keypad question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th July 2006, 21:33

Members who have read this thread : 3

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