EMBEDDED BASIC Feb 14, 2011 -------------------------- Program: All program lines must start with a line number. It is customary to use increments of 10 in case you want to add some lines in-between afterwords. Variables: Variable names must start with a letter, may contain letters and numbers, may be up to 8 characters long FOR..NEXT variables must be a single letter Variables are 32-bit signed integers Registers: DIRA Pin direction 0=INPUT; 1=OUTPUT - write-only OUTA Pin outputs 0=LOW; 1=HIGH - write-only INA Pin inputs 0=LOW; 1=HIGH - read-only CNT System counter - read-only CTRA, CTRB Counter mode - write-only FRQA, FRQB Counter frequency - write-only PHSA, PHSB Counter phase - write-only VCFG, VSCL Sets video generator - write-only INKEY Returns value of keypress - read-only VARS Address of variables - read-only CHARS Address of character bitmaps - read-only Pin I/O: INPUT, OUTPUT, HIGH, LOW, PIN For all commands that operate on hardware pins you can specify a range of pins by using MSB..LSB. For example to make pin 23 high use: HIGH 23 To make pins 24 thru 26 high use: HIGH 24..26 !!! NOTE if the MSB value is less than the LSB value, the bits will be reversed, this is the same as the spin language !!! Operators (in order of precedence): Parenthesis ( ) UNARY +, UNARY -, !, ABS, RND, PEEKB, PEEKW, PEEKL, PIN, .. SHL, SHR, ROL, ROR, SAR, REV & |, ^ *, /, // +, - =, <, >, <=, >=, <> NOT AND OR &, |, ^ are bitwise (AND,OR,XOR); "AND" and "OR" are logical AND and OR. 4 | 1 = 5 ; 4 OR 1 = -1 Commands: BCOLOR BCOLOR {expression} Sets the background color (see COLOR, FCOLOR) CLS CLS Clears the screen COLOR COLOR {expression} Sets both background and foreground colors with one value (see BCOLOR, FCOLOR) CONT CONT {expression} Continue program after ESC is pressed DATA DATA expression, expression, expression Define data to be read with READ (see READ, RESTORE) DEBUG DEBUG Shows line #'s as program runs DISPLAY DISPLAY 42 ' prints a "*" Prints ascii character. May use multiple paramters. Value 10 moves to next line and moves back to starting position (for multi line displays) DUMP DUMP Shows program bytes, press a key to stop END END Stops program and returns to command prompt FCOLOR FCOLOR {expression} Sets the foreground color (see COLOR, BCOLOR) FOR/TO/STEP FOR A = 1 TO 10 {STEP 1} (only single letter variable names) Creates a program loop GOSUB GOSUB 1000 Go to subroutine (see RETURN) GOTO GOTO 1000 Jumps to line HIGH HIGH 23 HIGH 23..26 Make pin(s) an output and high IF/THEN IF A = B THEN GOTO 1000 IF A <> B THEN c=1000:d=1000 If the condition is true, execute commands following THEN INPUT INPUT 23 INPUT 23..26 Make pin(s) an input LET LET A=A*10 LET A=PIN 27..24 Assigns a value to a variable. (LET is optional) LIST LIST LIST 1000 Show program listing (Press a key to stop) LOAD LOAD LOAD 1 Retrieves program from EEPROM, if 64K eeprom can use LOAD [1-4] LOCATE LOCATE 5, 10 Sets print location LOW LOW 23 LOW 23..26 Make pin(s) an output and low NEW NEW Clears program and displays version info NEXT NEXT A Adjusts value and loops back to FOR line NODEBUG NODEBUG Does NOT show line #'s as it runs (see DEBUG) OUTPUT OUTPUT 23 OUTPUT 23..26 Makes pin(S) an output PAUSE PAUSE 1000 Pauses for value milliseconds PIN PIN 23,1 PIN 27..24,15 Sets pin output state. NOTE: DOES NOT SET PIN TO OUTPUT POKEB POKEB a,100 Changes a byte of program memory (RAM, not EEPROM) POKEW POKEW a,1000 Changes a word of program memory (RAM, not EEPROM) POKEL POKEL a,100000 Changes a long of program memory (RAM, not EEPROM) PRINT PRINT PRINT a PRINT "The value is ";a Prints to the screen. READ READ A,B,C Reads data from the DATA lines REM REM This is a comment dirx = 1 ' set direction to 1 Comment RESTORE RESTORE RESTORE 1000 Set line that READ will start reading data from RETURN RETURN Return from subroutine RUN RUN RUN 1000 Runs program SAVE SAVE SAVE 1 SAVEs program to EEPROM, if 64K eeprom can use SAVE [1-4] NOTE: Single letter variable names are faster than multi-letter variable names FOR...NEXT is faster than GOTO GOTO needs to scan from the beginning to find the line # requested FOR does NOT have to be the first command on a line. 10 CLS: FOR a=1 TO 10:PRINT a:NEXT a x..y returns (x + y*256 + 11141120) 11141120 = $AA0000 and is just a unique number which means (this is a .. result) x..y - 0..0 = x + y*256