You need to give more information. What kind of display are you using? First you say LCD, then you say LED. Which do you have and who makes it? When you say you want a 6 digit number to display, what form is it in? The Stamps are 16-bit microcontrollers and 16 bits gives you a little less than 5 significant digits (0 - 65535). If you're using signed values, that's -32768 to +32768. If you're using larger numbers, how are you representing them inside the Stamp?
opps. sorry . i mean LCD . cause now my LCD can have a lot of number on the screen . but i just want to display 6 number on the screen, so that when i key in the 7 number, it will not display . it will only display 6 number on the screen. sorry man
So you want a piece of code that lets you type numbers in but that will only accept 6 digit numbers? Pushing anything else on the keypad after there are 6 digit shouldn't do anything, right?
You haven't even posted your code to this thread. The code you have posted is hard to read since you didn't use code tags.
The code doesn't really make sense IMO. You use the same subroutine with every "IF" or "ELSEIF" condition when it doesn't make any sense to do so.
The code you posted has lots of problems.
I attempted to write some code based on my guess of what you're trying to do. Hopefully you can see how each "IF" or "ELSEIF" statement calls a subroutine to narrow the search of which button is pressed.
' {$STAMP BS2pe}
' {$PBASIC 2.5}
counter VAR Nib
TX PIN 15
Spkr PIN 15
#SELECT $stamp
#CASE BS2PE
T2400 CON 396
T9600 CON 84
T19K2 CON 32
#ENDSELECT
LcdBaud CON T19K2
LcdCls CON $0C ' clear LCD (use PAUSE 5 after)
LcdBLon CON $11 ' backlight on
COUNT_LIMIT CON 6
SEROUT TX, Lcdbaud, ["Key in PIN",CR, LcdBLon]
counter = 0
main:
counter = counter + 1 ' Assume a button will be pressed. If no button is pressed, we'll subtract it later.
IF (IN6=0 AND (IN7=0 OR IN0=0 OR IN1=0)) THEN
GOSUB check6701
PAUSE 250
ELSEIF (IN7=0 AND (IN8=0 OR IN1=0 OR IN0=0 OR IN2=0))THEN
GOSUB check78102
PAUSE 250
ELSEIF (IN8=0 AND (IN9=0 OR IN2=0 OR IN1=0 OR IN3=0))THEN
GOSUB check89213
PAUSE 250
ELSEIF (IN9=0 AND (IN10=0 OR IN3=0 OR IN2=0 OR IN4=0))THEN
GOSUB check9A324
PAUSE 250
ELSEIF (IN10=0 AND (IN11=0 OR IN4=0 OR IN3=0 OR IN5=0))THEN
GOSUB checkAB435
PAUSE 250
ELSEIF (IN11=0 AND (IN12=0 OR IN5=0 OR IN4=0))THEN
GOSUB checkBC54
PAUSE 250
ELSE
GOSUB noButtonPressed
ENDIF
IF counter >= COUNT_LIMIT THEN
SEROUT TX, Lcdbaud,[LcdCls,"Thanks for Banking",CR]
END ' I doubt this is the correct way to end a program.
ENDIF
GOTO main
'====================================END MAIN============================================== ='
check6701:
IF IN0=0 THEN 'num 0
SEROUT TX, Lcdbaud,["0"]
PAUSE 180
DO 'wait for button release
IF IN0 = 0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ELSEIF IN1 = 0 THEN 'num 1
SEROUT TX, Lcdbaud,["1"]
PAUSE 180
DO
IF IN1 = 0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ELSEIF IN7 = 0 THEN 'num 7 I don't know if this is correct
SEROUT TX, Lcdbaud,["7"]
PAUSE 180
DO
IF IN7 = 0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
ELSE ' button no longer pressed
GOSUB noButtonPressed
ENDIF
RETURN
check78102:
IF IN2 = 0 THEN 'num 2
SEROUT TX, Lcdbaud,["2"]
PAUSE 180
DO
IF IN2 = 0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
' check for IN8, IN1 and IN0
ENDIF
RETURN
check89213:
IF IN3 = 0 THEN 'num 3
SEROUT TX, Lcdbaud,["3"]
PAUSE 180
DO
IF IN3 = 0 THEN
PAUSE 180
ELSE
EXIT
ENDIF
LOOP
' check for IN9, IN2 and IN1
ENDIF
RETURN
check9A324:
'check IN10, IN3, IN2 AND IN4
RETURN
checkAB435:
'check IN11, IN2, IN3 AND IN5
RETURN
checkBC54:
'check IN12, IN5 AND IN4
RETURN
noButtonPressed:
counter = counter - 1 ' Subtract one to make up for the one we added at the beginning of the loop.
RETURN
If you haven't done so yet, you really ought to work through some of the Basic Stamp tutorials. A lot of your code looks like you're taking wild guesses at how to accomplish some tasks.
No you can't limit the display to six characters with a custom character. A custom character is one you define yourself. Custom character #1 comes programmed with a tilde "~" but this or any other custom character could be changed. If you wanted a smiley face character you could program one of the custom characters to display a smiley face.
You'll need to keep track of how many characters have been entered into the keypad. Your original code included a counter but the code monitored the count in the wrong places in the code.
may i know how does this code do "DispCC0 CON $00"
I'm not sure what your question is. I see your original code as a constant for clearing the screen. I assume you use SEROUT to send the clear screen message.
The partial program I posted in post #14 was an attempt to show you a possible strategy for finding which key was pressed. The original code used the same subroutine no matter which pin was detected to be low. I thought it would be better to use separate subroutines in order to limit the number of pins to check.
I'm not sure how your key pad works. The original code seems very inefficient for finding which key was pressed. I thought it would be better to try to identify which group of keys were possibly pressed and then use a subroutine to identify which key in the group was pressed. Much of what I wrote as based on assumptions (not necessarily correct ones) of how your keypad works. Than "main" section of the code leads me to think you're using a keypad which uses some sort of matrix. But the code in "Top" looks like you're only checking individual pins. It's not clear to me how your keypad works. If your keypad uses a matrix then the code I posted may be useful however is it's not a matrix then you'll want to use a different strategy for finding which key was pressed.
The key press counter should to be monitored from the main loop.
Comments
As Mike says, you need to clearly decribe exactly which LCD you have, what type of data you want to display and how you are sending it.
cause i try a lot , but still cannot work .
You sure make it hard for us to help you.
You haven't even posted your code to this thread. The code you have posted is hard to read since you didn't use code tags.
The code doesn't really make sense IMO. You use the same subroutine with every "IF" or "ELSEIF" condition when it doesn't make any sense to do so.
The code you posted has lots of problems.
I attempted to write some code based on my guess of what you're trying to do. Hopefully you can see how each "IF" or "ELSEIF" statement calls a subroutine to narrow the search of which button is pressed.
If you haven't done so yet, you really ought to work through some of the Basic Stamp tutorials. A lot of your code looks like you're taking wild guesses at how to accomplish some tasks.
It's not a complete program. You'll need to complete the various subroutines.
Use the subroutine "check6701" as a guide on how to write the other subroutines.
Each subroutine which checks for a button press should include the following code:
If no button press is detected then the counter needs to be set back to its original value.
No you can't limit the display to six characters with a custom character. A custom character is one you define yourself. Custom character #1 comes programmed with a tilde "~" but this or any other custom character could be changed. If you wanted a smiley face character you could program one of the custom characters to display a smiley face.
You'll need to keep track of how many characters have been entered into the keypad. Your original code included a counter but the code monitored the count in the wrong places in the code.
What code?
Did you write additional subroutines like "check6701" and complete the program? If so post it. Tell us what it does and what you want it to do.
I'm not sure what your question is. I see your original code as a constant for clearing the screen. I assume you use SEROUT to send the clear screen message.
The partial program I posted in post #14 was an attempt to show you a possible strategy for finding which key was pressed. The original code used the same subroutine no matter which pin was detected to be low. I thought it would be better to use separate subroutines in order to limit the number of pins to check.
I'm not sure how your key pad works. The original code seems very inefficient for finding which key was pressed. I thought it would be better to try to identify which group of keys were possibly pressed and then use a subroutine to identify which key in the group was pressed. Much of what I wrote as based on assumptions (not necessarily correct ones) of how your keypad works. Than "main" section of the code leads me to think you're using a keypad which uses some sort of matrix. But the code in "Top" looks like you're only checking individual pins. It's not clear to me how your keypad works. If your keypad uses a matrix then the code I posted may be useful however is it's not a matrix then you'll want to use a different strategy for finding which key was pressed.
The key press counter should to be monitored from the main loop.