Shop OBEX P1 Docs P2 Docs Learn Events
convert from QBASIC to PBASIC — Parallax Forums

convert from QBASIC to PBASIC

MYMMYM Posts: 9
edited 2005-10-24 14:30 in BASIC Stamp
I was wondering whether anyone can help me to program the following code, which is in QBASIC, to PBASIC.

BEGIN: cf = 0 
            df =0
Start:
CLS
LPRINT CHR$(cf);
PRINT "current floor =";
INPUT "enter destination-"; df
IF df > cf AND df <= 9 THEN GOTO Up
IF df < cf AND df >= 0 THEN GOTO Down
IF df = cf THEN GOTO Start
REM
Up: PRINT "elevator ascending"
DO
LPRINT CHR$(48 + cf);
SLEEP 1
DO
LPRINT CHR$(48 + cf);
IF NOT STRIG(1) THEN EXIT DO
LOOP
DO
LPRINT (48 + cf)
IF STRIG(1) THEN EXIT DO
LOOP
SOUND 440, 2
cf = cf + 1
PRINT "current floor="; cf
LPRINT (48 + cf)
LOOP UNTIL cf = df
GOTO Start
Down:
PRINT "elevator descending"
DO
PRINT CHR(64 + df);
SLEEP 1
DO 
LPRINT CHR$ (64 + df);
IF NOT STRIG(1)  THEN EXIT DO
LOOP
SOUND 40, 2
df = df + 1
cf = cf - 1
PRINT "destination floor="; cf
LPRINT (64 + df);
LOOP UNTIL df = df
GOTO Start
END




I am really just getting to know PBASIC and having a very difficult time moving toward PBASIC. So I would really appreciate it if anyone could help me. Thank You.

I am using BASIC STAMP EDITOR 2.2 and the BOE kit which includes the BS2.

NOTE: This program was created to control a model elevator using QBASIC.















[noparse][[/noparse]code]

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-21 22:18
    What does LPRINT do? I think the program is easily convertable, but I haven't used QBASIC in over 10 years so I don't remember how all the functions operate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Beau SchwabeBeau Schwabe Posts: 6,557
    edited 2005-10-21 22:44
    MYM,

    It's not exactly clear to me what you want to do with the converted program. Since LPRINT sends data to the printer port,
    do you want the Stamp to "talk" directly to the printer? If so, there is a bit more overhead involved.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • MYMMYM Posts: 9
    edited 2005-10-22 17:11
    Yes. I do want the stamp to "talk" directly to the printer.

    Thanks a lot for your help.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-22 17:52
    That's not going to be easy. Do you have the connections and signaling specifications?· How about starting with the Debug window first, and then moving to a printer?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-22 18:33
    MYM -

    Another method, which probably affords the quickest, easiest, and most flexible method of implementing the LPRINT QBASIC command on a PBASIC Stamp, without attempting to simulate a parallel port, is to change the LPRINT commands to SEROUT commands, convert (if necessary) any control codes, and output the data to a serial-to-parallel printer driver IC. This type of IC will also handle any control functions that may be necessary for your program to operate properly.

    One inexpensive choice (less than $14.00 US) is the EDE1400 or EDE1401 Printer Driver IC from ELABs. You can find the documentation here:
    http://www.elabinc.com/ then punch the EDE ICs button.

    Regards,

    Bruce Bates
  • MYMMYM Posts: 9
    edited 2005-10-24 12:33
    Thank You all for all your help.

    But I think it is better for me to do PBASIC from scratch and learn the basics before I start converting this and that without knowing all of the commands. (and there explanations ).
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-10-24 14:30
    Well, since the BS2 does not have a 'native' connection to a printer, that's not really part of the PBasic language.· That's why the earlier comments have been to add a printer interface chip to your design, and talk to it using a second serial port pin.

    However -- attached is a PBasic version of your program.

    Open one of the 'terminal' windows to see it in action.
Sign In or Register to comment.