Tiny Machine Basic Tutorial

Industrologic, Inc.
3201 Highgate Lane
St. Charles, MO
63301
USA

Phone: (636) 723-4000
www.industrologic.com
info@industrologic.com



Trademark and Copyright Information

Tiny Machine Basic and TMB are Trademarks of Industrologic, Inc. 2000. This document is Copyright (c) 2000-2015 by Industrologic, Inc. All rights reserved.

No part of this manual may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying or scanning, for any purpose other than the personal use by the purchaser of this product. Industrologic, Inc. reserves the right to revise this document at any time without obligation to notify any person of such revision. Industrologic, Inc. assumes no responsibility for any errors that may appear in this document.



Warning/Disclaimer

Whereas effort has been made to make the information in this document as useful and accurate as possible, Industrologic, Inc. assumes no responsibility for the application, usefulness, or completeness, of the information contained herein. Under no circumstance will Industrologic, Inc. be responsible or liable for any damages or losses including indirect or consequential damages or losses arising from either the use of any information contained within this manual or the use of any products or services referenced within this manual.



Introduction

If you have purchased one of Industrologic's products that includes a microcontroller with Tiny Machine Basic, this guide will help get you started. Industrologic has created a customized version of Tiny Machine Basic for each of its microcontroller boards in order to take advantage of the specific hardware on each board, therefore each version will be slightly different. However, to keep things simple this guide will refer only to information common to all versions. Once you have written a few simple programs you will need to refer to the documentation supplied with your product to learn about the features of Tiny Machine Basic specific to that board.



Information specific to Tiny Machine Basic

The "prompt" - If Tiny Machine Basic is not already running your program, it displays a prompt, which is the "greater than" (>) character. This means that it is "prompting" you to enter an instruction or begin entering a program. If you like you can enter instructions one at a time to see what they do. You simply need to type the instruction name and hit the ENTER key.

Programs in Tiny Machine Basic use "line numbers" to identify instructions. When Tiny Machine Basic runs your program it begins with the lowest line number it finds. To write one line of your program you would type a line number, a space, the instruction, and the ENTER key. (Programs can also be loaded automatically from software running on your PC.)

Special instructions - There are a few instructions that you will need every time you use Tiny Machine Basic, but these instructions should never actually be part of a program. They should only be used at the prompt or without a line number.

NEW - This erases all of your program lines in preparation for entering a new program
RUN - This tells Tiny Machine Basic to run your program once entered (or loaded from the software running on the PC)
LIST - This displays your program to the screen for you to read (or to download and save)
BOOTON - This tells Tiny Machine Basic to run your program automatically when power is applied to the board.
BOOTOFF - This reverse the action of BOOTON and causes Tiny Machine Basic to return the prompt when power is applied.

Once the BOOTON instruction is used you will need to press the pushbutton switch on the board (or type a Control C for some boards) while applying power in order to return to the prompt. Refer to the Tiny Machine Basic manual for the board.



Changing the communication parameters

The BAUD instruction is used to change the baud rate of a serial port in Tiny Machine Basic. (Some products also have a MODE instruction to change other communication parameters.) If you change the communication parameters they will remain changed unless changed again. The BAUD and MODE instructions may be used while running a program, but in most cases you will want to change them only at the command prompt. (This will of course require that any communication program used be changed to match.) If the pushbutton switch on the board is used to bypass the BOOTON instruction, it will also return a prompt at the factory settings of 9600 baud, 8 bits, 1 stop bit, no parity, and no flow control (handshaking).



Getting your microcontroller product ready to program

Note: Use a baud rate of 9600 or less for programming.

  1. Connect the board to an RS-232 serial port on your IBM PC compatible computer with the included cable.
  2. Connect the wallblock power supply to the board and apply power.
  3. Install the CD included with your product and view the README.TXT file. which explains the contents of the disk. (You can either use the installation program on the CD or manually copy the files you need to a folder on your computer.)
  4. Run the communication program called TERMBAS.EXE.
  5. Select the Com port according to which RS-232 port you used on the computer.
  6. Hit the ENTER key, and if everything has been set up correctly you will see the Tiny Machine Basic prompt, the ">".
You are now ready to do any of the following:

Entering and running a simple program

At the prompt do the following:

You have just written a program that consists of a simple loop. You should now see the numbers 0 through 255 being continuously displayed.

To stop your program you can turn off power to the board and then turn it back on so that it displays the prompt again. (With some versions of Tiny Machine Basic you can stop the program by entering a "Control C" character, that is, holding down the "Ctrl" key while pressing the "C" key.)



Other example programs

In the first program, we were very specific about what you were supposed to type because you had never before entered a program, but for the rest of the programs in this guide we will simply list the program lines much like the LIST instruction would do once your program was entered. Enter these programs just like you did the first one, ending each line with the ENTER key. (The left column is the only part to enter. The right column explains the instruction.) Before entering a program remember to use the NEW instruction to erase the old one, and after entering the new program use the RUN instruction to start it.



Example of how to check for a key pressed:

1 A=KEY        if a key is pressed put value in variable A (zero if no key pressed)
2 IF A=0 1     if A is zero go back to line 1 (this is a conditional branch)
3 PRINT A      display value of the key which is in variable A (try the Esc key)
6 GOTO 1       go to line 1 (this creates a loop from line 1 to line 6)

Add these lines to the above program:

4 A=A-27       subtract the value for the Escape key
5 IF A=0 10    if variable A is zero (used to be 27) go to line 10 (program will end)

This method will allow the Escape key to exit the loop. No power cycling necessary to return to the prompt.



Example of a time delay in a program:

1 PRINT "X"    display the X character (could be any character)
2 DELAY 20     delay 20 tenths of a second (2 seconds)
5 GOTO 1       go to line 1

Add these lines to the above program:

3 PRINT 13     send the "carriage return" character
4 PRINT 10     send the "line feed" character

These are two special control characters that must be sent to go to the next line of the display.



This is an example of how to make the program wait for you to enter a number from 0 to 255 at the keyboard and then use the value in the program. (Remember, a number cannot include any of the alphabet or punctuation characters.) It also shows how LOOP and ENDLOOP work to do something a specified number of times:

1 INPUT A      wait for a value to be entered followed by ENTER key
2 LOOP A       initiate a loop for the number of times in variable A
3 PRINT "X"    display the X character (could be any character)
4 ENDLOOP      this marks the end of the loop
5 GOTO 1       go to line 1



This is an example of how to have a main program call a subroutine:

1 A=10         put the value 10 into variable A
2 GOSUB 20     call the subroutine at line 20
3 A=15         put the value 15 into variable A
4 GOSUB 20     call the subroutine at line 20
5 DELAY 10     delay 10 tenths of a second (1 second)
6 GOTO 1       go to line 1
20 LOOP A      initiate a loop for the number of times in variable A
21 PRINT "X"   display the X character (could be any character)
22 ENDLOOP     this marks the end of the loop
23 PRINT 13    send the "carriage return" character
24 PRINT 10    send the "line feed" character
25 RETURN      must be at the end of every subroutine



Remember, these example programs used only those instructions common to all version of Tiny Machine Basic, but there are a lot more. What you should now do is to learn about the instructions related to the specific hardware of your particular microcontroller board by referring to the Tiny Machine Basic documentation you received with your board. Using what you have learned from these simple example programs will allow you to better understand how to use these additional instructions.



Writing programs in a text editor

The previous program examples have all been written while at the Tiny Machine Basic prompt, and have been entered directly into the Tiny Machine Basic program storage area. Although this works well for short programs, there is a much better way to write programs that allows you to save the programs on your PC. Since Tiny Machine Basic programs are text only you can use a "text editor" program to create, edit, and save your programs. There are a number of text editors available including some that are included with the PC operating system, like Windows Notepad. (If you use a "word processing" program to write programs, they must be saved as "plain text" and not in the word processing document format.)

The communication software included with Industrologic microcontroller products includes either a text editor (or a way to access a text editor) just for this purpose, along with an easy way to load your program into Tiny Machine Basic just as though you were entering it by typing at the prompt.



Using the NEW and BOOTON instructions in a text editor

Remember that the special instructions should be used only at the command prompt or without line numbers. Here is an example of how to use the NEW and BOOTON instructions in a program written in a text editor:

NEW               erases all program lines from any old program
1 PRINT "X"
2 DELAY 20
5 GOTO 1
BOOTON            runs your program when power is applied to board



end of manual
log file