Quick 4x4 keypad matrix question


Closed Thread
Results 1 to 16 of 16

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    Hi Sean,
    You have a flair for understatement, "slightly modified" It looks modified for all get out to me.
    Question1. Why are you putting in LCD defines if you are using the USART, Do you want dual display?

    Question 2. Since you did not specify which PIC you are using, which port is your PIC equipped to use the USART ? Is it the same as the keypad uses?

    Question 3. Why did you change the value of the resistors ? I suspect Bruce proved out his design before posting it on his website.
    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.

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    Yup, I'd start with using the same resistor values and logic as Bruce and get that working first. Then I'd tweak the code to my liking/needs and changing hardware.

    Archangel is right. Bruce adds little comments like this one for a reason:

    The original prototype was designed using the PIC16F628, but the code shown below can easily be modified to work on any PIC with sufficient I/O capacity for the keypad interface, and the two lines required for the serial output-pin, and baud-rate selection pin.

    CMCON is the comparator mode selection register. Loading a value of 7 into CMCON sets-up the PortA I/O-pins as digital, while turning OFF the comparators.

    If you prefer to use another PIC that has A/D on PortA, simply replace CMCON = 7 with ADCON1 = 7 to turn OFF the A/D peripheral, and set PortA to digital.
    Last edited by Demon; - 19th June 2011 at 02:42.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  3. #3
    Join Date
    Jun 2011
    Location
    St. Louis, MO
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    Thanks for the reply Demon.
    I didnt think these comments from Bruce really applied to my problem.

    PortA's pins were used for SEROUT and the baud selection portion of the original program. I changed the SEROUT to HSEROUT thinking it might change the end result of displaying the correct value and not of the button below it.

    The other port was for baud rate selection for the SEROUT command. By using the HSEROUT and defining its properties at the begining, I thought it would be easier to narrow down the problem.

    I still am using PORTB for the keypad just like in Bruce's code. By changing the resistors it worked better, but not perfect. I just cant seem to understand why it is doing it only on the one button.

    Thanks again,

    Sean

  4. #4
    Join Date
    Jun 2011
    Location
    St. Louis, MO
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    Thanks for the reply Archangel. In response to your questions...

    1. Why are you putting in LCD defines if you are using the USART, Do you want dual display?
    The LCD is used just for quick on-the-spot feedback. It was part of another program, so I usually just cut-and-paste it into other programs. The USART is just for debugging purposes. Plus it remindes me of the old BBS days .

    2. Since you did not specify which PIC you are using, which port is your PIC equipped to use the USART ? Is it the same as the keypad uses?
    At the beggining I stated I was using an PIC 16F877 @ 20 mhz. The hardware USART TX/RX are ports C6/C7 on the 16F877 which are only being used for serial communication. The keypad is is connected to PORTB.0 to PORTB.7.

    3. Why did you change the value of the resistors ? I suspect Bruce proved out his design before posting it on his website.
    I was under the impression that the value of the resistors were not that important to a certain extent. While researching keypad matrices, a few people stated that any value <= 10k would be sufficient. I had 1k resistors with me at the time so i gave it a shot. I just replaced the 1k resistors with 270-ohm. It seemed to make the problem occur only on one button (row3-col1). While pressing the button repeatedly, the value displayed will sometimes be the value of the button directly below it, but only intermittently.

    By changing the 1k resistors for 270 helped eliminate the problem on all the buttons except the one (row3-col1). I still cant figure what is causing this.

    thanks again for the help.

    Sean

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


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    Quote Originally Posted by triton99 View Post
    Thanks for the reply Archangel. In response to your questions...

    1. Why are you putting in LCD defines if you are using the USART, Do you want dual display?
    The LCD is used just for quick on-the-spot feedback. It was part of another program, so I usually just cut-and-paste it into other programs. The USART is just for debugging purposes. Plus it remindes me of the old BBS days .

    2. Since you did not specify which PIC you are using, which port is your PIC equipped to use the USART ? Is it the same as the keypad uses?
    At the beggining I stated I was using an PIC 16F877 @ 20 mhz. The hardware USART TX/RX are ports C6/C7 on the 16F877 which are only being used for serial communication. The keypad is is connected to PORTB.0 to PORTB.7.

    3. Why did you change the value of the resistors ? I suspect Bruce proved out his design before posting it on his website.
    I was under the impression that the value of the resistors were not that important to a certain extent. While researching keypad matrices, a few people stated that any value <= 10k would be sufficient. I had 1k resistors with me at the time so i gave it a shot. I just replaced the 1k resistors with 270-ohm. It seemed to make the problem occur only on one button (row3-col1). While pressing the button repeatedly, the value displayed will sometimes be the value of the button directly below it, but only intermittently.

    By changing the 1k resistors for 270 helped eliminate the problem on all the buttons except the one (row3-col1). I still cant figure what is causing this.

    thanks again for the help.

    Sean

    Hi Sean, Ok . . .

    1.OK . . . had to ask . .
    2. Sorry old eyes, I missed that. Ok that's good.
    3. Looked at Bruce's page again, his statement proves you right . . . non critical.
    This code is floating around the forum in many threads, with many variations, and the only thing I see is no TRIS settings for your ports B,C, & D. In the 1 Mr._E did he set the portb Tris as follows: TRISB = %11110000 , he also used an interrupt to detect the keypress, it maybe your finger is faster than your loop, especially given you are using 3 different display protocols. I would comment out any code you are not pressed to use and see if it improves, also you might consider debug over serout as it executes faster using less code space ( or so they tell me) I have not yet proven that last statement to myself, but it is a bit faster, in terms of how long a loop takes to execute,
    oh and try these defines (from mister E's famous picmulti calc)
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    Last edited by Archangel; - 19th June 2011 at 10:39. Reason: I really miss the Old Forum's text format
    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.

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


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    The program kinda of works....sometimes when a button is pressed, the number sent via HSEROUT is actually the number below it.

    i.e. Say the number "3" is pressed...most of the time the number "3" is displayed...but sometimes the number displayed will be "6", which is the button just below the "3" on the keypad.
    Double check your hardware.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    What's in the INCLUDE "ansi.inc" file ?
    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.

  8. #8
    Join Date
    Jun 2011
    Location
    St. Louis, MO
    Posts
    13


    Did you find this post helpful? Yes | No

    Smile Re: Quick 4x4 keypad matrix question

    I just assembled the same circuit using an 16f88 instead of the 16F877. Using the same circuit and code[plus changes for the 16F88], the program works perfect.

    These are the register setting I use on the 16F88.

    Code:
    CMCON =     7                   '// PortA = digital I/O
    OPTION_REG.7  =  0              '// Enable PORTB pull-ups
    ADCON1  =  7 
    ANSEL=%00000000                 '// set all analog pins to digital
    ANSEL = 0                       '// disable ADC
    With the circuit working on the 16F88, I resumed working on the 16F877.

    I rebuilt and re-checked the wiring on the 16F877. I also got rid of all the extra LCDOUT and HSEROUT commands, while using only the SEROUT command, just like the Bruce's original example. It still has the weird problem. I just cant seem to pinpoint what is causing the error. Its weird too, because I dont have to be pressing the button fast....it does it even if when I press the button slowly. Every once in a while it will display the number below instead of the actual number. Arghhhhhh!!!! I love this stuff .

    *Archangel, the "ANSI.INC" was from Darrel Taylors easy ANSI module for PBP.
    It is the main reason I wanted to use HSEROUT. The ansi.inc only works with the hardware USART, and not with SEROUT(2).

    Thanks for the help, Im not giving up on this.

    Sean
    Last edited by triton99; - 20th June 2011 at 03:03.
    "Reality is merely an illusion, albeit a very persistent one." , Albert Einstein

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


    Did you find this post helpful? Yes | No

    Default Re: Quick 4x4 keypad matrix question

    Ok, just wanted to know, oh and I do see where you set TrisB in your orig modified code. Maybe as Dave mentioned there is a hardware problem, bad breadboard or the pic it'self. Those breadboards get corrosion inside them and then the fun begins.
    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.

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts