DEBUG Examples

BS1 icon BS2 icon BS2e icon BS2sx icon BS2p icon BS2pe icon BS2px icon

Syntax: DEBUG

 

 

 

' DEBUG.BAS
' Demonstrates the use of the BS1 DEBUG instruction. The BS1 DEBUG defaults
' to decimal output and provides the name of the variable unless directed
' otherwise.

' {$STAMP BS1}
' {$PBASIC 1.0}

SYMBOL  addr    = B2                    ' EEPROM address
SYMBOL  char    = B3                    ' character to print

Messages:
  EEPROM ("The Parallax BASIC Stamp 1", 13, 0)


Main:
  char = "A"

  DEBUG CLS                             ' clear screen
  DEBUG char, CR                        ' standard decimal output
  DEBUG $char, CR                       ' hex ($)
  DEBUG %char, CR                       ' binary (%)
  DEBUG #char, CR                       ' value only (#)
  DEBUG "Your grade is: "               ' string
  DEBUG #@char, CR, CR                  ' value only, as ASCII (@)

  addr = 0                              ' point to message
  GOSUB Print_It
  DEBUG "The Parallax BASIC Stamp 1"    ' same message -- fast

  END

' This subroutine can be used to transmit a string stored in EEPROM to
' the DEBUG window. Note that this is very SLOW as for each character the
' entire DEBUG packet (97 bytes!) must be transmitted -- which means that
' you can transmit about five characters per second with this method.
'
' A better alternative to this subroutine is to BRANCH to DEBUG statements
' containing the entire string.

Print_It:
  READ addr, char                       ' get character from EEPROM
  addr = addr + 1                       ' point to next location
  IF char = 0 THEN Print_Done           ' if 0, terminate printing
  DEBUG #@char                          ' character to DEBUG window
  GOTO Print_It                         ' loop again

Print_Done:
  RETURN

 

This next demonstration illustrates sending information to and retrieving information from the Debug Terminal window. Also illustrated is the unique ability to accept any valid numeric format using the NUM modifier. To enter binary or hexadecimal values, the number must be preceded by "%" (binary) or "$" (hex).

NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.

' DEBUG_DEBUGIN.BS2
' This program demonstrates the ability to accept user input from the
' Debug Terminal, and to accept numeric entry in any valid format.

' {$STAMP BS2}
' {$PBASIC 2.5}

myNum           VAR     Word


Main:
  DO
    DEBUG CLS, "Enter a any number: "   ' prompt user
    DEBUGIN SNUM myNum                  ' accept number in any format

    DEBUG CRSRXY, 0, 2,                 ' display in all formats
          SDEC ? myNum,
          SHEX ? myNum,
          SBIN ? myNum
    PAUSE 3000
  LOOP                                  ' do it again
  END

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012