Wiki

Clone wiki

Terminal-BASIC / Home

About

Terminal-BASIC is a BASIC-like language interpreter for ATMega-based uc boards. Written in C++ using Arduino libs, it's not as lightweight as it should be, and not fits into 16k chips like ATMega168 at the moment. From the other side, unlike many existing projects, like TinyBASIC ports, it supports real numbers and multidimensional arrays.

The language core support BASIC control structures, input, output and basic arithmetics of integer and real numbers and arrays, input, output and concatenation of the strings. Extended functionality is available through the modules, that can be plugged to the core, adding new commands and functions (and eating up huge ammounts of the flash memory).

The architecture of the Terminal-BASIC is shown on the picture below: UML.png

The main interpreter object can be instantiated multiple times, using different Stream objects. So, on the multi-USART systems, like Atmega128 and Atmega2560, it is possible to create a multiterminal BASIC timesharing system.

Language reference

List of the commands

  • CLS clear screen and move cursor

  • DUMP [ARRAYS|VARS] debug info of BASIC memory, variables and arrays

  • LIST inputed program listing

  • LOAD load program from EEPROM

  • NEW clear BASIC memory

  • RUN run inputed program

  • SAVE save current program into EEPROM

Variables declaration:

LET ABC = 3

declares ABC real number variable (single precision)

LET Y% = 4

declares integer variable [-32768; 32767]

LET SS$="HELLO, WORLD"

declares string variable

Aray declaration

DIM AB$(3,3,3)

declares 3 dimensional array with each dimension from 0 to 3 of integer data

Aritmetics

LET A=3.0:LET B=2.0

PRINT (A+B)^(A*B)

prints 15625.00000000

DUMP VARS

prints

A: 3.00000000

B: 2.00000000

Program, which outputs a multiplication table

10 PRINT "MULTIPLICATION TABLE"
20 FOR I%=1 TO 9 STEP 1
30 FOR J%=1 TO 9 STEP 1
40 GOSUB 100
50 NEXT J%
60 NEXT I%
70 END
100 PRINT I%,"*",J%,"=",I%*J%
110 RETURN

This short form also works

10 FORI%=1TO9:FORJ%=1TO9
20 PRINTI%,J%,I%*J%
30 NEXTJ%:NEXTI%
40 END

Math module functions

  • ABS(arg) absolute value

  • ACS(arg) arccos

  • ATN(arg) atan

  • COS(arg) cos

  • COT(arg) ctg

  • EXP(arg) exponent

  • LOG(arg) natural logarithm

  • PI() return pi value

  • SIN(arg) sin

  • SQR(arg) square root

  • TAN(arg) tan

ArduinoIO module functions

  • AREAD(<PIN>) read analog value in volts (5V ref voltage)

  • AREAD%(<PIN>) read analog value in ADC units (as in the ADC data register)

  • DREAD(<PIN>) read digital value of pin

Usage

Downloads section contains precompiled images for different AVR boards. After programming the flash use following terminal settings:

  • Local echo ON

  • implicit CR

  • 57600 baud rate

Working program examples

1. Neuton method for finding extremums of the 1 argument function

10 PRINT "FUNCTION EXTREMUMS FINDING"
20 REM FUNCTION F(X) IS COMPUTED AT LINE 3000
30 REM FIRST DERIVATIVE F'(X) IS COMPUTED AT LINE 1000
40 REM SECOND DERIVATIVE F''(X) IS COMPUTED AT LINE 2000
50 PRINT "PRECISION:":INPUT E
60 PRINT "INITIAL VALUE:":INPUT Z
70 PRINT "":PRINT "SEQUATIONAL APPROXYMATIONS":PRINT"X","Z"
80 LET X=Z
90 GOSUB 1000:GOSUB 2000
100 LET Z=X-F/D
110 PRINT X,Z
120 IF ABS(Z-X)>E GOTO 80
130 PRINT " "
140 LETX=Z:GOSUB1000:GOSUB2000:GOSUB3000
150 IF D>0 THEN PRINT "MINIMUM:":GOTO190
160 IF D<0 THEN PRINT "MAXIMUM:":GOTO190
190 PRINT FF,"AT",X
200 END
1000 LET F=X-COS(X)
1010 RETURN
2000 LET D=1+SIN(X)
2010 RETURN
3000 LET FF=X^2/2-SIN(X)
3010 RETURN

Updated