Matrix Keypad routine


Closed Thread
Page 1 of 4 1234 LastLast
Results 1 to 40 of 135
  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 04: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 02:37.

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


    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 12: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

    Default Code problem

    Hello,

    That version of PBP is using?.

    Leonard



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

  14. #14


    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

  15. #15
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,619


    Did you find this post helpful? Yes | No

    Default ????????????????????????????,

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

    Sorry, Leonardo

    I do not understand anything in your sentence ... try to be a bit more explicit.

    I opened Twice "keypad.bas" ... it compiles also ...

    may also be Too many files opened ???

    Alain
    Last edited by Acetronics2; - 26th June 2006 at 15:21.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    i use PBP V2.46 but it should work with most previous one. MPASM version shouldn't be much of a problem.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=938&stc=1&d=1151334864 ">

    Be sure the INCLUDE file is in the same directory of your project and it should compile as is. Unless add the path in the INCLUDE line.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=939&stc=1&d=1151335131 ">
    Attached Images Attached Images   
    Last edited by mister_e; - 26th June 2006 at 17:19.
    Steve

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

  17. #17
    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

  18. #18
    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  

  19. #19
    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?

  20. #20
    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.

  21. #21
    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

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


    Did you find this post helpful? Yes | No

    Default

    seems you forgot to add external pull-ups....

    i don't know wich pic you are using but try

    OPTION_REG.7=0
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    i use 16f628a with pull-ups ..... for test

    in circuit row and col have voltage around 0,5 to 3,5v (oscillating ... i don't know why)

    than i press one button, 2 pins have 0,0v

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


    Did you find this post helpful? Yes | No

    Default

    Hi. While testing Steve's routine, I get many fatal errors. The attached Screen Capture gives the state. Steve if you can have a look...

    Includes are OK about names and paths.

    Ioannis
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Ioannis,
    You have to compile with MPASM, not PM.

    mpardinho,
    You probably miswired something. with your exact program it works fine here. Also.. there's no PORTC on PIC16F628 but you should already know that.

    i used this line for my config fuses
    Code:
    @   __CONFIG  _INTRC_OSC_NOCLKOUT & _MCLRE_OFF  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_ON
    Did you tried with OPTION_REG.7=0 without resistor?

    wich value of pull-up?
    Steve

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

  26. #26
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Ioannis,
    You have to compile with MPASM, not PM.
    Ohh! dear....

    Thanks,
    Ioannis

  27. #27
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Mpasm > Pm

    Hello Steve,

    Any idea in getting your code to work (compile) with PM. ?

    That would be a big help.

    thank you for the shareing the code.

    regards

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


    Did you find this post helpful? Yes | No

    Default

    Nope, i have no idea and no plan to do it.

    I NEVER use PM, it really don't worth to use it anyways... sorry
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    I know of NO reason why anyone should still be using PM.

    If you don't use ASM then it'll handle PBP just fine. But if you do use ASM, PM will cause nothing but problems. I never use it anymore either.

    However, before I found out how much better MPASM is, I used PM for a year or 2, and am probably more familiar with it than Steve.

    So here's Steve's Kepad.bas, modified to work with PM.exe

    This version will NOT work with MPASM

    Don't forget to remove the .txt extension.

    HTH,
    Attached Files Attached Files
    DT

  30. #30
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Smile

    Looks good Steve. Worth a vote *****

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


    Did you find this post helpful? Yes | No

    Default

    i has the advantages to be 'user configurable' and support many matrix Keypad type... up to 8X8.

    Can be used in a Timer interrupt as well, so you can read from it when you want, etc etc.

    Enjoy!
    Steve

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

  32. #32
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    It looks quite comprehensive.

    I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.

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


    Did you find this post helpful? Yes | No

    Default

    If that was true... ASM additions, substraction, bit shifting functions and few STATUS register bits wouldn't exist...(carry/Borrow, Z)
    Last edited by mister_e; - 13th May 2007 at 00:35.
    Steve

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

  34. #34
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I know of NO reason why anyone should still be using PM.

    If you don't use ASM then it'll handle PBP just fine. But if you do use ASM, PM will cause nothing but problems. I never use it anymore either.

    However, before I found out how much better MPASM is, I used PM for a year or 2, and am probably more familiar with it than Steve.

    So here's Steve's Kepad.bas, modified to work with PM.exe

    This version will NOT work with MPASM

    Don't forget to remove the .txt extension.

    HTH,
    Thanks Darrel.

    Unfortunately I still use PM and maybe I am facing all problems because of that. I shall shift over to MPASM and see the difference.

    Today my biggest problem is to get a 16F628A to sleep and wake it on INT on Change B4...B7. This is in conjuction with a keypad rotuine I am working on for a keylock project.

    I think I must change over and see (experience) the difference myself

    Thank you steve for this wonderful thread.

    regards

  35. #35
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post On Par?

    Quote Originally Posted by mister_e View Post
    If that was true... ASM additions, substraction, bit shifting functions and few STATUS register bits wouldn't exist...(carry/Borrow, Z)
    So, you believe that a PIC performs on par with: A = (100 / I) + (J * 2) Vs IF B = 1 THEN A = 120 ?
    Huge amount of work for the PIC to do something like this: A = (100 / I) + (J * 2)
    100 x the num of clock cycles perhaps?
    Last edited by T.Jackson; - 13th May 2007 at 07:47.

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


    Did you find this post helpful? Yes | No

    Default

    Trent, If your example was right i could agree with some part of it... programming method and code optimization is an endless story... i'm not going to argument on which is better, which is worst... it's not what the actual thread is about anyway.

    100X ??? NAH, i don't think so. Depending the Value of I, few times maybe... but not 100 for sure. and * 2, is just a Byte shifting, one position to the left... not much... 1-2 cycle not much.
    -----------------------------

    Charudatt,
    before going in sleep mode, make sure those PINs are set to input (with pull-up) and the others are set LOW and OUTPUT (or input but with pull-down resistor). Once you'll press a key, RB<7:4> should see the LOW signal... which should wake your PIC, then you call the keypad scan.
    Last edited by mister_e; - 13th May 2007 at 10:11.
    Steve

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

  37. #37
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    I tend to base most of my algorithms around direct logic - boolean algebraic structures - rather than continuous mathematics, i.e calculations. PIC's are not as well equipped for calculations.
    Huh? Lookups have their place (and I love them when needed) but to say PICs are not equipped for calculations is just plain silly.

    For all your projects (that you have posted), was time of the issue or code space? (answer = the latter). With your example equation, which one takes less code space? Which one is faster for larger I? (answer = calculation based approach).

    Code:
    ' Calculation based equation A = 100/I +J*2
    If I > 100 then
    A = J<<1
    ELSE
    A = 100
    FOR X = 1 to 100
    A = A – I
    IF A < I then OUT
    NEXT X
    OUT:
    A = X+ J<<1
    ENDIF
    or
    Code:
    ' lookup based equation A = 100/I +J*2
    IF I = 1 then A = 100+J<<1
    If I = 2 then A = 50 +J<<1
    If I = 3 then A = 33+J<<1
    If I = 4 then A = 25+J<<1
    ...
    ' (a bunch more  if-thens)
    ...
    if I =100 then A = 1+J<<1
    If I > 100 then A = J<<1
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  38. #38
    Join Date
    May 2007
    Location
    Harvest, Alabama
    Posts
    10


    Did you find this post helpful? Yes | No

    Default Pull Up Resistors

    I know the Pull up Resistor attaches to Vss but where does it go else wise? Also... What happens to other test programs etc by its presence?

    Paul

  39. #39
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980


    Did you find this post helpful? Yes | No

    Default

    To port B.

    As for the programs, what programs? Depends on what are the programs doing... Usually the port B with PU enabled, reads as all 1s.

    Ioannis

  40. #40
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Smile Don't twist my words...

    Quote Originally Posted by paul borgmeier View Post
    Huh? Lookups have their place (and I love them when needed) but to say PICs are not equipped for calculations is just plain silly.
    I didn't say not equipped - I said not as well equipped. And, I'm more so referring to something that's more so "hard coded" over calculations. When I say hard coded I'm talking about something that's direct as in (a = 100) Vs (a = b x 10 / 2) No prizes for guessing which is faster and uses less resource.
    Last edited by T.Jackson; - 23rd May 2007 at 10:28.

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, 23:58
  2. Need help in matrix keypad coding
    By rano_zen06 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 24th May 2008, 14:16
  3. I2C PCF8574 4X4 Keypad routine
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2007, 22:25
  4. Inconsistent output on a 4x4 matrix keypad
    By markcadcam in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 24th November 2006, 04:54
  5. very basic matrix keypad question
    By kitcat in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 8th July 2006, 22: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