Tiny Machine Basic for the DR51 Single Board Computer

Reference Manual for Version 1.0

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. 2001
This document is Copyright (c) 2003 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.


Overview and General Information

Tiny Machine Basic for the DR51 (TMB-DR51) is a simple BASIC language interpreter with a limited syntax and list of instructions. TMB-DR51 is not so much a high level language like most BASIC interpreters, but is a cross between BASIC and machine language. It has been written specifically for the 8 bit structure of the Intel 8051 instruction set compatible families of microcontrollers, and for program storage in a small serial EEPROM.

TMB-DR51 includes features that make it easy to write and understand bit manipulation programs. When entering programs it will understand values entered in decimal or hexadecimal as well as single byte character strings. It also features commands that can change the display of number values from decimal to hexadecimal.

Instructions entered while programming are saved as two-byte tokenized instructions, not as BASIC source code, therefore, all instruction arguments and line numbers are limited to a single byte (values from 0 to 255). Values that exceed this limit at run time will "roll over" or "roll under" back to a byte value, and will not cause a run-time error. Similarly, instructions that use a limited range of values and are given values outside that range will not cause a run-time error, but will either ignore the instruction or convert the illegal value to a legal value.

A "command" consists of an instruction and its single byte "argument", and will be performed as soon as entered. A program line entry consists of a number from 1 to 255, a space, an instruction, and a single byte argument. Lower case characters are converted to upper case when typed since all instructions must be in upper case. Line numbers and arguments are always a single byte and can be entered as decimal values, e.g. x xx xxx xD xxD xxxD, hexadecimal values, e.g. xH xxH, or quoted single character strings, e.g. "x".

Instructions that manipulate the I/O port bits of the microcontroller must be used in ways that are compatible with the port hardware. If any port bit is to be used as an input, it must be set to a logic level "high" state, or "1". (On power up the port pins are set high.)

Comments may be added to program files created and saved on a host computer and uploaded, but the program saved in the DR51 will not contain comments. Comments must be on separate lines, and any line that does not begin with a program line number may be a comment. When comment lines are sent to the DR51 during program upload, syntax errors occur, and the lines are ignored.


Variables

The following is a list of variables in TMB-DR51 which are byte values that can be read or assigned values by the user program.

A, B, C, D   general purpose byte variables where certain operations are performed
E, F, G      and where the results of certain operations are stored
The following is a list of byte variables that can be read and displayed, but cannot be assigned values by the user program. The user program must read KEY often enough to insure that it contains current and valid values.

KEY    the ASCII value of the last character received at the
       Serial Port (cleared after being read)
(A)    a special description of variable A used to display the ASCII
       character rather than the numeric value

Instructions

The following is a list of instructions where [arg] is an argument to the instruction in the form of a byte variable, number, or ASCII character.

The command instructions will normally be used only as a command at the prompt, and the rest of the instructions will normally be used in a program, but may be used as a command at the prompt to see how the instruction works.

Command instructions:

BAUD=[arg]     Set baud rate of the Serial Port to [arg] times 100, and save in
               EEPROM. Allowable values are 192, 96, 48, 24, 12, 6, 3. (If you
               change the baud rate in TMB-DR51, you will also need to change it
               in your terminal software!)

Example:
BAUD=96        set the Serial Port baud rate to 9600


BOOTON         Run your program when TMB-DR51 starts (i.e., on power up)
BOOTOFF        Turn off the BOOTON feature (both are saved in EEPROM)
Note: The BOOTON feature can be overridden by connecting the two pins of J2 while power is applied to the DR51. TMB-DR51 will then return a prompt at 9600 baud (regardless of the baud rate specified with the BAUD instruction).

NEW            Erase all program lines
LIST           Display the program lines (if there are more than 20 lines the
               listing will pause until you press a key)
RUN            Run the program from the command prompt (>)
END            Stop the program and return to the prompt
The program can be stopped with the END instruction, by having no further lines to execute, (possibly by going to a non-existant line number above the rest of the lines), or by telling the program to go to line zero. If the program does not have a method of exiting in response to some program condition, the power will need to be cycled to return to the prompt.

Control and Program Flow instructions:

DELAY [arg]    Pause the program for [arg] tenths (1/10) of a second
GOTO [arg]     Jump to the instructions beginning at line number [arg]
GOSUB [arg]    Call subroutine at line number [arg] (1 layer deep only)
RETURN         Return to next instruction after the last GOSUB
LOOP [arg]     Begin a loop with [arg] iterations (1 layer deep only)
ENDLOOP        Terminate a loop
Subroutines and loops may only be one layer deep, that is, a subroutine may not contain another GOSUB instruction, and an ENDLOOP instruction must be performed before another LOOP instruction is performed.


Examples:
DELAY 255      delay 25.5 seconds

1 GOSUB 10     call subroutine at line 10
2 GOTO 1       jump to line 1
10 PRINT "A"   send an upper case A to the serial port
11 RETURN      jump to line following the GOSUB instruction

10 GOSUB A     call subroutine at the line number of the value of variable A
               (if the value of A is 20 it would be the same as GOSUB 20)

1 LOOP 255     start a loop of 255
2 PRINT "A"    send an upper case "A" to the serial port
3 ENDLOOP      jump back to line 2 until 255 loops have been done

Display and Keyboard instructions (Serial Port):

PRINT [arg]    Display a byte value in decimal/hexadecimal, or as character
               (This instruction sends characters out the serial port)
               See Appendix A for a table of these values

The PRINT instruction does not include a carriage return/line feed sequence (13D/10D or 0DH/0AH) after displaying a value or character like most BASIC languages. If either of these characters are desired they will need to be displayed separately. The PRINT instruction, when in HEX mode, will always display values with two digits followed by "H".

Lower case characters are converted to upper case when typed since all instructions must be in upper case. If a lower case displayable character is used as a value argument, the ASCII code must be used since it cannot be enclosed in quotes. For example, to print an "a" you must use PRINT 97 or PRINT 61H.

HEX            Display values in hexadecimal (try this at the command prompt)
DECIMAL        Display values in decimal (returns it to normal)
INPUT [arg]    Wait for a value to be entered (followed by a carriage return) and
               then put the value in [arg]. (This instruction waits for characters
               from the serial port). See Appendix A for a table of these values.

The ESCAPE key will cancel value entry with the INPUT instruction, (but not stop the program)


Examples:
PRINT 0DH      send a carriage return to the serial port
PRINT 13       send a carriage return to the serial port
PRINT 0AH      send a line feed to the serial port
PRINT 10       send a line feed to the serial port
PRINT "A"      send an upper case A to the serial port
PRINT 65       send an upper case A to the serial port
PRINT 97       send a lower case A to the serial port
INPUT A        wait for a value and then set variable A to that value
 
A=66           ASCII code for 'B"
PRINT (A)      send ASCII character "B" to serial port

Variable Manipulation instructions:

A=[arg]        Set byte variable A to [arg]
A=A+[arg]      Add the value in [arg] to variable A
A=A-[arg]      Subtract the value in [arg] from variable A
A=A*[arg]      Multiply variable A by the value in [arg]
A=A/[arg]      Divide variable A by the value in [arg], (remainder is discarded)
A=A\[arg]      Remainder of dividing variable A by the value in [arg]

IF A=0 [arg]   If variable A is zero jump to line number [arg]
IF A<>0 [arg]  If variable A is not zero jump to line number [arg]
IF A=B [arg]   If variable A equals variable B jump to line number [arg]
IF A<>B [arg]  If variable A does not equal variable B jump to line number [arg]
IF A<B [arg}   If variable A is less than variable B jump to line number [arg]
IF A>B [arg]   If variable A is greater than variable B jump to line number [arg]


Examples:
A=KEY          get value of last character at Serial Port 1
A=A-66         subtract the ASCII value for "B", which is 66
IF A=0 30      if character was "B" then jump to line 30

A=A+B          add the value of variable B to variable A
A=A+10         add 10 to variable A (e.g., if A contained 10 it would
               become 20, if A contained 255 it would roll over to 9)
A=A-1          subtract 1 from A (e.g., if A contained 2 it would
               become 1, if A contained 0 it would roll under to 255)
A=A*10         multiply variable A by 10 (e.g., if A contained 10 it would
               become 100, if A contained 30 it would roll over to 44)
A=A/5          divide variable A by 5 (e.g., if A contained 10 it would
               become 2, if A contained 202 it would become 40)
A=A\7          divide variable A by 7 and return the remainder in variable A
               (e.g., if A contained 10 it would become 3, if A contained 21 it
               would become 0)

IF A=0 10      if variable A is equal to 0 then jump to line 10
IF A<>0 15     if variable A is not equal to 0 then jump to line 15
IF A<B 20      if variable A is less than variable B then jump to line 20

Relay instructions:

RELAY1=[arg]   Turn on Relay 1 if [arg] is 1, off if 0 (uses bit 0 of [arg])
RELAY2=[arg]   Turn on Relay 2 if [arg] is 1, off if 0 (uses bit 0 of [arg])
RELAYS=[arg]   Change on/off status of both relays based on [arg], where
               Relays 2 and 1 are controlled by bits 1 and 0 of [arg] respectively

IF RELAY1=0 [arg]   If Relay 1 is off jump to line number [arg]
IF RELAY1=1 [arg]   If Relay 1 is on jump to line number [arg]
IF RELAY2=0 [arg]   If Relay 2 is off jump to line number [arg]
IF RELAY2=1 [arg]   If Relay 2 is on jump to line number [arg]


Examples:
RELAY1=1            turn on Relay 1
IF RELAY1=0 100     if Relay 1 is off jump to line number 100

LED instructions:

LED=[arg]        Turn on programmable LED if [arg] is 1, turn off if 0
                 (uses bit 0 of [arg])

IF LED=0 [arg]   If programmable LED is off jump to line number [arg]
IF LED=1 [arg]   If programmable LED is on jump to line number [arg]

Digital I/O instructions:

DO1=[arg]     Set digital I/O #1 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO2=[arg]     Set digital I/O #2 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO3=[arg]     Set digital I/O #3 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO4=[arg]     Set digital I/O #4 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO5=[arg]     Set digital I/O #5 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO6=[arg]     Set digital I/O #6 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO7=[arg]     Set digital I/O #7 high if [arg] is 1, low if 0 (uses bit 0 of [arg])
DO8=[arg]     Set digital I/O #8 high if [arg] is 1, low if 0 (uses bit 0 of [arg])

DO=[arg]      Set digital I/O #1-#8 to the byte value in [arg], with bit 0-7 = #1-8

If any digital I/O is to be used as an input, it must be set high, (its power up setting.)

READDI        Read digital I/O #1-#8 and put their byte value in variable A,
              where I/O #1-#8 = bits 0-7

IF DI1=0 [arg]   If digital I/O #1 is low jump to line number [arg]
IF DI1=1 [arg]   If digital I/O #1 is high jump to line number [arg]
IF DI2=0 [arg]   If digital I/O #2 is low jump to line number [arg]
IF DI2=1 [arg]   If digital I/O #2 is high jump to line number [arg]
IF DI3=0 [arg]   If digital I/O #3 is low jump to line number [arg]
IF DI3=1 [arg]   If digital I/O #3 is high jump to line number [arg]
IF DI4=0 [arg]   If digital I/O #4 is low jump to line number [arg]
IF DI4=1 [arg]   If digital I/O #4 is high jump to line number [arg]
IF DI5=0 [arg]   If digital I/O #5 is low jump to line number [arg]
IF DI5=1 [arg]   If digital I/O #5 is high jump to line number [arg]
IF DI6=0 [arg]   If digital I/O #6 is low jump to line number [arg]
IF DI6=1 [arg]   If digital I/O #6 is high jump to line number [arg]
IF DI7=0 [arg]   If digital I/O #7 is low jump to line number [arg]
IF DI7=1 [arg]   If digital I/O #7 is high jump to line number [arg]
IF DI8=0 [arg]   If digital I/O #8 is low jump to line number [arg]
IF DI8=1 [arg]   If digital I/O #8 is high jump to line number [arg]


Examples:
DO1=1          set digital I/O high for use as an input
IF DI1=0 100   if digital input #1 is low jump to line number 100

Keypad instructions:

The digital I/O signals can be used to read a keypad of up to 16 switches arranged as a 4 by 4 matrix with 8 connections to the I/O. If a keypad smaller than a 4 by 4 matrix is used, the digital I/O signals not used by the keypad may be used for other I/O purposes if the keypad configuration is properly done.

The following is a diagram of a typical 4 by 4 keypad switch matrix and how the switches are wired. The switches are identified by their "row" and "column" in the matrix. This diagram shows the rows and columns in a sequential order, but for manufacturing reasons many keypads have connections that are not in order. Documentation supplied with the keypad must be used in order to know which pins of the connector of the keypad (or other connections) are connected to which rows and columns.

keypad diagram

Before using the keypad instruction it must be told how the keypad switch matrix is connected to the digital I/O and also which character to return when a particular switch in the matrix is pressed. Program lines 230-237 and 240-255 are reserved for special PRINT instructions that tell the keypad instruction how to do this.

Program lines 230-237 specify which connection on the keypad is connected to which digital I/O, in this order: Row 1, row 2, row 3, row 4, column 1, column 2, column 3, and column 4. If a particular I/O signal is not used, for example, when using a keypad that is smaller than 4 by 4, its corresponding line should remain blank. (This assumes the NEW instruction was used before entering the program.)


Example:
230 PRINT 1    keypad row 1 is connected to digital I/O #1
231 PRINT 2    keypad row 2 is connected to digital I/O #2
232 PRINT 3    keypad row 3 is connected to digital I/O #3
233 PRINT 4    keypad row 4 is connected to digital I/O #4
234 PRINT 5    keypad column 1 is connected to digital I/O #5
235 PRINT 6    keypad column 2 is connected to digital I/O #6
236 PRINT 7    keypad column 3 is connected to digital I/O #7
237 PRINT 8    keypad column 4 is connected to digital I/O #8

Program lines 240-255 specify what character or ASCII value is returned when a particular switch is pressed. If any of the lines 240-255 do not contain a PRINT instruction, the character returned for that switch will be 255 decimal (FF hexadecimal). (This assumes the NEW instruction was used before entering the program.)


Example:
240 PRINT "1"  specify the character 1 with the switch at row 1 column 1
241 PRINT "2"  specify the character 2 with the switch at row 1 column 2
242 PRINT "3"  specify the character 3 with the switch at row 1 column 3
243 PRINT "A"  specify the character A with the switch at row 1 column 4
244 PRINT "4"  specify the character 4 with the switch at row 2 column 1
245 PRINT "5"  specify the character 5 with the switch at row 2 column 2
246 PRINT "6"  specify the character 6 with the switch at row 2 column 3
247 PRINT "B"  specify the character B with the switch at row 2 column 4
248 PRINT "7"  specify the character 7 with the switch at row 3 column 1
249 PRINT "8"  specify the character 8 with the switch at row 3 column 2
250 PRINT "9"  specify the character 9 with the switch at row 3 column 3
251 PRINT "C"  specify the character C with the switch at row 3 column 4
252 PRINT 27   specify the Escape character with the switch at row 4 column 1
253 PRINT "0"  specify the character 0 with the the switch at row 4 column 2
254 PRINT 13   specify a Carriage Return with the switch at row 4 column 3
255 PRINT "."  specify a period with the switch at row 4 column 4

When used to specify keypad characters the PRINT instruction works just like it does when displaying characters by sending them to the serial port. The character can be entered as a character enclosed in quotes or as a decimal or hexadecimal value.

READKP         Read the status of the keypad switch matrix and if a key is pressed
               place the associated character value for that key in variable B
               If a key is pressed when this instruction is used put the value 1
               variable A, otherwise put the value 0 in variable A

Example:
1 READKP       read the keypad
2 IF A=0 1     keep reading until a key is pressed
3 PRINT B      display the numeric value associated with the key
4 A=B          place value in variable A
5 PRINT (A)    display the character string

EEPROM instructions:

Part of the EEPROM used to store the user program can also be used to store program data such as configuration information that must be saved if the power is removed from the DR51. EEPROM addresses 1 through 255 correspond to TMB-DR51 line numbers 1 through 255. Using an EEPROM address will cause it to not be available for program line storage and will overwrite any program line stored there. Likewise, entering a program line at an EEPROM address will overwrite the data stored there.

When data is written to an EEPROM address, it is likely that the data will represent program instructions and arguments, which TMB-DR51 will attempt to RUN and LIST. In order to prevent the program from running this data as an instruction, an END instruction must be placed at a line number lower than any data address used so that the program will stop before reaching the data. If this is not done, the program may do any number of undesirable things, e.g., erasing itself or changing the baud rate unexpectedly. It is also suggested that the highest possible EEPROM addresses be used for data so that it is LISTED after the normal program lines.

Most EEPROMs may be written over a million times, but even this limit could be exceeded if the program wrote to the EEPROM in an unintended loop caused by incorrect programming, so some caution should be used. EEPROMs may be read an unlimited number of times.

WRITEEE [arg]  Write the 2 byte values in variables A and B to the EEPROM word at
               address [arg], where [arg] is an address from 1 to 255

READEE [arg]   Read the EEPROM word at address [arg] and put the 2 byte values in
               variables A and B, where [arg] is an address from 1 to 255

Examples:
A=FFH          set variable A value
B=FFH          set variable B value
WRITTEE 250    write A and B to memory location 250
READEE 255     read memory location 255 and place in variables A and B


Appendix A

The following is a table of character codes and their equivalent (ASCII) characters. These values are useful when using the PRINT instruction or when testing variables (like the variable KEY) for a specific character.

Decimal          Control Char. Control      Decimal               Decimal
Value   Character  Abbreviation  Key        Value   Character     Value   Character
-------------------------------------------------------------------------------------------
00      NULL                NUL  ^@         45      - (hyphen)    90      Z    
01      START OF HEADING    SOH  ^A         46      . (period)    91      [ (left bracket)
02      START OF TEXT       STX  ^B         47      /             92      \ (backslash)
03      END OF TEXT         ETX  ^C         48      0             93      ] (right bracket)
04      END OF TRANSMIT     EOT  ^D         49      1             94      ^ (carat)
05      ENQUIRY             ENQ  ^E         50      2             95      _ (underscore)
06      ACKNOWLEDGE         ACK  ^F         51      3             96      ` (accent)
07      BEEP                BEL  ^G         52      4             97      a
08      BACK SPACE          BS   ^H         53      5             98      b
09      HORIZONTAL TAB      HT   ^I         54      6             99      c
10      LINE FEED           LF   ^J         55      7             100     d
11      VERTICAL TAB        VT   ^K         56      8             101     e
12      FORM FEED           FF   ^L         57      9             102     f
13      CARRIAGE RETURN     CR   ^M         58      :             103     g
14      SHIFT OUT           SO   ^N         59      ;             104     h
15      SHIFT IN            SI   ^O         60      <             105     i
15      DEVICE LINK ESC     DLE  ^P         61      =             106     j
17      DC1 X-ON            DC1  ^Q         62      >             107     k
18      DC2                 DC2  ^R         63      ?             108     l
19      DC3 X-OFF           DC3  ^S         64      @             109     m
20      DC4                 DC4  ^T         65      A             110     n
21      NEG. ACKNOWLEDGE    NAK  ^U         66      B             111     o
22      SYNC. IDLE          SYN  ^V         67      C             112     p
23      END OF TX BLOCK     ETB  ^W         68      D             113     q
24      CANCEL              CAN  ^X         69      E             114     r
25      END MEDIUM          EM   ^Y         70      F             115     s
26      SUBSTITUTE          SUB  ^Z         71      G             116     t
27      ESCAPE              ESC             72      H             117     u
28      RIGHT ARROW (on PC)                 73      I             118     v
29      LEFT ARROW  (on PC)                 74      J             119     w
30      UP ARROW    (on PC)                 75      K             120     x
31      DOWN ARROW  (on PC)                 76      L             121     y
32      BLANK SPACE                         77      M             122     z
33      !                                   78      N             123     { (left brace)
34      " (double quote)                    79      O             124     | (vertical bar) 
35      # (number sign)                     80      P             125     } (right brace)
36      $                                   81      Q             126     ~ (tilde)
37      %                                   82      R             127     DELETE
38      &                                   83      S
39      ' (single quote)                    84      T
40      ( (open parenthesis)                85      U
41      ) (close parenthesis)               86      V
42      *                                   87      W
43      +                                   88      X
44      , (comma)                           89      Y


end of manual
log file