Shop OBEX P1 Docs P2 Docs Learn Events
Keypad and Multiplexing Help — Parallax Forums

Keypad and Multiplexing Help

MRMR Posts: 46
edited 2006-12-21 15:55 in BASIC Stamp
Hi,

I have ten 7 segment Led Displays Common Anode, connected in parallel with one 7447 BCD to 7 Segment Decoder chip. I have pins 0-3 as the binary nibble from the BS2P40 to the 7447 decoder chip. What I want to do is scan a keypad and store each keypress in a variable, once all 10 variables have been stored I would like to Turn on each display which is connected to its own pin on the basic stamp, send the corresponding Binary nibble from the variable to the decoder chip shut off the display and do the same for each display. I am not very advanced with programming in PBasic. Mutliplexing 7 segment displays is what I am trying to accomplish. In addition, would someone be kind enough to explain the difference between DIRS and OUTS, I know that you can have High and Low bytes but what do the actual functions mean? Whats the difference Between DIRS,and OUTS? My code is sloppy and not the best but I am still learning. Each 7 segment display has 7 lines all wired in parallel to one 7447 BCD Decoder chip. The 4 Binary inputs on the 7447 are connected to pins 0-3 on the basic stamp. This way I can drive a seven segment display with only 4 lines instead of 7 lines.

Here is my Code:

' {$STAMP BS2p}

'This program scans a ten digit keypad and stores each keypress into specific
'variables. Once the enter key is pressed the variables are sent to the corresponding
'display and multiplexed. I am considering placing external transistors to help switching.
'Dates are stored in variables.
'One 7447 Decoder will be used instead of using 8 input lines.


'Constants
ZERO CON %0000
One CON %0001
Two CON %0010
Three CON %0011
Four CON %0100
Five CON %0101
Six CON %0110
Seven CON %0111
Eight CON %1000
Nine CON %1001


Digit1 VAR Nib
Digit2 VAR nib
Digit3 VAR nib
Digit4 VAR nib
Digit5 VAR nib

main: 'Main Keypad Scanning Routine
AUXIO
IF IN0=0 THEN Number
IF IN2=0 THEN number2
IF IN3=0 THEN enter
' I would like to expand this to all ten digits 0-9, but I don't know how to program
' the stamp to store each keypress in a different variable. Example 1st keypress is
' stored in variable Digit1 possibility of 0-9, then the 2nd keypress is stored in Digit2 possibility of 0-9.
' Etc Etc until all Ten Digits have been stored in thier appropriate variable.
GOTO main

number:
Digit=nine
GOTO main

number2:
Digit2=Two
GOTO main



Enter: ' Begin Multiplexing displays
MAINIO
HIGH 15 'Turn on Display 1
DIRL=Digit 'Send Binary Nibble to Display; Note Nibble is on Pins 0-3 MainIO A=Pin 0 D=Pin 3
PAUSE 100 'Take A break.
LOW 15 'Shut off display 1
HIGH 14 'Turn on Display 2
DIRL=Digit2 'Send Binary Nibble to Display 2.
PAUSE 100 'Pause
LOW 14 'Shut off Display 2
GOTO enter

Post Edited (MR) : 12/20/2006 7:30:14 AM GMT

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-20 15:08
    MR,
    ·
    ·· Are you locked into using that exact hardware for the displays?· How about hardware for the keypad?· There are integrated circuits which make interfacing the keypad and displays less painful.· However, if you want to do it exactly like that I would recommend working on one section at a time and then when both function you can work on integrating the code.· For scanning the keypad you might want to have a look at the following thread which uses 8 I/O lines to scan a 4X4 keypad.· Tracy Allen has provided some good code and there is a schematic listed in the thread as well.· I hope this helps.· Take care.

    http://forums.parallax.com/showthread.php?p=570329

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • MRMR Posts: 46
    edited 2006-12-21 01:15
    1. Are you locked into using that exact hardware for the displays?
    If I understand the question correctly, I have to use 7 segment displays not LCD displays as this is an industrial application that needs the ruggedness of 7 segment displays.
    Please explain what you mean by being Locked into that exact hardware for the displays.

    How about hardware for the keypad?
    As far as the keypad, The less I/O pins that I use the better, if I can get by with using 8 lines instead of 10 lines for the keypad by all means I will do it.

    I am trying to accomplish this with just the basic stamp and minimal hardware, in other words I would prefer not to wait on ordering a special encoder chip or anything as time is a factor in finishing this project.

    Thanks,

    MR.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-12-21 15:06
    MR,
    ·
    ·· What I was referring to is that you could use a chip such as the MAX7219 or the MC14489 to drive the displays.· Each of these would require 3 I/O pins and could drive 8 and 5 digits, respectively.· As for the keypad, there are chips such as the EDE1144 which can interface a 4X4 Matrix keypad through a simple serial interface.· I have posted examples of using this chip with the BASIC Stamp on these forums a few times.· There are also many examples of using the MAX7219, such as the following Completed Project.· I hope this helps.· Take care.

    http://forums.parallax.com/showthread.php?p=552892

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2006-12-21 15:55
    Hi MR, DIRS INS and OUTS read or write the status of the I/O pins at bit,nibble,byte or word level.

    DIRS configures the pins to be inputs (0) or outputs (1). For example DIRA=%1111 would set the lowest nibble (pins 0 1 2 3) as outputs. DIRL=%11110000 would set the low byte as 4 inputs (0 1 2 3) and 4 outputs (4 5 6 7)

    OUTS can read or write the logic level of the outputs. If we take the last example above OUTB=%0110 would simultaneously set pins·5 and·6 high (+5v) and pins 4 and 7 low (0v).

    INS can read any or all inputs at one go. Again taking the DIRL example above (this time looking at the inputs), if you had a 4 bit binary input on pins 0 1 2 and 3 you could read that value and/or assign it to a variable such as :·my_bin_num = INA.·Decoding a·keypad is one useful way to use this function, 4 pins monitor 16 different key states stored in one variable.

    Jeff T.
Sign In or Register to comment.