Matrix Keypad routine - Page 3


Closed Thread
Page 3 of 4 FirstFirst 1234 LastLast
Results 81 to 120 of 135
  1. #81


    Did you find this post helpful? Yes | No

    Default

    I found this solution which was already in the forum, thanks

    Quote Originally Posted by mister_e View Post
    OK NO NEED FOR THAT

    i've attach the latest version... which i thought i had posted here


    So the only thing you will have to do, is to add this simple line
    Code:
    DEFINE SCAN_ONCE 1
    And this should cure the problem.

    I have added this feature once i needed to scan a keypad with a timer interrupt... which is certainly the way to go for any Push-Button/Keypad entry anyways.

    Enjoy!

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


    Did you find this post helpful? Yes | No

    Default

    This is an update to the PM version of Steve's Matrix Keypad routine.

    Steve added a SCAN_ONCE option after I converted it for PM.exe. And someone recently asked for an update to it. It took me so long to do it, I forget who asked.

    Note: This is for PM only. It will not work with MPASM.

    HTH,
    Attached Files Attached Files
    DT

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

  4. #84
    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

  5. #85
    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

  6. #86
    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  

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

  8. #88
    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

  9. #89
    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.

  10. #90
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    well, i was thinking that when i push "Button A" of the keyapd, the upper setpoint will be displayed, "Button B" = Lower limit, "Button C" = Backspace, "Button D" = OK , "Button *" = alarm on/off, "Button #" = Main screen

  11. #91
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    well, i was thinking that when i push "Button A" of the keyapd, the upper setpoint will be displayed, "Button B" = Lower limit, "Button C" = Backspace, "Button D" = OK , "Button *" = alarm on/off, "Button #" = Main screen
    Ok, so you've defined the FUNCTIONs of the buttons...now how to you act on those functions.
    In fact, do yourself a favor and just work on adding one button at a time...

  12. #92
    Join Date
    Oct 2008
    Posts
    47


    Did you find this post helpful? Yes | No

    Default

    thats my point. I have no idea where to begin...i was thinking maybe scan keypad first, check if A or B was pressed and if so then act upon it by prompting the user to enter a desired setpoint. once that's done, press ok and return to the main display screen. the alarm can be set on for the desired lower setpoint and once the upper setpoint has been reached, the relay should switch on. vice versa

  13. #93
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    thats my point. I have no idea where to begin...i was thinking maybe scan keypad first, check if A or B was pressed and if so then act upon it by prompting the user to enter a desired setpoint. once that's done, press ok and return to the main display screen. the alarm can be set on for the desired lower setpoint and once the upper setpoint has been reached, the relay should switch on. vice versa
    Then write some code and see how it works!
    If it doesn't work, post the code, and I'm sure somebody will help you figure it out.

  14. #94
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    The first thing to do is open Mr. E's Keypad.bas and read the instructions he wrote for you.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  15. #95


    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

  16. #96
    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?

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

  18. #98
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Kalind View Post
    well, i was thinking that when i push "Button A" of the keyapd, the upper setpoint will be displayed, "Button B" = Lower limit, "Button C" = Backspace, "Button D" = OK , "Button *" = alarm on/off, "Button #" = Main screen
    Code:
    InterruptHandler:
    @ READKEYPAD _MyVar
    resume
    'now your key reading is stored in MyVar
    most 16 key keypads are laid out 123A 456B 789C *0#D, so 1=1 2=2 3=3 A=4 4=5 . . . .
    You can use this as is or use a lookup routine to alias the actual port reading to what
    you want, like so:
    Code:
    lookup MyVar,[0,"123A456B789C*0#D"],MyOtherVar
    now your key information stored in myOtherVar will mirror your keypad.
    so . . .
    Code:
    If myothervar = A then gosub Uppersetpoint
    if MyOtherVar = b then gosub . . . .easy
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  19. #99
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Hay guys and girls. I've been playing around with this coding this afternoon and i keep getting errors and when i dont nothing going as i thought it should so any chance somone could point out whats wrong please or point me in the right dirrection at least!

    My main coding:

    Code:
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad.bas"         
    
        '                      
        '    Hardware connection
        '    ===================
        DEFINE KEYPAD_ROW        8       ' 8 row 
        define KEYPAD_ROW_PORT   PORTc   '   on PORTB
        DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
        DEFINE KEYPAD_COL        4       ' 4 col 
        DEFINE KEYPAD_COL_PORT   PORTc   '   on PORTA
        DEFINE KEYPAD_COL_BIT    0       '      <3:0>
        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
    '
    DEFINE LCD_DREG PORTb 			'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 4 			'Define first pin of portb connected to LCD DB4
    DEFINE LCD_RSREG PORTb 			'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 3 			'Define Portb pin used for RS connection
    DEFINE LCD_EREG PORTb 			'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT 0 			'Define PortB pin used for E connection
    DEFINE LCD_BITS 4 			'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 			'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 		'Define delay between sending LCD commands
    DEFINE LCD_DATAUS 50 			'Define delay time between data sent.
        
        '
        '    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]
    	gosub lcddisp
        goto start
    
    lcddisp:
    LCDOUT $FE, 1, myvar
    pause 60
    return
    end

    The modified Keypad code
    Code:
    TRISA=%00000011
    TRISB=%00000000
    TRISC=%11111110
    ADCON0=%11000000
    ADCON1=%00000111 
    INCLUDE "KeyPad.bas"         
    
        '                      
        '    Hardware connection
        '    ===================
        DEFINE KEYPAD_ROW        8       ' 8 row 
        define KEYPAD_ROW_PORT   PORTc   '   on PORTB
        DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
        DEFINE KEYPAD_COL        4       ' 4 col 
        DEFINE KEYPAD_COL_PORT   PORTc   '   on PORTA
        DEFINE KEYPAD_COL_BIT    0       '      <3:0>
        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
    '
    DEFINE LCD_DREG PORTb 			'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 4 			'Define first pin of portb connected to LCD DB4
    DEFINE LCD_RSREG PORTb 			'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 3 			'Define Portb pin used for RS connection
    DEFINE LCD_EREG PORTb 			'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT 0 			'Define PortB pin used for E connection
    DEFINE LCD_BITS 4 			'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 			'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 		'Define delay between sending LCD commands
    DEFINE LCD_DATAUS 50 			'Define delay time between data sent.
        
        '
        '    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]
    	gosub lcddisp
        goto start
    
    lcddisp:
    LCDOUT $FE, 1, myvar
    pause 60
    return
    end



    forgot to put the error code

    Executing: "C:\Program Files\Microchip\MPASM Suite\MPAsmWin.exe" /q /p16F876A "KEYPADTE.ASM" /l"KEYPADTE.lst" /e"KEYPADTE.err"
    Error[113] C:\PBP\PBPPIC14.LIB 2784 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2785 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2789 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2790 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2800 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2871 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2889 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2913 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2920 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2928 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\PBPPIC14.LIB 2934 : Symbol not previously defined (PORTb)
    Error[113] C:\PBP\KEYPADTE.ASM 100 : Symbol not previously defined (PORTc)
    Error[113] C:\PBP\KEYPADTE.ASM 103 : Symbol not previously defined (PORTc)
    Error[113] C:\PBP\KEYPADTE.ASM 125 : Symbol not previously defined (PORTc)
    Error[113] C:\PBP\KEYPADTE.ASM 136 : Symbol not previously defined (PORTc)
    Halting build on first failure as requested.
    BUILD FAILED: Thu Nov 20 16:00:57 2008
    Attached Images Attached Images  
    Last edited by chrisshortys; - 20th November 2008 at 17:45.

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


    Did you find this post helpful? Yes | No

    Default

    YUP, that's what happen when you don't check the spelling of your DEFINEs. DEFINEs are case sensitive. So PORTb have to be written PORTB, and so on with all others.
    Steve

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

  21. #101
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Cheers, so any clues as to whats wrong now? i dont get any reaction on the LCD and i get several ports flash high then low

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


    Did you find this post helpful? Yes | No

    Default

    well...
    Code:
        DEFINE KEYPAD_ROW        8       ' 8 row 
        define KEYPAD_ROW_PORT   PORTc   '   on PORTB
        DEFINE KEYPAD_ROW_BIT    0       '      <7:0>
        DEFINE KEYPAD_COL        4       ' 4 col 
        DEFINE KEYPAD_COL_PORT   PORTc   '   on PORTA
        DEFINE KEYPAD_COL_BIT    0       '      <3:0>
    looking at your schematic bellow

    There's some problems there for sure... You don't use a 8X4 keypad
    Code:
        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
    Last edited by mister_e; - 20th November 2008 at 18:58.
    Steve

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

  23. #103
    Join Date
    Oct 2008
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    Thanks yet again mister_e! You should move in with me, that way i wouldnt have to use the net to bother yo every other day

    and yes i put the dec2 myvar on the lcdout command so all works now

    time to play with it some more!

  24. #104
    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???

  25. #105
    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.

  26. #106


    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

  27. #107


    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

  28. #108
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    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

  29. #109


    Did you find this post helpful? Yes | No

    Default

    Hi Ioannis

    Thanks for the reply :-)
    Lookup is already implemented and working .

    My range would be anything really (inifinity ??) but I guess I could use 0 to 999

    It's like dialling on a phone ... you dial the numbers and then press the dial button :-)

    I want to type numbers in and then press the # key and * to backspace or clear last entry ...

    Kind regards

    Dennis

  30. #110
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Well, if you go for the 999 then a 0-65535 is possible as the final result needs a word variable.

    One idea untested is this:

    Code:
    array   var byte[5]
    index   var byte
    i       var byte
    word_v  var word
    
    'Get keypress
    index=0
    
    loop:
    gosub key_read
    if mykey=32 then loop 'No key press returns 32
    array[index]=myvar
    index=index+1
    if index=5 then calculate_result
    goto loop
    ...
    
    caculate_result:
    word_var=0:mult=10000
    for i=index-1 to 0 step -1
        word_var=word_var*mult+array[i]
        mult=mult/10
    next i
    index=0
    goto display_result
    As there is the index counter, there is no need to press '#'. Numbers must be entered in 5 digit format, e.g. 00123.

    Also there is no filter if the user keys in a number greater than 65535, in which case result will be of course wrong due to overflow.

    Ioannis
    Last edited by Ioannis; - 23rd November 2009 at 21:02.

  31. #111


    Did you find this post helpful? Yes | No

    Default ooops

    Hi Ioannis

    Thank you for the code example... I'm just thinking that perhaps it would indeed be more practical to use 255 as the max number, in which case I would need to declare a byte as opposed to a word ...not so ?

    Kind regards

    Dennis

  32. #112
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,802


    Did you find this post helpful? Yes | No

    Default

    Yes, that is correct. Rest applies of course.

    But don't be afraid of the word variable!

    Ioannis

  33. #113


    Did you find this post helpful? Yes | No

    Default help with a small change

    Hi all

    The keypad code has been working very well ! Thanks mister_e!

    Initially I had to wire alter the wiring to the keypad to the PIC to get things working now in order to match the header pins for PORT B on a dev board I am building I need to alter the include file somehow to match my keypad.
    I was hoping someone could point me in the right direction for this or tell me where to change the code to match the desired pin configuration.
    Here is what I have now:

    EXISTING CONFIG (WORKING)
    -------------------------

    Columns Rows
    ______________ _____________
    Keypad 7 6 5 4 3 2 1 0

    PIC B4 B5 B6 B7 B0 B1 B2 B3

    Here's what I would like to be
    DESIRED CONFIG
    --------------

    Columns Rows
    ______________ _____________
    Keypad 7 6 5 4 3 2 1 0

    PIC B7 B6 B5 B4 B3 B2 B1 B0



    I would appreciate any help/info

    Kind regards

    Dennis
    Last edited by Dennis; - 7th January 2010 at 23:34.

  34. #114


    Did you find this post helpful? Yes | No

    Default Here's a picture to better explain it

    Check the attached file

    Dennis
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    Steve's keypad routines won't let you reverse the orders like that.
    But you can re-map the keys to whatever you want.

    By reversing both the columns and rows, I think it would come out like this ...
    Code:
    @ READKEYPAD _myvar
    
    ; original keys   1  2  3  4  5  6  7 8 9 10 11 12 13 14 15 16 
    LOOKUP  myvar,[0,16,15,14,13,12,11,10,9,8, 7, 6, 5, 4, 3, 2, 1],myvar
    Which should also work like this ...
    Code:
    myvar = 17 - myvar
    If they don't line up right, you can change the LOOKUP to a pattern that matches.

    hth,
    DT

  36. #116


    Did you find this post helpful? Yes | No

    Default awesome

    Thanks Darrel

    Will give it a shot and feedback results here :-)

    Dennis

  37. #117


    Did you find this post helpful? Yes | No

    Default Fixed!!

    Hi Darrel

    Thanks for the assistance :-)
    The LOOKUP change was the easiest solution !

    originally I had this
    Code:
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
    
    LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress
    And I just changed the line to this
    Code:
    @ READKEYPAD _myvar  'read keypress variable and place in myvar
       LOOKUP myvar,[0,"D#0*C987B654A321"],myvar
    Thanks a million , it saves me having to redo my dev board design or re-wiring the keypad :-) YAY

    Kind regards
    Dennis

  38. #118
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Fail enought times and you start to learn!

    HI all,
    I have been playing with this wonderful piece of code for many hours. Really cool code. I was having problems with one row of the keypad but the rest was working enough for me to proceed filling in the gaps and learning the lessons from the thread. I bring this up because I have been caught on it before, you would have thought I'd have learned....

    The row in question would freeze the operation of the circuit. Upon looking closely at the datasheet, I my eye caught the LOW VOLTAGE PROGRAMMING option. A faint voice in my head reminded me that we were not friends (the option, not the voice). Yep, that was it. Disabled it in meLabs programmer and... you guessed it... runs just like it was suppose to. Who'd a thought it?

    Hope that this saves someone else some head banging. Some gotchas I have to keep reminding myself about.
    Bo

  39. #119
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Converting in Steve's include

    Hi all,

    I have managed to get Steve's (Mister E) KeyPad.bas to remap and do what I would like to accomplish. Thanks again Steve for writing it and you others for explaining it. Really handy!

    Here's the question: Where in KeyPad.bas would you insert the "LOOKUP myvar,... " so that you only had to do it once and not burn up a bunch of space? In my case, I would save the original, and rename the converter custom version to something appropriate.

    From what I can decipher, (which is embarrassingly meager), the include file sets up a macro if you choose to use "@ READKEYPAD _YourVar". It gets the result from the subroutine "KeypadScan".

    Am I right that the "LOOKUP..." would go just before the "ReadCol:"
    subroutine to allow the remapping to occur each time you look for a key?

    Thanks
    Bo

  40. #120
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Appologies

    I'm sorry to the list....

    After I posted that last question, it hit me like a brick... That was being really immature... I knew what I wanted to happen, but I hung when I saw a bit of code that was confusing to me. I had an idea what might work but instead of trying to test it myself, I defaulted to asking the list. Very poor.. I should have at least tried something and done some of my own work first instead of asking others to do it for me.

    My feeble assumption proved so far to be correct, by adding the LOOKUP into what I now call KeyPadRM.bas (the RM for ReMap), and making sure to save it as a .bas, I can eliminate many redundant lines of code. The edit is at the end of Steve's code:
    Code:
    ......
                until row>(KB_ROW-1)                           
            if (single_scan=0) AND (KEY=0) then ScanKeypad     ; Row scan finished?
      LOOKUP  Key,[0,1,2,3,10,4,5,6,11,7,8,9,12,15,14,16,13],Key ; ReMap Edit  
          RETURN                                                 ; any key pressed?      
    ReadCol:
        KeyTemp=kb_col_PORT>>kb_col_Bit                        ; Read Column state
        KeyTemp=KeyTemp & kEYMASK                              ; Keep only wanted bits
        return
    
    JumpOverKeyScan:
    Any corrections of my understanding are welcome.
    Bo

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