BASIC 52
Instructions Set
Quick Reference Manual MCS® BASIC - 52
MCS®-BASIC 52 - Intel - Operating and Reference Manual
BASIC GPC® 554 - Short Guide - MCS® BASIC-52 Intel BASIC Interpreter for Philips 80C552 CPU.
The Microcontroller Idea Book:
Circuits, Programs, & Applications featuring the 8052-BASIC Microcontrolle by Jan Axelson (with chapters available on-line).
The 80C52-BASIC chip is a custom-masked 80C52 microcontroller with a full-featured 8K-byte ROM-resident Basic-52 interpreter. The 80C52-BASIC chip is specifically designed to address the needs of process control, measurement, and instrumentation applications. The internal BASIC-52 language allows users to write programs directly in BASIC. Assembly language routines are easily executed as CALL routines from BASIC.
The fully static design of the 80C52-BASIC chip allows the user to reduce system power by reducing the clock frequency from 29 MHz down to any value, even DC, without loss of data or internal registers (typical operating frequency for BASIC-52 is 11.0592 MHz o 22.1184 MHz). In addition, the 80C52 has two software modes for reduced activity: Idle Mode, where the CPU is frozen but the serial port, timers, and interrupt system continue to function; and Power-Down Mode, where the internal RAM is saved but all other functions are ceased.
A minimum amount of hardware is required to support the 80C52-BASIC chip. Small systems can be constructed with only an address latch, 1K byte of external memory, and the appropriate serial port drivers. With the addition of a transistor, a gate, and a few passive components, BASIC-52 can program EPROM/EEPROMs directly. Both standard and fast programming algorithms are supported.
Software
Hardware
The BASIC-52 Interpreter
BASIC-52 is a very complete implementation of the BASIC language contained in just 8K bytes of ROM. It provides a powerful tool which combines ease of development in a high-level language with the speed necessary for the most time-critical process-control applications. Due to the low system overhead and 11-MHz system clock, BASIC-52 is extremely fast and efficient. It actually runs the "Sieve benchmark program faster than an IBM PC. BASIC-52 offers many unique features, including an accurate real-time clock, the ability to process interrupts, and the ability to treat EPROM, EEPROM memory as if it were mass storage. In addition, the I/O routines, arithmetic routines and trasformation routine in BASIC are callable as assembly language subroutines.
BASIC-52 permits use of both integer and floating-point numbers. Integer numbers range from 0 to 65535, and floating-point numbers range from 1E-127 to 0.99999999E+127 with eight digits of significance. Numbers may be entered and displayed in integer, decimal, hexadecimal, or exponential format.
The following is a list of commands, statements, and operators supported by the 80C52-BASIC. Although some are unique to BASIC-52, just a cursory inspection reveals that the full power of structured programming in BASIC for process-control applications is available.
COMMANDS |
STATEMENTS |
OPERATORS |
||||
RUN | BAUD | FOR-TO-STEP | PRINT# | + | PI | XBY() |
LIST | CALL | NEXT | PH0. | - | SIN() | GET |
LIST # | CLEAR | GOSUB | PH0.# | * | COS() | IE |
NEW | CLEARS | RETURN | PH1. | / | TAN() | IP |
NULL | CLEAR1 | GOTO | PH1.# | ** | ATN() | PORT1 |
RAM | CLOCK0 | ON-GOTO | PUSH | .AND. | = | PCON |
ROM | CLOCK1 | ON-GOSUB | POP | .OR. | < | RCAP2 |
XFER | DATA | IF-THEN-ELSE | PWM | .XOR. | <= | T2CON |
PROG | READ | INPUT | REM | NOT | > | TCON |
PROG1 | RESTORE | LET | RETI | ABS() | >= | TMOD |
PROG2 | DIM | ONERR | STOP | INT() | <> | TIME |
FPROG | DO-WHILE | ONEXT1 | STRING | SGN() | ASC() | TIMER0 |
FPROG1 | DO-UNTIL | ONTIME | UO0 | SQR() | CHR() | TIMER1 |
FPROG2 | END | UO1 | RND | CBY() | TIMER2 | |
UI0 | LOG() | DBY() | XTAL | |||
UI1 | EXP() | MTOP |
Operating Conditions*
Operating Temperature:
Commercial 0 C to 70 C
Industrial -40 C to 85 C
Operating voltage (Vcc): +5 volts ± 10%
Absolute Maximum Ratings*
Voltage on any pin with respect
to ground (Vss): -0.5V to 7.0V
Power dissipation: 200 mW
Maximum lcc at 12 MHz: 24mA
80C52-BASIC Pin Description*
Vss Circuit ground potential
Vcc Circuit supply voltage
AD0-AD7 The multiplexed low-order address and data bus used during access to external memory. External pull-up resistors (10k ohm) are required on these pins if BASIC-52 EPROM/EEPROM programming feature is used.
A8-A15 The high-order address bus used during access to external memory.
PORT 1 Port 1 is a quasi-bidirectional 8-bit input/output port. It can be used as a standard parallel I/O port with the PORT1 command in BASIC-52, or the individual pins of Port 1 can have alternative functions as follows:
PORT 1.0(T2) Can be used as the trigger input to Timer/Counter #2. A logic 1 must be written to this bit in order for this function to operate.
PORT 1.1 (T2EX) Can be used as the external input to Timer/Counter #2. A logic 1 must be written to this bit in order for this function to operate.
PORT 1.2 (PWM OUTPUT) This pin is used as the Pulse Width Modulated (PWM) output port when the PWM statement is executed. The PWM statement can generate pulses of varying frequency and duty cycle.
PORT 1.3 (ALE DISABLE) This pin is used to disable the ALE signal to the external latch when the EPROM/EEPROM programming feature is being used. In a system, this pin is logically ANDed with ALE.
PORT 1.4 (PROGRAMMING PULSE) This pin provides the proper programming pulse when programming EPROM/EEPROMs.
PORT 1.5 (PROGRAMMING ENABLE) This pin is used to enable the programming voltage (Vpp) when programming EPROMs and remains active low during programming. On EEPROMs that do not require any special programming voltage, this pin is not used.
PORT 1.6 (DMA ACKNOWLEDGE) When the pseudo-DMA feature is implemented (as outlined in the BASIC-52 Programmers Manual), this pin functions as an active-low DMA Acknowledge output.
PORT 1.7 (LINE PRINTER OUTPUT) This pin functions as a serial output when the LIST# or PRINT# commands are used in BASIC. This enables the user to have hard-copy output during program operation or for program listings.
RESET A logic 1 (>3.5V) on this pin for more than two machine cycles while the oscillator is running will reset the device. An internal pull-down resistor permits power-on reset using only a capacitor connected between this pin and Vcc.
ALE (Address Latch Enable) an output pin that is used to latch the low-order address byte during read, write, or program fetch operations to external memory.
PSEN (Program Store Enable) a signal used to enable external program memory. This pin will remain a logic 1 unless the user is running an assembly language program in external memory.
XTAL1 Input to the inverting amplifier that forms the oscillator. This input should be left floating when an external oscillator is used.
XTAL2 Output of the inverting amplifier that forms the oscillator and input to the internal clock generator. Receives the external oscillator signal when an external oscillator is used.
RD This pin is a control that is used to enable read operations to external data memory.
WR This pin is a control signal that is used to enable write operations to external data memory.
T1 This pin can be programmed to be an external input to Timer/Counter 1
T0 This pin can be programmed to be an external input to Timer/Counter 0
INT1 This is the external interrupt 1 input pin. Interrupts on this pin may be handled in either BASIC-52 or assembly language.
INT0/DMA REQUEST This is the external interrupt 0 input pin. It may optionally be programmed to function as a DMA request input pin or used by EEPROM devices during programming.
CONSOLE SERIAL OUTPUT This is the serial input pin that receives data from the console device. Standard serial ASCII codes consisting of 8-bit data with no parity at standard data rates are assumed. After RESET in BASIC-52, if desired and if the first character received is a "space," then BASIC-52 will perform an auto-baudrate calculation and automatically set the console serial input to the incoming data rate.
EA When EA is held high, the CPU functions as an 80C52 with a BASIC interpreter executing out of internal program memory (unless the program counter exceeds 0FFFh). When EA is held low, the CPU functions as a generic 80C52 and executes only out of external program memory.
*Note: For complete details of the 80C52-BASIC chips electrical characteristics and timing diagrams, refer to the design specification sheet for the 80C52 microcontroller chip.
COMMAND FUNCTION
RUN Execute a program
CONT CONTinue after a STOP or control-C
LIST LIST program to the console device
LIST# LIST program to serial printer port (P1.7)
NEW Erase the program stored in RAM
NULL Set NULL count after carriage return/line feed
RAM Evoke RAM mode, current program in READ/WRITE memory
ROM Evoke ROM mode, current program in ROM/EPROM memory
XFER Transfer a program from ROM/EPROM to RAM
STATEMENT FUNCTION
BAUD Set baud rate for line printer
port
CALL CALL assembly language program
CLEAR CLEAR variables, interrupts and Strings
CLEARS CLEAR Stacks
CLEARI CLEAR Interrupts
CLOCK1 Enable REAL TIME CLOCK
CLOCK0 Disable REAL TIME CLOCK
DATA DATA to be read by READ statement
READ READ data in DATA statement
RESTORE RESTORE READ pointer
DIM Allocate memory for arrayed variables
DO Set up loop for WHILE or UNTIL
UNTIL Test DO loop condition (loop if false)
WHILE Test DO loop condition (loop if true)
END Terminate program execution
FOR-TO-{STEP} Set up FOR-NEXT loop
NEXT Test FOR-NEXT loop condition
GOSUB Execute subroutine
RETURN RETURN from subroutine
GOTO GOTO program line number
ON GOTO Conditional GOTO
ON GOSUB Conditional GOSUB
IF-THEN-{ELSE} Conditional test
INPUT INPUT a string or variable
LET Assign a variable or string a value (LET is optional)
ONERR ONERRor GOTO line number
ONTIME Generate an interrupt when TIME is equal to or greater
than
ONTIME argument-line number is after comma
ONEX1 GOSUB to line number following ONEX1 when INT1 pin is pulled
low
PRINT PRINT variables, strings or literals P. is shorthand for
PRINT
PRINT# PRINT to software serial port (P1.7)
PH0. PRINT HEX mode with zero suppression
PH1. PRINT HEX mode with no zero suppression
PH0.# PH0. to line printer (P1.7)
PH1.# PH1.# to line printer (P1.7)
PUSH PUSH expressions on argument stack
POP POP argument stack to variables
PWM PULSE WIDTH MODULATION
REM REMark
RETI RETurn from Interrupt
STOP Break program execution
STRING Allocate memory for STRlNGs
UI1 Evoke User console Input routine
UI0 Evoke BASIC console Input routine
UO1 Evoke User console Output routine
UO0 Evoke BASIC console Output routine
OPERATORS FUNCTION
CBY( ) Read program memory
DBY( ) Read/assign internal data memory
XBY( ) Read/assign external Data memory
GET Read console
IE Read/assign IE register
IP Read/assign IP register
PORT1 Read/assign I/O port 1 (P1)
PCON Read/assign PCON register
RCAP2 Read/assign RCAP2 (RCAP2H:RCAP2L)
T2CON Read/assign T2CON register
TCON Read/assign TCON register
TMOD Read/assign TMOD register
TIME Read/assign the REAL TIME CLOCK
TIMER0 Read/assign TIMER0 (TH0: TL0)
TIMER1 Read/assign TIMER1 (TH1: TL1)
TIMER2 Read/assign TIMER2 (TH2: TL2)
+ Addition
/ Division
** Exponentation
* Multiplication
- Subtraction
.AND. Logical AND
.OR. Logical OR
.XOR. Logical XOR
STORED CONSTANT
PI Pi - 3.1415926
OPERATORS - SINGLE OPERAND
ABS( ) Absolute value
NOT( ) Ones complement
INT( ) Integer
SGN( ) Sign
SQR( ) Square root
RND Random number
LOG( ) Natural log
EXP( ) "e" (2.7182818) to the X
SIN( ) Returns the sine of argument
COS( ) Returns the cosine of argument
TAN( ) Returns the tangent of argument
ATN( ) Returns arctangent of argument
Last Up-dated at October 23, 2004