Tutorial - BASIC Stamp Debugging
Qwaszx72
Posts: 30
Here is a BASIC Stamp Debugging tutorial(As suggested by vaclav_sal):
What is DEBUGGING?
Through the use of the debug commands, you are able to detect accidental infinite loops; assure that the math or computations the BASIC Stamp is doing are being done correctly; find and then fix bugs or errors in your code; and altogether become a better programmer!
What is DEBUGGING?
Debugging is a simple way to locate and fix errors within your program. It is a very easy thing to do but if not done correctly or not done at all, it is very hard to find an error within your code
Through the use of the debug commands, you are able to detect accidental infinite loops; assure that the math or computations the BASIC Stamp is doing are being done correctly; find and then fix bugs or errors in your code; and altogether become a better programmer!
Comments
Debug - This command is used to send the value of variables or messages from the BASIC Stamp module to your computer for easy debugging.
Debugin - This is commonly used to send commands via your computer to your BASIC Stamp in order to test different parts of your code.
The debug command works on ALL BASIC Stamp modules.
The DEBUG command can send variables or values to your computer to be displayed in the Debug Window.
Here is a simple program that will send the value of the variable Debug_Data:
Formatters:
If you run this program, you will notice that the ASCII character #123("{") will show up in your debug screen. This is usually of no help when you want to know a numerical value. For example, if you would like to count how many times someone clicked a button, you would want to display a DECIMAL value of the variable.
To do this you would simply add a formatter before the variable:
In the above example you may notice in the line DEBUG DEC Debug_Data the "DEC" before Debug_Data. This tells your computer to display the decimal value of the variable.
All of the different formatters are listed below:
? - Displays "[Variable_Name] = [Variable_Value]"; by default the variable is displayed as a decimal value, but you can add a formatter before the "?" to display the variable in a different format(Example: BIN ? Debug_Data will display "Debug_Data = 1111011").***
ASC ? - Displays "[Variable_Name] = [Variable_Value]"; the variable will be displayed in the ASCII format.***
DEC - Displays decimal value, optionally fixed to 1-5 digits.*
HEX - Displays hexadecimal value, optionally fixed to 1-4 digits.**
BIN - Displays binary value of the variable, optionally fixed to 1-16 digits.**
STR - Displays ASCII string from the bytearray(An array of multiple bytes) until byte = 0(This will be when there are no more values stored in the array). Optionally add "\ [Amount of characters to display]" after the variable to only display a certain amount of bytes from the array.
REP - Displays the ASCII a certain amount of times. Must be in this format: "REP [Variable or ASCII character] \ [Amount of times to repeat].
* A "S" may be put before the formatter for a signed value.
** "S" for signed value and/or "I" for indicated value(The "I" must come before the "S" when displaying a Signed, Indicated value)
*** An automatic line feed will be added
Here is a program that demonstrates the uses of formatters:
Commands:
Sometimes, you will want to send Commands to your debug window in order to do certain things.
These commands are:
Clear Screen(CLS) - Clear the screen and place cursor at home position.
Home(HOME) - Place cursor at home in the upper-left corner or the screen.
Move To [x,y](CRSRXY) - Moves the cursor to a specified location.
Cursor Left(CRSRLF) - Move cursor left one character.
Cursor Right(CRSRRT) - Move cursor right one character.
Cursor Up(CRSRUP) - Move cursor up one character.
Cursor Down(CRSRDN) - Move cursor down one character.
Bell(BELL) - Beep the PC speaker.
Backspace(BKSP) - Back up cursor to left one space.
Tab(TAB) - Tab to the next column.
Line Feed(LF) - Move cursor down one line.
Clear to End of Line(CLREOL) - Clear line contents right of the cursor.
Clear Down(CLRDN) - Clear screen contents below the cursor.
Carriage Return(CR) - Move cursor to the beginning of the next line. This also moves everything to the right of the cursor to the next line.
Move To Column X(CRSRX) - Move cursor to specified column.
Move To Line Y(CRSRY) - Move cursor to specified line.
Here is a program that demonstrates the use of all the commands:
The debugin command only works on the BASIC Stamp 2 and up.
The DEBUGIN command will read keystrokes from your computer and send them to the BASIC Stamp module.
Here is a simple program that will get a byte sized value from the debug window and then subtract it from 65535 and send the result to the debug window:
If you look, the above program uses the same formatters for DEBUGIN as used in the DEBUG command. There are however two additional formatters: NUM and SNUM.
NUM - A generic numeric input. The user must indicate hex($), binary(%), or decimal(N/A) and then provide the value(Only $, %, 0 - 9, A - F accepted)
SNUM - Does the exact same thing as NUM yet allows for a signed value(-32768 to + 32767).
After any character not used in the formatter is given the value will be sent to the BASIC Stamp. If the BASIC Stamp uses a command like DEC5 then after 5 digits have been submitted, the value will be sent to the BASIC Stamp.
I will not go into much more detail on the formatters because they are the same as the DEBUG command.
Please post any comments, questions, or fixes that you wish. I will get back to you as soon as I can.
Also, if you would like me to create more tutorials, please do not be hesitant to reply asking me to do so. Just be sure to tell me what you would like the tutorial to be on.
Here are the links to my other tutorials:
Retrieving EEPROM Data From BASIC Stamp Modules
You are filling big void in BASIC Stamp programming.
I would suggest you always check the official terminology in Parallax documentation.
For example DEBUG is a command, DEC , ASC etc are formatters, CLS is a control character in DEBUG command.
I think you should avoid generic terms likes "data" or "send".
It is good to use simple terminology, but if you say " to set variable" that is exactly what you doing when using command "DEBUGIN variable".
I also think emphasizing command default options would be nice for a beginner to know.
Sample "DEBUG ? variable" is same as "DEBUG DEC ? variable"
I do not know your background but I would suggest you solicit a "technical and English " editor help before your next post.
Sorry, but I cannot help you with English and really do not have time for technical editing.
Too many honeydoos!!!
Keep it up. You are doing valuable service to the forum.
Vaclav
.
For example: using a debug statement after a variable is fine for finding out what it's value is. What if that value is wrong? Placing another debug cmd right before the suspect code can tell you what the value was before you make a change. Sometimes the output is incorrect because the input was incorrect to begin with.