Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Decimal Math Help! - Page 2 — Parallax Forums

BS2 Decimal Math Help!

2»

Comments

  • RGuyserRGuyser Posts: 90
    edited 2006-06-02 07:11
    Ok mike, here is what I have ended up with.. excuse the excessive code. I will try to edit out the fluff.

    I tried 2 different parallel 2x16 LCD displays (14-pin guys). Neither worked with the document on the parallax site. Know anything about black bars with Vin, and nothing with VDD?

    Thanks for the continued input. lemme know what you think.


    spI=8000 'Number of steps to move 1 inch
    spT=spI/1000 'Number of steps to move 1000th of an inch
    Pwdth=20 'Time to pause between steps

    '
    [noparse][[/noparse]Program]
    main:
    DEBUG CLS
    DEBUG "----Linear Mover v0----",CR
    DEBUG "(1)Move Table",CR
    DEBUG "(2)Settings",CR
    DEBUG "(3)Help",CR
    DEBUG "
    ",CR
    DEBUGIN DEC1 opt

    ON opt GOSUB main,move,settings,help


    move:
    DEBUG CR,"Distance to Travel(x.xxx): "
    DEBUGIN DEC1 inches ' Read in inches to travel
    DEBUG "." ' after inches entered, display a decimal point
    DEBUGIN DEC3 thous 'read in thous

    DEBUG CR,"Total: ", DEC1 inches,".",DEC3 thous,CR 'display distance to go
    DEBUG "
    ",CR
    DEBUG "Steps inch: ", DEC spI,CR
    DEBUG "Steps thou: ", DEC spT,CR
    DEBUG "Pulse Width: ", DEC Pwdth,CR
    DEBUG "
    ",CR
    DEBUG "Steps Taken :"


    compute:
    IF inches => 1 THEN
    FOR x = 1 TO inches
    FOR xstep= 1 TO spI
    DEBUG " ", CRSRX,14, DEC xstep 'Use this to watch each step
    HIGH 0
    PAUSE Pwdth
    LOW 0
    PAUSE Pwdth
    NEXT
    NEXT
    DEBUG CR
    ELSE
    ENDIF

    IF thous => 1 THEN
    FOR x = 1 TO thous
    FOR xxxstep= 1 TO spT
    DEBUG " ", CRSRX,14, DEC x 'Use this to watch each step
    HIGH 0 'Brings pin 0 high
    PAUSE Pwdth 'gives it some time
    LOW 0 'takes pin 0 back low
    PAUSE Pwdth 'gives it some time
    NEXT
    NEXT
    ELSE
    ENDIF

    PAUSE 4000
    GOTO main

    END
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-02 13:22
    This look like it will work although it will take nearly forever to step through an inch or any significant fraction with the DEBUG to watch each step. You don't need the ELSE if there's no "if not" statements and you don't really need the IF ... >= 1 THEN and ENDIF at all since the FOR statement will not execute the loop if the end value is less than the beginning value. Also, at the beginning you have an ON opt GOSUB. This should be ON opt GOTO since the routines come back via a GOTO rather than a RETURN. Also keep in mind that, if opt is invalid (here > 3) the ON statement "falls through".

    I've used the 2x16 parallel displays and they've always worked for me. Connect them up exactly as pictured in the Basic Stamp Manual in the section on the LCDCMD command. You do have to have this long initialization routine that's demonstrated in the LCDINIT.bsp example, but it should just work after that. I assume you have a BS2p, BS2pe, or BS2px since those are the Stamps with the built-in parallel LCD commands. If not, the datasheet (probably what you mentioned) at <http://www.parallax.com/dl/docs/prod/audiovis/lcd2x16par.pdf&gt; has complete examples using simpler commands. Also check out the Nuts and Volts articles on the Parallax website. They go into more detail on the parallel display.
  • RGuyserRGuyser Posts: 90
    edited 2006-06-02 23:54
    mike,

    thanks for the comments. i know the debug commands take forever. they will soon be gone, commented out... those if than =>s... i couldnt get it to work without them, but i will be rewriting all of this code anyways.. this was an experiment... as far as goto and gosub differences, i am learning quickly, but odnt know there differences between all the various methods of doing things. thank you!

    i got the LCD working. apparently they like 5v at most... 9v 'boils them'.(!!)

    i am using a BS2. this is actually all practice for using picbasic eventually. ivew got a few dozen pic micros, but I love the parallax community - so i have decided to try and get proficient at PBASIC first...

    With the code in that .pdf, it loads everything into eeprom first. i am having trtouble figuring out of this is completely nescisarry. the parallax code and schematic provided have very little background information. i can understand most of what it is doing, but not everything..

    it seems to me that data is loaded into the eeprom and autoamtically converted to some sort of ascii or hex or something, then reconverted when read back out into the LCD. is it not possible to make a subroutine that does this with word variables instead?

    i am concerned about the slower speed of eeprom memory, and the perishable nature...

    thank you!

    Robert.
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-05 02:39
    If you use DATA statements (read the section on them in the manual!) the PBasic compiler loads the data to your Stamp along with the program. If you have the latest PBasic compiler, you can prefix DATA items with WORD and it will use two successive bytes to store the 16 bit value. You can also use the WORD prefix in the READ statement and the Stamp will fetch both bytes and reassemble the value for you. You mentioned ascii or hex. Keep in mind that everything in the Stamp is stored as 8 bit bytes. The compiler allows you to write this information in a variety of formats (hex, decimal, 8 bit, 16 bit (as 2 8 bit bytes), etc.) and converts it all to a sequence of 8 bit values that are copied to the program EEPROM. You can use formatting prefixes in your output statements and the Stamp PBasic interpreter will convert these 8 or 16 bit values to a sequence of ascii characters that are actually displayed with the DEBUG, SEROUT, or LCDOUT (or other output statements). The program eeprom can be rewritten thousands of times without problems. Read speed is not a particular problem (it's as fast as anything else in the Stamp). Don't use any eeprom for data that will be rewritten more than a few thousand times. Most eeprom is good for over 100,000 cycles, but it's easy to make mistakes in your program that may cause this to be exceeded.
Sign In or Register to comment.