Shop OBEX P1 Docs P2 Docs Learn Events
How to limit the characters ? — Parallax Forums

How to limit the characters ?

Francis160791Francis160791 Posts: 28
edited 2013-11-07 16:36 in BASIC Stamp
i want to display only 6 characters on to my LCD. more then 6, then number cannot be display . how can i do it ? please help !

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-18 09:03
    You need to give more information. Examples would be helpful showing what you want to display.
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-18 10:22
    like i only want to display 6 number on my LED. thanks a lot mike green :)
  • Mike GreenMike Green Posts: 23,101
    edited 2013-10-18 10:55
    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?
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-18 11:02
    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
  • ercoerco Posts: 20,257
    edited 2013-10-18 12:30
    You could put a piece of black tape over the LCD so you can't see characters 7-20. :)

    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.
  • ElectrodudeElectrodude Posts: 1,660
    edited 2013-10-18 19:09
    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?
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-20 07:27
    yes electrodude !!! :D

    cause i try a lot , but still cannot work .
  • prof_brainoprof_braino Posts: 4,313
    edited 2013-10-20 08:59
    Place link to the datasheet for theLCD you are using. Without this information, it will be difficult to give useful information.
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-20 18:01
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-20 22:12
    Is the code you're using posted on this other thread?
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-20 22:21
    yes man. i need to limit the number to 6.
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-27 23:54
    anyone know to to limit the char ?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-28 01:18
    anyone know to to limit the char ?

    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.
    ' {$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.
  • Francis160791Francis160791 Posts: 28
    edited 2013-10-28 02:06
    i will try it first :D thanks a lot man :)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-10-28 08:08
    i will try it first :D thanks a lot man :)

    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:
    ELSE
        GOSUB noButtonPressed
    

    If no button press is detected then the counter needs to be set back to its original value.
  • Francis160791Francis160791 Posts: 28
    edited 2013-11-06 01:46
    can i use Display custom character 6 to limit my char ? from http://elmicro.com/files/parallax/seriallcd-v20.pdf. there is a table that can custom to 6.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-06 07:53
    can i use Display custom character 6 to limit my char ? from http://elmicro.com/files/parallax/seriallcd-v20.pdf. there is a table that can custom to 6.

    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.
  • Francis160791Francis160791 Posts: 28
    edited 2013-11-06 16:44
    i see. but i try the code . still cannot limit my char to 6. cause i just want to display 6 char on my LCD.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-06 16:59
    i see. but i try 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.
  • Francis160791Francis160791 Posts: 28
    edited 2013-11-06 17:01
    i trying the check6701 that time you gave me. still doing it .
  • Francis160791Francis160791 Posts: 28
    edited 2013-11-07 01:24
    may i know how does this code do "DispCC0 CON $00"
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-07 06:14
    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.
  • Francis160791Francis160791 Posts: 28
    edited 2013-11-07 16:36
    i see. but i will still try out with the code. thanks a lot Duane Degn. you help me a lot in my project :D
Sign In or Register to comment.