ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 2210
Скачиваний: 1
Programming
It can be hard to find an error that gives no error message. The best way to narrow the search is to write and test your programs in small modules, so that the amount of code to search through remains manageable.
The Microcontroller Idea Book |
71 |
Chapter 5
BASIC-52 Keywords by Function
The following is a quick reference to BASIC-52’s keywords, grouped by function. After this is a more detailed list, arranged alphabetically, with the syntax and a brief description of what each keyword does. Some of the keywords, like RUN, LIST, and PRINT, are ones that you’ll use constantly. A few, like NULL or UI0, have specialized uses that you may never need. Again, for a more complete reference, see the BASIC-52 programming manual.
Running and Listing Programs
CONT
LIST
NEW
RAM
REM
ROM
RROM
RUN
STOP
XFER
Storing Programs in NV Memory
FPROG
FPROG1-FPROG6
PGM
PROG
PROG1-PROG6
Program Control Structures
(loops and subroutines)
DO UNTIL
DO WHILE END
FOR TO [STEP] NEXT] GOSUB
GOTO
IF THEN [ELSE] ON GOSUB
ON GOTO
RETURN
Printing and Displaying Information on the Host Computer
PH0.
PH1.
PRINT, P., ?
Additional PRINT Formatting
CR
SPC
TAB
USING, U.
Input/Output
CBY
DBY
GET
INPUT
LIST#
NULL
PORT1
PH0.#
PH1.#
PRINT#, P#, ?#
XBY
System Control Values
BAUD
FREE
LEN
MTOP
STRING
72 |
The Microcontroller Idea Book |
Programming
Math Operators |
Data Storage |
= |
ASC |
+ |
CHR |
- |
CLEAR |
* |
CLEARS |
/ |
DATA |
** |
DIM |
> |
LD@ |
< |
POP |
<> |
PUSH |
>= |
READ |
<= |
RESTORE |
ABS |
ST@ |
ATN |
|
COS |
Timers and Interrupts |
EXP |
|
INT |
CLEARI |
LET |
CLOCK0 |
LOG |
CLOCK1 |
NOT |
IDLE |
PI |
IE |
RND |
IP |
SGN |
ONERR |
SIN |
ONEX1 |
SQR |
ONTIME |
TAN |
PCON |
Logical Operators |
PWM |
RCAP2 |
|
.AND. |
RETI |
T2CON |
|
.OR. |
TCON |
.XOR. |
TIME |
Assembly-language Interfacing |
TIMER0 |
TIMER1 |
|
TIMER2 |
|
CALL |
TMOD |
LIST@ |
|
PH0.@ |
|
PH1.@ |
|
PRINT@, P@, ?@ |
|
UI0 |
|
UI1 |
|
UO0 |
|
UO1 |
The Microcontroller Idea Book |
73 |
Chapter 5
Quick Reference to BASIC-52
This quick reference to the BASIC-52 programming language lists the keywords alphabetically, along with brief descriptions of function and use.
Conventions
The reference uses the following typographic conventions:
KEYWORDS (boldface uppercase)
BASIC-52 keywords
placeholders (italics)
Variables, expressions, constants, or other information that you must supply
[optional items] (enclosed in square brackets) Items that are not required
repeating elements... (followed by ellipsis (three dots))
You may add more items with the same form as the preceding item.
C = command mode
R = run mode
variable = expression |
C,R |
Assigns a value to a variable |
|
expression = expression |
C,R |
Equivalence test (relational operator) |
|
expression + expression |
C,R |
Add |
|
expression - expression |
C,R |
Subtract |
|
expression * expression |
C,R |
Multiply |
74 |
The Microcontroller Idea Book |
Programming |
|
expression / expression |
C,R |
Divide |
|
expression ** expression |
C,R |
Raises first expression to value of second expression (exponent) |
|
expression <> expression |
C,R |
Inequality test (relational operator) |
|
expression < expression |
C,R |
Less than test (relational operator) |
|
expression > expression |
C,R |
Greater than test (relational operator) |
|
expression <= expression |
C,R |
Less than or equal test (relational operator) |
|
expression >= expression |
C,R |
Greater than or equal test (relational operator) |
|
? |
|
Same as PRINT |
|
ABS (expression) |
C,R |
Returns the absolute value of expression |
|
expression .AND. expression |
C,R |
Logical AND |
|
ASC(character) |
C,R |
Returns the value of ASCII character |
|
ATN(expression) |
C,R |
Returns the arctangent of expression |
|
BAUD expression |
C,R |
Sets the baud rate for LPT (pin 8). For proper operation, XTAL must match the |
|
system’s crystal frequency. |
|
CALL integer |
C,R |
Calls an assembly-language routine at the specified address in program memory. |
|
The Microcontroller Idea Book |
75 |
Chapter 5
CBY(expression) |
C,R |
Retrieves the value at expression in program, or code, memory. |
|
CHR(expression) |
C,R |
Converts expression to its ASCII character. |
|
CLEAR |
C,R |
Sets all variables to 0, resets all stacks and interrupts evoked by BASIC. |
|
CLEARI |
C,R |
Clears all interrupts evoked by BASIC. Disables |
ONTIME, ONEX1. |
CLEARS |
C,R |
Resets BASIC-52’s stacks. Sets control stack = 0FEh, argument stack = 1FEh, in- |
|
ternal stack = value in 3Eh in internal RAM. |
|
CLOCK0 |
C,R |
Disables the real-time clock. |
|
CLOCK1 |
C,R |
Enables the real-time clock. |
|
CONT |
C |
Continues executing program after STOP or CONTROL+C. |
|
COS(expression) |
C,R |
Returns the cosine of expression |
|
CR
PRINT option. Causes a carriage return, but no line feed, on the host display.
DATA expression [,...,expression] |
R |
Specifies expressions to be retrieved by a READ statement. |
|
DBY(expression) |
C,R |
Retrieves or assigns a value at expression in internal data memory. |
|
DIM array name [(size)] [,...array name(size)] |
C,R |
Reserves storage for an array. Default size is 11 (0-10). Size limits are 0-254. |
|
Example: |
|
DIM B(100) |
|
Reserves storage for 100-element array B |
76 |
The Microcontroller Idea Book |
Programming |
|
DO: [program statements]: UNTIL relational expression |
R |
Executes all statements between DO and UNTIL until relational expression is |
|
true. |
|
DO: [program statements]: WHILE relational expression |
R |
Executes all statements between DO and WHILE until relational expression is |
|
false. |
|
END |
R |
Terminates program execution. |
|
EXP (expression) |
C,R |
Raises e (2.7182818) to the power of expression |
|
FOR counter variable = start-count expression |
C,R |
TO end-count expression [ |
|
STEP count-increment expression]: [program statements]: |
|
NEXT [counter variable] |
|
Executes all statements between FOR and NEXT the number of times specified by |
|
the counter and step expressions. |
|
FPROG, FPROG1-FPROG6 |
C |
Like PROG, PROG1-PROG6, but using Intelligent programming algorithm. |
|
FREE |
C,R |
Returns the number of bytes of unused external data RAM. |
|
GET |
R |
Contains the ASCII code of a character received from the host computer’s key- |
|
board. After a program reads the value of GET (For example, G=GET), GET re- |
|
turns to 0 until a new character arrives. |
|
GOSUB line number |
R |
Causes BASIC-52 to transfer program control to a subroutine beginning at line |
|
number. A RETURN statement returns control to the line number following the |
|
GOSUB statement. |
|
GOTO line number |
C,R |
Causes BASIC-52 to jump to line number in the current program. |
|
IDLE |
R |
Forces BASIC-52 to wait for ONTIME or ONEX1 interrupt. |
|
The Microcontroller Idea Book |
77 |