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


    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 09:11.
    Steve

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

  2. #2
    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
    __________________

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

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,821


    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

  5. #5
    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 09:28.

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    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.
    If a is hard coded to equal 100, then I would guess b and c would be hard coded too. If I understand you correctly this is what the PIC a good for. If this was all I had to do I good do it on paper once and would not have to bother with all of this programing and such. In my world variables change.

    In you opinion, what should we all be using?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Post

    (b & c) are variables that will only be hard coded if assigned with a fixed value. In Discrete mathematics, if we were to say, a(x) means something - then this is effectively a predicate since the variable x can take on many different forms. On the other hand, if we say A = 100 and it's a "real number", it is said to be a proposition because there is obvious truth in it. Clearly 100 is a real number.

    In you opinion, what should we all be using?
    Short answer is, in my opinion - use whatever works best for you. Focus on your strengths and if it gets the job done, call it a day
    Last edited by T.Jackson; - 23rd May 2007 at 13:46.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    (b & c) are variables that will only be hard coded if assigned with a fixed value. In Discrete mathematics, if we were to say, a(x) means something - then this is effectively a predicate since the variable x can take on many different forms. On the other hand, if we say A = 100 and it's a "real number", it is said to be a proposition because there is obvious truth in it. Clearly 100 is a real number.


    Short answer is, in my opinion - use whatever works best for you. Focus on your strengths and if it gets the job done, call it a day
    I was being sarcastic.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Post

    I think what I'm really trying to say here is that, if we want (a) to equal 100, and we can predict this value, then why use a formula? (It's unnecessary maths)

    Code:
    Public Function DrawLCD()
       '-----------------------------------------------------------------------------
       '// 2 Line 16 LCD_Chrs 5x7 matrix                                            '
       '-----------------------------------------------------------------------------
       Dim i As Long 'General working var for nested loops
       Dim j As Long '^
       Dim k As Long '^
       Dim f As Long '^
       Dim e As Long '^
       Dim h As Long '^
       
       '// Draw display matrix with all segs off    '
       For LCD_Row = 0 To 1                         '2 lines
           For LCD_Chrs = 0 To 15                   '16 chrs per line
               For f = 0 To 7                       'Matrix row
                   For k = 0 To 4                   'Matrix col
                       For j = 0 To Draw_Scale - 1  'Ea seg is (dscale x dscale) pixels
                           For i = 0 To Draw_Scale - 1 '^
                               SetPixelV LCD.hdc, 2 + i + k * (Draw_Scale + 1) + (LCD_Chrs * Draw_Scale * 6) + (LCD_Chrs * 4), 3 + j + (f * (Draw_Scale + 1)) + (LCD_Row * Draw_Scale * 9) + LCD_Row * 7, vbGreen
                           Next
                       Next
                   Next
               Next
           Next
       Next
    I'm forced into using calculations with the above code because we can't easily predict the values of the variables without making things even more complex than they already are. So there's plenty of valid reasoning behind this predicate arrangement. But if we can predict what we want, and it's feasible to do so, why not hard code it???
    <hr/>
    Last edited by T.Jackson; - 23rd May 2007 at 14:57.

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


    Did you find this post helpful? Yes | No

    Unhappy Pullup resistors

    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?) I really want to trigger the circuit with a minimum of time so I want the pullup fast so that my transistors (Nice NPN's for switching) with about 4.7 K ohms lead in resistance trigger off pretty much as fast as any current comes on the pin to signal it.

    I will be pushing a signal in the switch of the NPN transistor so that there is some current to pull a MOSFET fast. I need some current to move like NOW.

    In any case since I just cooked a $15 chip and an X1 Board , I really want to know some answers. (I just burned up some money) I need to know what voltage appears on the pins of the chip when we set for example a PORTA.2 =1. or PORTA.2 = 0 Is it on PORTA.1 = 1 a positive or negative voltage. It was logic testing that cooked this equipment.

    All advice will be appreciated.

    Well I got a cross of a posting that occurred between my post and an answer.

    The issue of Pullups seems to be a feature of the pin to cause it to draw some current to make it pull down a few thousandths of an ampere so that the circuit stays logic stable. I would think that if I am driving a transistor as I am the obvious value to use is about 10K because the transistor will have a 4.7 K or so leading out of the logic pin into the transistor Emitter. Or does this 4.7 to Vss draw down enough power so that the transistor needs no other resistor on the emitter?

    Generally a 5 VDC to emitter of a switching transistor with logic state high would take a 4.7 K ohm in the way of the signal feeding into the emitter (P of the NPN). If you take a 5 VDC state with a 10 K ohm to Vss and the positive voltage on the pins as high logic state then a 4.7 to the emitter should keep enough current to the transistor to open the gate so I am guessing based upon the previous answer that a 10 K ohm is in order (???)

    When we change from an input drain state as in the keyboard to an output control state, I would suspect that we add a current to bring the pin near switch on state but just below in order to logically control things, Is this so?


    Thanks
    Last edited by CluckShot; - 18th June 2007 at 00:52. Reason: cross posting

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


    Did you find this post helpful? Yes | No

    Default

    For Switchs, Keypad the Pull-up value is not really important. 10K is common, that's what i use. They can be higher... but i stick with 10K.

    For switches and Keypad, yes you could use the internal one without having too much problem.

    If you don't use any, this will cause you some problem as the internal gate don't see a logic level... it will see noise, so it will react weird. It has nothing to do with the Output driver, as the pin is set as Input. And BTW, if you enable ALL internal pull-up, they will be disabled on all Output configured I/O.

    <hr>PORTA.x = 1 = 5Volt
    PORTA.x = 0 = 0Volt<hr>

    To drive a transistor (NPN/PNP) you need a resistor in serie with the base, unless you will burn the I/O. Roughly, if you don't insert a resistor in serie with the transistor base, the i/O will see only a diode, as there's no current limiting resistor the current will be infinite. I=E/R, I=Vdd/0 hence some obvious damage to the PIC which can't provide more than 25mA by I/O, and x/PORT.

    The base resistor will have to be calculated. But you need to know how much current your transistor will drive and the transistor Hfe. The base resistor have to be higher than Vdd/25mA to avoid burning the I/O and few time lower than the calculated one to ensure proper switching.

    rb=Vdd-0.7/(Ic/Hfetyp)

    HTH
    Last edited by mister_e; - 18th June 2007 at 01:17.
    Steve

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

  12. #12
    Join Date
    May 2007
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Steve

    Does the same apply to driving a n-channel power mosfet?
    I would like to drive a IRFP250N n-channel mosfet.
    (for this mosfet the static drain-to-source on-resistance Rds(on)=0.075ohm,
    drain-to-source leakage current Idss = 25-250uA)
    Do I also need a resistor inbetween the mosfet and the output pin?
    If so, should I use the same calc as above to determine the ohm value of the resistor?

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


    Did you find this post helpful? Yes | No

    Default

    in theory, you don't need any resistor in between as the gate impedance and their gain(not the right term but.. ) is quite large . BUT if you worry of a Gate to Source short, or else weird stuff, you should use a resistor in serie to 'protect' the PIC.
    Steve

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

  14. #14
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CluckShot View Post
    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?)
    I was taught, back in the "old days", to figure for about 1 ma to flow in the pullup (or, when needed, pulldown). Thus for 5-volt TTL, 4.7K; for 12-volt CMOS logic, 10K. I still use these values without thinking, and everything still works.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  15. #15
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CluckShot View Post
    How do we determine what the pullup should be? I mean 100 to 300 ohms or 10 K ohms doesn't exactly give me the data I need. (Does it vary with the circuit being driven for example?)
    I was taught, back in the "old days", to figure for about 1 ma to flow in the pullup (or, when needed, pulldown). Thus for 5-volt TTL, 4.7K; for 12-volt CMOS logic, 10K. I still use these values without thinking, and everything still works.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

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


    Did you find this post helpful? Yes | No

    Default

    I think that's for a standard 10 TTL loads.

    But a PIC pin is only 1 load. So you can be fine with 40K, which is somewhere around the range of the internal weak pull-ups.
    <br>
    DT

  17. #17
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I think that's for a standard 10 TTL loads.

    But a PIC pin is only 1 load. So you can be fine with 40K, which is somewhere around the range of the internal weak pull-ups.
    <br>
    I'm sure you're correct, Darrel. As I wrote, that was a long time ago. My feeble point was, I still automatically use that thumb rule and those values and the circuits still work. (Probably kind of like driving a tack with a sledgehammer . . . )
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  18. #18


    Did you find this post helpful? Yes | No

    Default Optional timeout keyboard routine

    Hi MisterE

    Using with succes your keypadroutine on a 4x2 keypad

    I was wondering if it would be possible to jump out the keypadroutine if no key is pressed
    in order to handle the main loop

    I need to receive some serial commands by HSERIN, but when a key is pressed
    it should go to a label and then return to the main loop checking Hserin

    Now it waits for a keypress

    Thanks

  19. #19
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Wink thanks guys

    T. Jackson & Mr. E,

    Nice work to both of you regarding Matrix Keypads!

    I have used Trents example with great success, I plan on trying out Mr. E's with a handheld Wireless panel/LCD I put together for work. I want to add a 4x4 matrix keypad to the front of the reciever case and upgrade my TXM/RSM LR LINX modules to the new LT tranciever type. I really think having the matrix keypad will expand (the crap out of) the types of commands I can send.....wall mounted reciever, robot, whatever....
    Attached Images Attached Images  
    Padawan-78

  20. #20
    Join Date
    Jan 2007
    Location
    Houston, TX
    Posts
    96


    Did you find this post helpful? Yes | No

    Red face

    Hello,
    Just an hour ago I tried to include Mr. E's Keypad.bas file in pbp folder and my local "pic_programs" folder. I DID rename the txt file and saved it to .BAS file.
    Here is the code....
    Code:
    INCLUDE "KeyPad.bas"         
    myvar var byte
    
    
    start:
        @ READKEYPAD _myvar
        hserout ["Key=",dec myvar,13,10]
        'LCDOUT 254,ROW1,"COMMAND", DEC MYVAR
        goto start
    Won't compile....
    I keep getting lots of "opcode expected instead of....'kb_row','kb_col', 'debounce_delay' " errors. I did read the thread about the errors found when you don't save as a .BAS file but I must not be seeing something obvious, happens to me alot on this forum.

    Mr. E could you lend a hand,

    I am using version 2.50A & PM assembler
    Padawan-78

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


    Did you find this post helpful? Yes | No

    Default

    With Steve's version, you have to use MPASM.

    For PM, use the version I recently uploaded to Post#82

    hth,
    DT

  22. #22
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Hi Guys ,

    Well this keyboard matrix routine has been here a while and works well.

    but if you need to place a 1 row or column port pin on another port out of sequence then you have a problem.

    I face this as i changed from 16f1947 to 18f67k22 on the pcb , where the 16f1947 has portF.0 , and 18f67k22 does not
    as you guessed a row pin was on Portf.0

    PORTF.0 -3 was row ,portb 0-3 was column , so no problem with the column port , but row0 wont work on an non existent port
    so the new row0 port was connected to a spare pin at portG.4

    PortG.4 TRES direction was set to output prior to keypad.bas include used , but could have been set in in the keypad.bas section of code after the asm that sets the TRES for the colume and row ports assigned


    I used the port offset value to point portG.4 , when it was selecting row0 , and set the POrtG.4 =1 prior as per steves comments
    the offset value 12 is worked out 12 port locations past portF0

    i also did not care if portF.0 TRES were set to output as per steves routine , but if this was an issue , removing the ASM code that sets the TRES in keypad.bas and do it as per normal would have been ok


    I hope this helps someone that has a similar problem

    cheers

    Sheldon

    Code section prior to change
    =====================

    Code:
    ScanKeypad:
            key=0                                              ; no key is press
            row=0                                              ; begin scan @ ROW0
            col=0                                              ; and COL0
                   
            kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
            repeat                                             
                
              
                  ROWBIT=ROW+KB_ROW_BIT                    ; point to a ROW bit
                  kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit
    after code change
    ==============

    Code:
    ScanKeypad:
            key=0                                              ; no key is press
            row=0                                              ; begin scan @ ROW0
            col=0                                              ; and COL0
            PORTG.4 = 1                                        ; Setup row-0 = 1 
            
            kb_row_PORT=kb_row_PORT | InitialState             ; set all ROW bits to 1 using bitwise OR
            repeat                                             
                
                if row = 0  then 
                   Rowbit = 12                                 ; offset amount for row 0  from PortF.0 to point to PortG.4 
                 else  
                  ROWBIT=ROW+KB_ROW_BIT                        ; point to a ROW bit
                endif   
                  kb_row_PORT.0[RowBit]=0                      ; clear actual ROW bit

  23. #23
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Exclamation Need help desperately!!!

    I'm doing a temperature control system. Pretty new to PIC programming. I have managed to display temperature on the LCD using an LM35 sensor and a 16 x 2 lcd with a 16F873. I want to add on a 4 x4 matrix keypad so that i can set setpoints to switch a relay and a low warning buzzer I have no idea how to program for the above mentioned add-ons. Please could someone help me. below is my code which will obviously need additions and a scematic of my circuit is attached . Please could somebody help me with this!!

    ' Define LCD registers and bits

    Define LCD_DREG PORTB
    Define LCD_DBIT 0
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 5
    Define LCD_EREG PORTB
    Define LCD_EBIT 4
    dEFINE LCD_BITS 4
    DEFINE LCD_LINES 2

    adval var word ' Create adval to store result
    temp var word ' Create temp to store result
    temp1 var word ' Create temp1 to store result

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %11000001 ' Configure and turn on A/D Module
    Pause 100 ' Wait 0.1 second


    loop: ADCON0.2 = 1 ' Start Conversion

    AGAIN: Pause 1
    If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished

    adval.highbyte = ADRESH ' Move HIGH byte of result to adval
    adval.lowbyte = ADRESL ' Move LOW byte of result to adval

    Lcdout $fe, 1 ' Clear screen
    temp=50*adval ' Conversion to Degrees
    temp=temp/100
    Lcdout "TEMP = ",DEC temp,$DF,"C" ' Display the value of temp
    temp1 = temp*18 ' Conversion to Fahrenheit
    temp1 = temp1+320
    temp1 = temp1/10
    lcdout $FE,$C0, "TEMP = ",dec temp1,$DF,"F" ' Display the value of temp
    Pause 1000 ' Wait 1 second

    Goto loop ' Do it forever
    End
    Attached Images Attached Images  

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    I'm doing a temperature control system. Pretty new to PIC programming. I have managed to display temperature on the LCD using an LM35 sensor and a 16 x 2 lcd with a 16F873. I want to add on a 4 x4 matrix keypad so that i can set setpoints to switch a relay and a low warning buzzer I have no idea how to program for the above mentioned add-ons. Please could someone help me. below is my code which will obviously need additions and a scematic of my circuit is attached . Please could somebody help me with this!!
    Schematic for keypad connection to a PIC is talked about at the beginning of this thread. If you need a schematic, draw it up... Shouldn't be that difficult at all...dontcha think?

    As far as the code goes, you've gotten this far (or have you? Ctrl-C/Ctrl-V)...
    Why not write some code, doesn't even have to be real code, just talk yourself thru it, and type it out as you talk. After you see it written down, you just might be able to write the code yourself.

  25. #25
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Question

    i have written this code. its just that im really confused and lost as to how to begin with the keypad. i kinda figured out how to hook up the keypad though. i just need help as to how to go about doing the code

  26. #26
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    i have written this code. its just that im really confused and lost as to how to begin with the keypad. i kinda figured out how to hook up the keypad though. i just need help as to how to go about doing the code
    I am HELPING. No need for whiney PM's.
    Key word here is HELPING...not DOING.
    I think you'll find a whole lot of people around here willing to HELP...some might even be willing to DO.
    Write some code, in fact, don't even write code, just write a sequence of thoughts of how you think the program should operate. The code will follow. That's how it works. You think about something and it happens eventually.
    As far as your keypad goes, what's wrong with the code that's provided earlier in the thread? I use it...works great for me.

  27. #27


    Did you find this post helpful? Yes | No

    Default

    Well the answeris in mister E's code, it works very well give it a true it is very well documented and easy to use

    Walter


    Quote Originally Posted by Kalind View Post
    I'm doing a temperature control system. Pretty new to PIC programming. I have managed to display temperature on the LCD using an LM35 sensor and a 16 x 2 lcd with a 16F873. I want to add on a 4 x4 matrix keypad so that i can set setpoints to switch a relay and a low warning buzzer I have no idea how to program for the above mentioned add-ons. Please could someone help me. below is my code which will obviously need additions and a scematic of my circuit is attached . Please could somebody help me with this!!

    ' Define LCD registers and bits

    Define LCD_DREG PORTB
    Define LCD_DBIT 0
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 5
    Define LCD_EREG PORTB
    Define LCD_EBIT 4
    dEFINE LCD_BITS 4
    DEFINE LCD_LINES 2

    adval var word ' Create adval to store result
    temp var word ' Create temp to store result
    temp1 var word ' Create temp1 to store result

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %11000001 ' Configure and turn on A/D Module
    Pause 100 ' Wait 0.1 second


    loop: ADCON0.2 = 1 ' Start Conversion

    AGAIN: Pause 1
    If ADCON0.2 = 1 Then AGAIN ' Wait for low on bit-2 of ADCON0, conversion finished

    adval.highbyte = ADRESH ' Move HIGH byte of result to adval
    adval.lowbyte = ADRESL ' Move LOW byte of result to adval

    Lcdout $fe, 1 ' Clear screen
    temp=50*adval ' Conversion to Degrees
    temp=temp/100
    Lcdout "TEMP = ",DEC temp,$DF,"C" ' Display the value of temp
    temp1 = temp*18 ' Conversion to Fahrenheit
    temp1 = temp1+320
    temp1 = temp1/10
    lcdout $FE,$C0, "TEMP = ",dec temp1,$DF,"F" ' Display the value of temp
    Pause 1000 ' Wait 1 second

    Goto loop ' Do it forever
    End

  28. #28
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Question

    ok, now that i have e's keypad code, how do i implement the idea that i mentioned in #90?

  29. #29
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    ok, now that i have e's keypad code, how do i implement the idea that i mentioned in #90?
    Do you have the code working?
    What happens when "A" is pressed now?
    Dave
    Always wear safety glasses while programming.

  30. #30
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: Need help desperately!!!

    handy key fifo for this routine to keep 5 key strokes deep

    Code:
     
      if key >0  then 
           
       for Key_count  = 4 to 1 step - 1 
           Key_value(Key_count) = Key_value( Key_count - 1)
       next Key_count     
     
        Key_Value(0) = Key
       
       endif

  31. #31
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    579


    Did you find this post helpful? Yes | No

    Default Re: Need help desperately!!!

    How can I use this include for something like this ???
    Code:
    main:
    @ READKEYPAD _myvar
    gosub check
    goto main
    
    check:
    select case myvar
    
    case 1  
    porta.0 = 1 ; WHILE CASE 1 PORTA.0 = 1, THEN PORTA.0 = 0
    Thanks !

  32. #32
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,522


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    Code:
    CASE 1  
      Porta.0 = 1
      WHILE myVar = 1
        @ READKEYPAD _myvar
      WEND
      PortA.0 = 0
    /Henrik.

  33. #33
    Join Date
    Aug 2008
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    HI
    ABOUT THE ROUTINE WRITTEN BY MR MISTER_E.
    I NEED HELP HOW TO MAKE THE NUMBERS ARE IN SERIES EXAMPLES 12345566
    AND THEN PRESS THE BUTTON # SEND VIA SERIAL A SEQUECIA.
    Code:
    #CONFIG
        __config _HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF & _LVP_OFF & _WRT_OFF   
    #ENDCONFIG
    
    DEFINE OSC 4 
    
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad2.bas"         
    
    '                      
    '    Hardware connection
    '    ===================
    
    DEFINE KEYPAD_ROW		4      
    DEFINE KEYPAD_ROW_PORT   	PORTC   
    DEFINE KEYPAD_ROW_BIT	0
    DEFINE KEYPAD_COL        	3
    DEFINE KEYPAD_COL_PORT   PORTC
    DEFINE KEYPAD_COL_BIT    	4
    DEFINE KEYPAD_DEBOUNCEMS 200     'debounce delay = 200 mSec
    define KEYPAD_AUTOREPEAT 1       'use auto-repeat
        
    ' LCD Display
    ' -----------
    ' Adjust these to suit your chosen LCD pinout
    '
    '----DEFINIR   LCD--------------------------------------------------------------
    DEFINE LCD_DREG PORTB     ' LCD data port
    DEFINE LCD_DBIT 4         ' LCD data starting bit
    DEFINE LCD_RSREG PORTB    ' LCD register select port
    DEFINE LCD_RSBIT 2        ' LCD register select bit
    DEFINE LCD_EREG PORTB     ' LCD enable port
    DEFINE LCD_EBIT 3         ' LCD enable bit
    DEFINE LCD_BITS 4         ' LCD data bus size
    DEFINE LCD_LINES 2        ' Number lines on LCD
    DEFINE LCD_COMMANDUS 5000 ' Command delay time in us
    DEFINE LCD_DATAUS 50      ' Data delay time in us
    
    mykey   VAR BYTE
    myvar   var byte
    array   var byte[5]
    index   var byte
    i       var byte
    word_v  var word
     
    LCDOUT $FE,1,  "  FONTE DIGITAL   "
    PAUSE 1000
    LCDOUT $FE,1
        '    ---------------------------------[Program Start]----------------------------------------------
    start:
        @ READKEYPAD _myvar
    	gosub lcddisp
        goto start
    
    lcddisp:
        LCDOUT $FE,$C0,DEC4 myvar 
        pause 60
        return
        end
    Attached Images Attached Images  

  34. #34
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,821


    Did you find this post helpful? Yes | No

    Default Re: Matrix Keypad routine

    You may add the keypresses to an array using an index and then send the array over the serial port.

    Not tested but you get the idea:

    Code:
    string    var byte[9]
    index1    var byte
    
    start:
    For index1=0 to 8
    @ READKEYPAD _myvar
    	string[index1]=myvar
    next index1
    
    if myvar="#" then hserout [STR string\8]
    
    goto start
    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 : 2

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