Dick Cappels' project pages http://www.projects.cappels.org

Return to AttoBasic Page
 

Notes on Atto basic for the ATmega163 as of version 163-021115C and AT90S8515 as of version 8515-021115C.

Contents copyright 2002 Richard Cappels All rights reserved. Comments, suggestions, and bug reports should be addressed to projects@cappels.org

Atto basic was inspired by Nascom Microcomputer's Tiny Basic, though some features, such as cassette tape control, have not been implemented. Strings are and REM statements are not supported. Special functions have been added to provide access to the on-chip features such as EEPROM program storage, I/O port access, pulse width modulator control, analog comparator output access, the abillity to read the A-to-D converter, and a rudimentary DS Interface are provided. Access to all I/O, on chip peripherals and RAM allocated for array storage are supported via POKE and PEEK commands.

The language is a byte wide basic for simple control experiments. It supports 26 variables (A..Z) and limited unassigned byte wide arithmetic and relational operators. Subroutine calls and FOR_NEXT loops are supported but nesting is not allowed. Line numbers in the range of 0..255 are allowed. The input line buffer is 60 characters long.

HARDWARE CONSIDERATIONS:

This firmware is intended to run on Atmel ATmega163 operating at 3.69 MHz (for the STK-500), 4.00 Mhz, and 8.00 MHz or an AT90S8515 operating at 3.69 MHz (also for the STK-500) or 8 Mhz.  This means that an external crystal options needs to be selected during programming. "EXT XTAL, Startup: 67ms + 16 CK" works satisfactorily.

The ATmega163 provides 499 bytes of program memory. The AT90S8515 provides 298 bytes of program storage but does not have an A-to-Converter.

Communications with the terminal is via RS-232 at 9600 baud. Use 8 data bits, 1 stop bit, and no parity. The RXD and TXD pins should be connected to an inverting RS-232 interface. The Maxim MAX-232 and the discreet interface shown in ATmel Application note AVR-910 are examples of such interfaces.

A rudimentary DS Interface is implemented on PORT D. The Attention signal is on PD3 and the Data signal in on PD4. Weak internal pull-ups are provided on these pins, but external pull up resistors of a few thousand ohms are suggested unless you application is proven to not need them.

If the RXD pin is grounded when the chip comes out of reset, either from application of power or after an external reset,  the contents of the EEPROM will be loaded and executed by the interpreter. A program started this way may be stopped with a control-c keyboard combination. After the program is stopped, the interpeter will reinitialize itself, leaving the program RAM clear.

A weak internal pull-up  is applied to the RXD pin.

If a passive pull-up is used on the RXD pin, as opposed to an active device such as the output of a MAX-232, by using three  additional external components, the chip can be made to automatically execute the program in EEPROM by holding the RXD pin low for a short time after the application  of power, while not precluding input from the terminal by using the following circuit.

1. From the RXD pin connect the anode of a small signal diode, such as a 1N4148 or 1N916.

2. Connect the cathode of the diode, to the positive end of a 22 uf capacitor and ground the negative end of the capacitor.

3. Connect a 100K resistor from the positive end of the capacitor (and thus also the cathode of the diode) to +5 volts.

The LOAD and SAVE commands allow the contents of the program memory to be stored in the on-chip EEPROM (Electrically  Erasable Programmable Read Only Memory) and loaded for later editing or execution. If the contents of the EEPROM is loaded when the EEPROM is in an erased state some of  the internal pointers may be set inappropriately, so it is advisable to type "NEW" to initialize the pointers and then typing "SAVE" to store the initialized memory space into the EEPROM.

It is possible for the contents of the EEPROM to become corrupted, particularly if power is  lost during a SAVE operation, resulting in a program that does not execute correctly. The nature of the corruption may not be visible when listing the  program, but might be visible using the DUMP command.

Instruction set of the interpreter:

----------------------control----------------------
CONTROL-C.......... THE CONTROL-C KEYBOARD COMBINATION HALTS PROGRAM OPERATION
CONTROL-S..........  THE CONTROL-S KEYBOARD COMBINATION STOPS THE PROGRAM UNTIL ANOTHER KEY IS PRESSED
NEW..........  NEW PROGRAM EX: NEW
LIST..........  LIST PROGRAM EX: LIST
PRINT..........  PRINT VALUE TO SCREEN EX: PRINT A
PRX..........  PRINT HEX EX: PRX 100 results in the output: 64
PRB..........  PRINT BINARY EX: PIB INB prints PINB in binary
$ (Dollar Sign)..........  CONVERT TWO FOLLOWING CHARACTERS FROM ASCII EX: A:=$31
KEY..........  GET KEY FROM TERMINAL EX: A := KEY ; or KEY (return) to pause.
EMIT..........  EMIT VALUE AS ASCII CHARACTER TO TERMINAL EX: EMIT $20 (sends a space)
RUN..........  RUN PROGRAM EX: RUN
IF-THEN..........  CONTROL STRUCTURE EX: IF A=31 THEN GOTO 100
FOR-TO-NEX.......... T LOOPING STRUCTURE EX: see below
GOSUB-RETURN..........  PROGRAM FLOW CONTROL EX: see below
GOTO PROGRAM..........  FLOW EX; GOTO 100
SIZE PRINT..........  REMAINING BYTES OF PROGRAM SPACE TO SCREEN EX: SIZE
DUMP..........  DUMP PROGRAM MEMORY IN HEX FORMAT EX: DUMP
END..........  STOP EXECUTION OF PROGRAM EX: END (this command is not required at end of program)
<backspace> .......... DESTRUCTIVE BACKSPACE DURING LINE EDITING
SAVE..........  SAVE PROGRAM TO EEPROM EX: SAVE
LOAD..........  LOAD PROGRAM FROM EEPROM EX: LOAD

----------------------operator/relational----------------------
:=..........  set equal to, LET instruction not needed)
=..........  used for evaluation as in IF a = b THEN...)
<>..........  not equal to
>..........  is greater than
<..........  is less than
-..........  subtraction, 8 bit unsigned
+ .......... addition, 8 bit
AND .......... logical AND between two 8 bit values
OR..........  logical OR between two 8 bit values
XOR..........  logical Exclusive OR between two 8 bit values
LSL..........  logical shift left
LSR..........  logical shift right

----------------------I/O----------------------
PEEK..........  READ VALUE OF MEMORY EX: PRX PEEK A,B
POKE..........  WRITE VALUE OF MEMORY EX: POKE A,$31; POKE VALUE,destination

OPA..........  OUTPUT PORT A EX: OPA $1A
SBA..........  SET BIT ON PORT A EX: SBA 3
CBA..........  CLEAR BIT ON PORT A EX: CBA 3
SDA..........  SET BIT IN DATA DIRECTION REGISTER A EX: SDA 3
CDA..........  CLEAR BIT IN DATA DIRECTION REGISTER A EX: CDA 3
ODA..........  OUTPUT DATA DIRECTION REGISTER A EX: ODA $FF
INA..........  INPUT PIN A EX: J:= INA
IBA..........  INPUT BIT FROM PORT A EX: IF IBA 2 THEN GOTO 100

OPB..........  OUTPUT PORT B EX: OPB $1A
SBB..........  SET BIT ON PORT B EX: SBB 3
CBB..........  CLEAR BIT ON PORT B EX: CBB 3
SDB..........  SET BIT IN DATA DIRECTION REGISTER B EX: SDB 3
CDB..........  CLEAR BIT IN DATA DIRECTION REGISTER B EX: CDB 3
ODB..........  OUTPUT DATA DIRECTION REGISTER B EX: ODB $FF
INB..........  INPUT PIN B EX: J:= INB
IBB..........  INPUT BIT FROM PORT B EX: IF IBB 2 THEN GOTO 100

OPC..........  OUTPUT PORT C EX: OPC $1A
SBC..........  SET BIT ON PORT C EX: SBC 3
CBC..........  CLEAR BIT ON PORT C EX: CBC 3
SDC..........  SET BIT IN DATA DIRECTION REGISTER C EX: SDC 3
CDC..........  CLEAR BIT IN DATA DIRECTION REGISTER C EX: CDC 3
ODC..........  OUTPUT DATA DIRECTION REGISTER C EX: ODC $FF
INC..........  INPUT PIN A EX: J:= INA
IBC..........  INPUT BIT FROM PORT C EX: IF IBC 2 THEN GOTO 100

OPD..........  OUTPUT PORT D EX: OPD $1A
SBD..........  SET BIT ON PORT D EX: SBD 3
CBD..........  CLEAR BIT ON PORT D EX: CBD 3
SDD..........  SET BIT IN DATA DIRECTION REGISTER D EX: SDD 3
CDD..........  CLEAR BIT IN DATA DIRECTION REGISTER D EX: CDD 3
ODD..........  OUTPUT DATA DIRECTION REGISTER D EX: ODD $FF
IND..........  INPUT PIN D EX: J:= IND
IBD..........  INPUT BIT FROM PORT D EX: IF IBD 2 THEN GOTO 100

PWM8..........  PULSE WIDTH MODULATION 8 BIT ON OC1A PIN EX: PWM 17
PWE..........  PWM EXTENDED 10 BIT PWM ON OC1A pin EX: PWE 2,00
PWO..........  PWM ON OC1A PIN OFF (does not affect any data direction register).
ACO..........  ANALOG COMPARATOR OUTPUT EX: IF ACO THEN PRINT A. Prints a if analog comparator output is high
ADC..........  8 bit ADC conversion EX: PRX ADC ; PRX ADC 9
DSDATA..........  Send byte over DS Interface as data EX: DSDATA A
DSCOMMAND..........  Send byte over DS Interface as a command EX: DSCOMMAND C
DSREAD..........  Read a byte from DS Interface EX: PRX DSREAD

----------------------------------------------------------------------------------------
COMMANDS:

If-Then structures may be set up with either of two alternate structures.
1. All on one line, such as "IF A = 2 THEN GOTO 10, or
2. if the "THEN" is omitted and the then is on a second line, as in:
" 10 IF A = B
20 goto 100
30 <next statement>"
where the line following the IF statement only executes if the statement is satisfied.

The relational operators, =, >, <, and <> return 0 if the test is true,
and a nonzero value if the test is false. This derives from the equals evaluation
being done by simple subtraction of the two values, thus when equal, the subtraction
yields zero. For example,
"print 7=2" results in the value 5 being displayed.
"print 7>2" results in the value 0 being displayed.
"print 2>7" results in the value 1 (a nonzero value) being displayed.
 

----------------------------------------------------------------------------------------
ENTERING PROGRAMS:

Available program space is 499 characters.

Lines may be edited before the return character is entered by using the backspace key.

Any line that has a numeral in the first column will be stored in the  program memory if there is room for it when the return character is received.

Any line that does not have a numeral in the first column will be interpreted immediately when the  return character is received.

Valid line numbers range from 0 to 255.

Lines are stored in the program memory in sequence corresponding to their line numbers.

Empty lines, or lines containing only numerals will not be stored.

Entering a line with a line number that corresponds to the line number of a line already in the program memory will result in  the line in the program memory being replaced by the new line.

Entering an empty line or a line that only contains numerals with a line number that corresponds to the line number of a line  already in the program memory will result in the line in the program memory being deleted.

Commands may be entered in either upper-case or lower-case as they are all converted to upper case when read by the interpreter.

The first three letters of a command may be used in place of the entire command in the case of  commands longer than three characters. Thus, "PRI" can substitute for "PRINT".

Commands and numbers need to be delimited so the parser can tell them apart. Two formal delimiters supported are the space character and the comma. Numbers and letters are informally delimited  and so do not need formal delimiters. Thus,

The order of execution of line with more than one command or function on the line may  at times differ from other implementations of basic. An argument will take the results or arguments immediately following the command, as the following example illustrates.
-------------------------
LIST

10 POKE 100,$60
20 POKE 200,$62
30 PRINT PEEK $60 + 2
40 PRINT 2 + PEEK $60
 

Free pages:1 chars:167

>RUN
200
102
-------------------------

The "$" is an operator and needs to be formally delimited from other operators such a +.-,=, etc.

The "TO", as in "FOR A = 1 to 9" may be replaced with one or more spaces, thus the line: "FOR A = 1 9" is equivalent. The "TO" command is included as a convenience.

A RETURN command without a corresponding GOSUB has the same effect as END in that execution will stop.

The following examples may clarify some of the preceding.

OK: A=255
NOT OK: A=256

OK: PRINT $0F
NOT OK: PRINT $F (Result is garbage because $ expects two chars and does not check.)

OK: FOR A=
NOT OK: FORA= (can't tell the difference between the "FOR" and the "A")

OK: A:= $10
A:= $10+10
A:= A+ $10
B:= $31
PRX A+B
PRX $2A
PRX $10 + 10
PRX $2A + 9 + $0C + 21

OK: A= $3A
NOT OK: A=$3A (need a space between "=" and "$")

OK; PRINT A
NOT OK: PRINT A,B (print will only print the last value on a line)

OK: GOTO 25
GOTO $20 (but why would you want to?)
GOTO A
GOTO A+B
GOTO 2 + 2 + 5

----------------------------------------------------------------------------------------
Detailed list of commands:
 

==================================================
CONTROL-C...................User break

Pressing the control-C keyboard combination will interrupt and halt program execution.

==================================================
CONTROL-S...................Suspend output to terminal

Pressing the Control-S keyboard combination will during printing to the terminal will cause the microcontroller to suspend character output until another character is received from the terminal. If control-s is received during program execution, program execution will also be suspend until another character is received from the terminal.

==================================================
NEW...................NEW PROGRAM

EX:
>NEW
 

Action: Clears program memory and resets relevant pointers. Variables are not affected.

==================================================
LIST...................LIST PROGRAM

EX:
>LIST

Action: Lists contents of program memory.

This command dumps the entire program buffer.

List may be entered from the editor prompt.
EX:
>List

or it may included in a program.
EX:
10 LIST
 
 

==================================================
PRINT...................PRINT VALUE TO SCREEN
EX:
>PRINT A

Action: Prints a number to the terminal as a decimal number, range 0..255.

Arguments: One simple expression that can be evaluated as a number.

Usage: Only one argument is taken by the PRINT command, and this is the last number or the result of the last evaluation on a line. See the examples below.

This program:
>10 A:= 1
>20 B:=2 2
>30 PRINT A,B

results in the output: 2

This program:
>10 A:= 1
>20 B:=2 2
>30 PRINT A + B

results in the output: 3

PRINT prints only one value per line.
 

==================================================
PRX................... PRINT HEX

Similar in use to the PRINT command.
EX:
50 PRX 31

results in the output: $1F

==================================================
PRB ...................PRINT BINARY

Similar in use to the PRINT command.
EX:

50 PRB 4

results in the output: 00000100

==================================================
$ (Dollar sign)...................CONVERTS THE TWO CHARACTERS FOLLOWING FROM ASCII AS HEX
 

EX:
10 PRINT $1F

results in the output: 31

Dollar sign interprets the two characters following it as an hexadecimal representation of a byte. The only error that will be flagged is if the interpreter encounters the end of the line before two characters are converted. T

The parser sees the dollar sign character as the same type of character as the equal sign (=), thus must be separated from it by a delimiting space or comma.

OK: C:= $3A
NOT OK: C:=$3A

==================================================
KEY...................GET KEY FROM TERMINAL

EX: A := KEY

It is not necessary to utilize the value returned by KEY, thus KEY can be used to make the program pause then resume when a key is pressed.

EX:

50 Key

results in the program waiting until a character is received from the terminal.
 

EMIT EMIT VALUE AS ASCII CHARACTER TO TERMINAL

EX:

50 EMIT $20

results in a space character being sent to the terminal.

==================================================
RUN...................RUN PROGRAM

EX: (From command prompt)
>RUN

Note: Run may also be executed from within a program, but is of little utility and is likely to result in a stack overflow error.

==================================================
IF-THEN...................CONTROL STRUCTURE
 
 

If-Then structures may be set up with either of two alternate structures.
1. All on one line.

ED:
50 IF A = 2 THEN GOSTO 100
60 PRX PEEK A

results in the program jumping to line 100 when A is equal to 2, and execution continuing with line 60 when A is not equal to 2.
 

2. if the "THEN" is omitted from the line with the “IF” statement and the “THEN” part of the statement is on the line immediately following the “IF” statement.

EX:
" 10 IF A = B
20 GOTO 100
30 PRX PEEK A
where the line following the IF statement only executes if the statement is satisfied.

An alternative way or writing this second form, which uses more memory but may be more readable is to include the term “THEN” in the line following the with the
“IF” statement. The use of “THEN” in this case has no effect on the program.

EX:
" 10 IF A = B
20 THEN GOTO 100
30 PRX PEEK A

==================================================
FOR-TO-NEXT ...................LOOPING STRUCTURE

The “FOR” statement is followed by a a variable (A in the example below), which in turn is followed by an initial and terminal count for the loop. The program later executes a “NEXT” statement that increments the counter and returns program flow the statement immediately after the “FOR” statement. Lines between the “FOR” and “NEXT” statements are executed until the NEXT statement causes the variable to exceed the terminal value. The variable may be used for computational or indexing purposes.

EX:
10 FOR A = $70 TO $75
20 PRX PEEK A
30 NEXT

will result in the contents of memory locations $70 through $75 (112 through 117 decimal) being printed to the terminal.

To conserve memory, the word “TO” may be omitted, only using one or more delimiters between the parameters, so line 10 from the example above may alternatively be written as either:

10 FOR A = $70,$75

or as:

10 FOR A = $70 $75

without affecting the operation of the loop.

Only one return address for FOR-NEXT constructs is stored at a time, thus FOR-NEXT loops may not be nested. The return address storage for GOSUB is independent from that of FOR-NEXT, therefore one or more GOSUBS may be included in FOR-NEXT structures provided neither the FOR-NEXT constructs nor the GOSUB-RETURN constructs are not nested.

==================================================
GOSUB-RETURN ...................PROGRAM FLOW CONTROL

The GOSUB statement is followed by the line number of the subroutine to be executed. The subroutine ends with a RETURN statement, which will return program flow to the line following the line that called the subroutine.

EX:

10 FOR A = 1 TO 10
20 GOSUB 100
30 NEXT
40 END
100 PRINT A
110 RETURN
 

In the example above, the value of A is printed by the subroutine at line 100. The subroutine is terminated by at RETURN statement. The RETURN statement need not necessarily be on a separate line. For example, the following works:
EX:
100 PRINT A RETURN.

The GOTO destination can also be contained in a variable. In the example below, subroutines at locations 103, 106, and 109 will execute in sequence.

EX:
10 FOR Z = 1 TO 3
20 A := Z+Z+Z+100
30 GOSUB A
40 NEXT
50 END
103 PRINT 103
104 RETURN
106 PRINT 106
107 RETURN
109 PRINT 109
110 RETURN

 Only one return address for GOSUB-RETURN constructs is stored at a time, thus GOSUBS may not be nested. The return address  storage for the F OR-NEXT loop is independent from that of GOSUB-RETURN, therefore one or more GOSUBS may be included in FOR-NEXT structures provided  neither the FOR-NEXT constructs nor the GOSUB-RETURN constructs are not nested.
 

==================================================
GOTO...................PROGRAM FLOW
Unconditionally redirects program flow.

EX:

10 B = 19
20 A = 22
30 GOTO 100
40 B = 3
100 PRINT A+B

In the example above, the instruction at line 40 is not executed. Program flow jumps from line 40 to line 100.

The GOTO destination can also be contained in a variable, thus a GOTO destination can be computed.

10 A:= 100
20 GOTO A
30 END
100 PRINT 123

In the above example, line 20 program flow jumps to line 100.

==================================================
SIZE...................PRINT REMAINING BYTES OF PROGRAM SPACE TO SCREEN

EX:
>SIZE

SIZE may also be executed within a program.

DUMP HEX DUMP PROGRAM MEMORY TO TERMINAL

EX:
The
>dump

The full program memory is dumped to the terminal, followed by a carriage return, followed by two bytes pointing to the next available memory location.

==================================================
END...................END OF PROGRAM

When the program encounters an END command, it stops execution and outputs “Break “.
 

EX:
10 RPX PEEK $6D
20 END

>RUN
$52
Break
 

==================================================
PEEK ...................READ VALUE OF MEMORY
 

PEEK ADDRESS

PEEK provides the value contained in a memory location pointed to by the value following the PEEK command. The argument  evaluates to a byte wide pointer to an address in page 0 of memory. Page 0 includes all of the chips’s I/O and peripherals as well as the line buffer, variable storage,  and 58 bytes of RAM (Addresses $60 through $9A) which may be used in a program as an array.

EX:
10 PRX PEEK $60

The example above would cause the contents of the memory location $60
to be printed to the terminal.

POKE WRITE VALUE OF MEMORY

POKE VALUE,DESTINATION
 

EX:
10 POKE A,$60

The example again assigns the value of memory location $60 to variable A.

==================================================
POKE...................WRITE VALUE TO MEMORY

Writes a value the value to a memory location pointed. The address argument evaluates to a byte-wide pointer to an address in  page 0 of memory. Page 0 includes all of the chips’s I/O and peripherals as well as the line buffer, variable storage, and 58 bytes of RAM (Addresses $60  through $9A) which may be used in a program as an array.
 

<backspace> DESTRUCTIVE BACKSPACE DURING LINE EDITING

Deletes character just to the left of the cursor.

==================================================
SAVE SAVE PROGRAM TO EEPROM

EX: SAVE

SAVE saves the entire program memory space and relevant pointers to the on-chip EEPROM (Electrically Erasable Programmable  Read Only Memory).

SAVE can be executed from inside a program, but the program will stop execution after the SAVE statement is executed.

The on-chip EEPROM has a minimum guaranteed number of write cycles, after which the memory is not guaranteed by the  manufacture to function properly. The specified minimum, according on the ATmega163 data sheet is 100,000 write operations.

==================================================
LOAD ...................LOAD PROGRAM FROM EEPROM
 

LOAD loads the entire program memory space and relevant pointers from the on-chip EEPROM (Electrically Erasable Programmable Read Only Memory).

EX: LOAD

LOAD can be executed from inside a program, but the program will stop execution after the LOAD statement is executed.
 

==================================================
---------------------OPERATORS----------------

==================================================
:= ...................set equal to
 

This command is used to assign a value to a variable.
The use of “set equal” obviates the need for a LET command. The equal operator (“=”) is reserved for evaluation.

EX:
10 A := 123

The example above assigns the value 123 ot the variable, A.

==================================================
=  ...................Evaluate

The equal operator is used for evaluation of the relative magnitudes of two values.

The equal operator returns a value of 0 if the two values following it are equal and a nonzero value if they are no equal.

EX:
10 IF A = B THEN GOTO 100
20 END
100 PRINT 44

In the example above, the values of and an B are compared by the equal operator and if the value of A is equal to the value of B, program flow will be directed to line 100, otherwise the program will stop at line 20.
 

EX:
10 PRINT 2 = 3

In the example above, the value 1 will be printed to the terminal.

EX:
10 PRINT 2 = 2
 

In the example above, a nonzero value will be printed to the terminal.
 

==================================================
<>  ...................not equal to
 

The not equal to operator is used for evaluation of the relative magnitudes of two values.

The not-equal operator returns a value of 0 if the two values following it are equal and a nonzero value if they are not equal.

EX:
10 IF A <> B THEN GOTO 100
20 END
100 PRINT 44
In the example above, the values of and an B are compared by the equal operator and if the value of A is not equal to the value of B, program flow will be directed to line 100, otherwise the program will stop at line 20.

EX:
10 PRINT 2 <> 3

In the example above, the value 0 will be printed to the terminal.

EX:
10 PRINT 2<> 2
 

In the example above, a nonzero value will be printed to the terminal.
 

==================================================
>  ...................is greater than

The is greater than operator is used for evaluation of the relative magnitudes of two values.
 The equal operator returns a value of 0 if the first of the two values following the operator is larger than the second of the  two values following the operator, and will return a nonzero value if the first of the two values following the operator is not larger than the second value following  the operator.

EX:
10 IF A > B THEN GOTO 100
20 END
100 PRINT 44

In the example above, the values of and an B are compared by the is greater than operator and if the value of A is greater than  the value of B, program flow will be directed to line 100, otherwise the program will stop at line 20.
 

EX:
10 PRINT 2 > 1

In the example above, the value 0 will be printed to the terminal.

EX:
10 PRINT 2 > 2
 

In the example above, a nonzero value will be printed to the terminal.

==================================================
<  ...................is less than

The is less than operator is used for evaluation of the relative magnitudes of two values.

The equal operator returns a value of 0 if the first of the two values following the operator is smaller than the second of the  two values following the operator, and will return a nonzero value if the first of the two values following the operator is not smaller than the second value following  the operator.

EX:
10 IF A < B THEN GOTO 100
20 END
100 PRINT 44

In the example above, the values of and an B are compared by the is less than operator and if the value of A is less than the  value of B, program flow will be directed to line 100, otherwise the program will stop at line 20.
 

EX:
10 PRINT 2 < 3

In the example above, the value 0 will be printed to the terminal.

EX:
10 PRINT 2 < 2
 

In the example above, a nonzero value will be printed to the terminal.

==================================================
-  ...................subtraction, 8 bit unsigned

The subtract operator provides the result of the unsigned subtraction of two bytes.

EX:
10 PRINT 3 - 2

The above example will result in the value 1 being printed to the terminal.

EX:
10 PRINT 2 - 3

The above example will result in the value 255 being printed to the terminal.
 

==================================================
+ ................... addition, 8 bit
 

The addition operator provides the result of the addition of two bytes.

EX:
10 PRINT 3 + 2

The above example will result in the value 5 being printed to the terminal.

EX:
10 PRINT 255 + 3

The above example will result in the value 2 being printed to the terminal.
 
 
 

==================================================
AND  ...................logical AND between two 8 bit values

The AND operator provides the result of a bit-wise logical AND of two bytes.

EX:
10 PRINT 5 AND 2

The above example will result in the value 1 being printed to the terminal.

==================================================
OR  ...................logical OR between two 8 bit values

The OR operator provides the result of a bit-wise logical OR of two bytes.

EX:
10 PRINT 5 OR 2

The above example will result in the value 7 being printed to the terminal.
 

EX:
10 PRINT 5 OR 1

The above example will result in the value 5 being printed to the terminal.

==================================================
XOR ...................logical Exclusive OR between two 8 bit values
 

The XOR operator provides the result of a bit-wise logical EXCLUSIVE-OR of two bytes.

EX:
10 PRINT $A5 XOR $5A

The above example will result in the value 255 being printed to the terminal.
 

EX:
10 PRINT 2 XOR 3

The above example will result in the value 1 being printed to the terminal.

==================================================
LSL  ...................logical shift left
 
 

The LSL operator provides the result of shifting a byte to the left one bit position.

EX:
10 PRINT LSL 4
The above example will result in the value 8 being printed to the terminal.
 

==================================================
LSR  ...................logical shift right
 

The LSR operator provides the result of shifting a byte to the left one bit position.

EX:
10 PRINT LSR 8
The above example will result in the value 84 being printed to the terminal.
 
 

---------------------I/O---------------------

==================================================
PWM8  ...................PULSE WIDTH MODULATION 8 BIT ON OC1A PIN
 

EX:
10 PWM8 17

The above example would output a 17/256 duty cycle pulse, which when filtered would produce about 373 mv when operating from a 5.00 volt power supply.

The command is more conventionally typed with the three letter abbreviation, as an example:

10 pwm 17

This command configures PORTD BIT 5/OC1A PIN  as an output.

The PWM8 command uses timer-counter 1.

==================================================
PWE  ...................PWM EXTENDED 10 BIT PWM ON OC1A PIN
 

The command, PWE is followed by two parameters which are the high two bits and the lower 8 bits respectively of the 10 bit PWM value to be output on the OC1A pin.

EX:
10 PWE $02,$1F
 

The above example would output a 543/1024 duty cycle pulse, which when filtered would produce about 265 mv when operating from a 5.00 volt power supply.

This command configures PORTD BIT 5/OC1A (ATMEGA163 PIN 19) as an output.

The PWME command uses timer-counter 1.

==================================================
PWO  ...................PWM ON OC1A pin is turned off OFF
 

EX:
10 PWO

Stops the pwm pulses by stopping timer-counter 1 and disconnecting it from the OC1A pin. This command does not affect the direction of PORTD BIT 5 (Atmega163
19).
 

==================================================
OPA  ...................OUTPUT BYTE TO PORT A
OPB  ...................OUTPUT BYTE TO PORT B
OPC  ...................OUTPUT BYTE TO PORT C
OPD  ...................OUTPUT BYTE TO PORT D

OPA writes a value to output port A.

EX:
10 OPA $F0

In the example above, the highest four bits (bits 4..7) are set high and the lower 4 bits (bits 0..3) are set low. I/O pins have  multiple uses, so check the data sheet for the microcontroller.

==================================================
ODA   ...................OUTPUT DATA DIRECTION REGISTER A
ODB   ...................OUTPUT DATA DIRECTION REGISTER B
ODC  ................... OUTPUT DATA DIRECTION REGISTER C
ODD   ...................OUTPUT DATA DIRECTION REGISTER D

ODA writes a value to DATA DIRECTION REGISTER A (DDRA)

EX:
10 ODA $F0

In the example above, the highest four bits (bits 4..7) are set as outputs and the lower 4 bits (bits 0..3) are set inputs. There  are interactions between the state of the data bits on the associated output port and the electrical characteristics of the I/O pins when configured and inputs, so  check the data sheet for the microcontroller for details.

==================================================
INA  ................... INPUT BYTE FROM PIN A
INB   ...................INPUT BYTE FROM PIN B
INC   ...................INPUT BYTE FROM PIN C
IND  ................... INPUT BYTE FROM PIN D
 

INA provides the value on the inputs pins on PORT A (PINA).

EX:
10 PRINT INA

In the example above, the data on input PORT A is printed to the terminal.

EX:
10 PRB INA
20 GOTO 10

>RUN
00011110
00000110
00000000
00000000
Break

>In the example above, the value on the PORT A pins are continually sent to the terminal in binary format.
 

==================================================
SBA   ...................SET BIT ON PORT A
SBB   ...................SET BIT ON PORT B
SBC  ....................SET BIT ON PORT C
SBD  ....................SET BIT ON PORT D

EX:
10 SBA 3

In the example above. bit 3 of PORTA is set to logic high.

==================================================
CBA ....................CLEAR BIT ON PORT A
CBB ....................CLEAR BIT ON PORT B
CBC ....................CLEAR BIT ON PORT C
CBD ....................CLEAR BIT ON PORT D

EX:
10 CBA 3
 

In the example above, bit 3 of PORT A is cleared to logic low.
==================================================
SDA ....................SET BIT IN DATA DIRECTION REGISTER A
SDB ....................SET BIT IN DATA DIRECTION REGISTER B
SDC ....................SET BIT IN DATA DIRECTION REGISTER C
SDD ....................SET BIT IN DATA DIRECTION REGISTER D

EX:
10 SDA 3

In the example above, bit 3 of PORT A is set as an output.
==================================================
CDA ....................CLEAR BIT IN DATA DIRECTION REGISTER A
CDB ....................CLEAR BIT IN DATA DIRECTION REGISTER B
CDC ....................CLEAR BIT IN DATA DIRECTION REGISTER C
CDD ....................CLEAR BIT IN DATA DIRECTION REGISTER D

EX:
10 CDA 3

In the example above, bit 3 of PORT A is set as an input.

==================================================
IBA ....................INPUT BIT FROM PORT A
IBB ....................INPUT BIT FROM PORT C
IBC ....................INPUT BIT FROM PORT D
IBD ....................INPUT BIT FROM PORT D

Returns the inverse of the state of the designated bit on port A

EX:
IF IBA 2 THEN GOTO 100

In the example above, if PORTA BIT 2 is high, the program will branch to line 100.

EX:
PRINT IBA 2

In the example above, if PORTA BIT 2 is high, a value of 0 will be printed to the terminal, and if PORTA Bit 2 is low, a value of 1 will be printed to the terminal.

The valid range for the argument is 0..7, corresponding to the 8 possible bit positions.
 

ACO ANALOG COMPARATOR OUTPUT EX: IF ACO THEN PRINT A.

The ACO operator provides the inverted state of the on-chip analog comparator. If the output is high, the returned value is 0, if the output is low, the returned value is 1. The ACO command does not change and data direction pins.

EX:
10 IF ACO THEN GOTO 100
20 PRINT 0
30 GOTO 10
100 PRINT 1
110 GOTO 10

In the above example, the program repetitively samples the comparator output and prints 1 to the terminal when the comparator's output is high and prints 0 to the terminal when the comparator's output is low. Note this program can be stopped by typing control-c on the terminal keyboard.

See the microcontroller data sheet for the comparator's electrical characteristics and details of comparator operation.

==================================================
ADC READ 8 BIT A/D CONVERTER

The ADC operator returns the value of an 8 bit measurement from the on-chip A-to-D converter, using the on-chip 2.56 volt reference. The sensitivity is 10 mv per lsb. If no parameter is given following the ADC operator, AD0 (Atmega163 pin 40) will be measured.
 

EX:
print ADC

The example above will print the measurement of the analog voltage on analog comparator input 0 (ATmega163 pin 20 in the DIP package).

EX:
10 IF ACO THEN GOTO 100
20 PRINT 0
30 GOTO 10
100 PRINT 1
110 GOTO 10

The example above will print measurements of analog channels 0 through 7 (ATmega163 pins 40 through 33 of the DIP package, respectively) to the terminal.

The on-chip A-to-D converter is very flexible and can be used in other modes using the PEEK and POKE commands. See the microcontroller data sheet for details of the electrical characteristics and details of operation of the A-to-D converter.

==================================================
DSDATA ..............................Send byte over DS Interface as data
DSCOMMAND ....................Send byte over DS Interface as a command
DSREAD ..............................Read a byte from DS Interface

Rudimentary DS Interface commands. DS Interface bytes are sent as either comamnds or data to the slave device and separate  instructions, DSCOMMAND and DSDATA are employed for these respective purposed. Data are read from the DS Interface with a single command, DSREAD, it being  assumed that the slave will not send commands.

DSDATA and DSCOMMAND take an argument following the instruction and send it via the DS Interface as data or a command  respectively.

DSREAD returns a value after the DS Interface accepts it from the DS Interface device. If the DS Interface device (slave). This  instruction can only read data if the DS INterface device (slave) is in the process of sending data.

EX:
10 DSDATA $A5 Send $A5 to DS Interface device (to slave)
20 DSCOMMAND $12 Send command to store data in register 2
30 DSCOMMAND $22 Send command to send register 2 to host
40 PRX DSREAD Fetch data from DS Interface and print in hex format

Below, is the example above, typed using short form (three character notation).                                                                               

EX:
10 DSD $A5
20 DSC $12
30 DSC $22
30 PRX DSR
 

EX:
10 FOR A = $20 TO $2F
20 DSCOMMAND A
30 PRINT DSRECEIVE
40 NEXT

The example above prints the 16 directly addressable DS Interface registers to the screen.

These instructions will cause interpreter to hang if used improperly or if the DS Interface device (slave) is not correctly  connected and operating. If interpreter hangs, it will be necessary to initiate hardware reset. The DS Interface is as follows: Attention = PD3, Data = PD4.

-end of document-
 
  Copyright 2002, 2003 Richard Cappels

Return to  AttoBasic Page