CHAPTER 7
Special Operators

7.1 SPECIAL FUNCTION OPERATORS

SPECIAL FUNCTION OPERATORS are called SPECIAL FUNCTION OPERATORS because they directly manipulate the I/0 hardware and the memory addresses on the DS5000 device.  All SPECIAL FUNCTION OPERATORS, with the exception of CBY([expr]) and GET, can be placed on either side of the replacement operator (=) in a LET STATEMENT.

EXAMPLES:

A = DBY(100) and DBY(100) = A+2

Both of the above are valid statements in DS5000-BASIC.  The SPECIAL FUNCTION OPERATORS in DS5000-BASIC include the following:


CBY([expr])

The CBY([expr]) operator is used to retrieve data from the PROGRAM or CODE MEMORY address space of the DS5000.  Since CODE memory cannot be written into on the DS5000, the CBY([expr]) operator cannot be assigned a value.  It can only be read.  Non-existent memory will read as 0.

A = CBY(1000) Causes the value in code memory space 1000 to be assigned to the variable A.  The argument for the CBY([expr]) operator MUST be a valid integer (i.e. between 0 and 65535 (0FFFFH) ).  If it is not, a BAD ARGUMENT ERROR will occur.


DBY([expr])

The DBY([expr]) operator is used to retrieve or assign a value to the DS5000's internal data memory.  The argument in the DBY operator must be between 0 and 127 inclusive.  The value assigned to DBY([expr]) can range between 0 and 255.  This is because there are only 128 internal memory locations in the DS5000 and one byte can only represent a quantity between 0 and 255 inclusive.  Nonexistent memory will read as 0FFH.

EXAMPLES:

A=DBY(B)
DBY(120) = CBY(1000)

The first example would assign variable A the value that is in internal memory location B.  B would have to be between 0 and 127.  The second example would load internal memory location 120 with the same value that is in program memory location 1000.


XBY([expr])

The XBY([expr]) operator is used to retrieve or assign a value to the DS5000 external data memory.  The argument in the XBY([expr]) operator must be a valid integer (i.e. between 0 and 65535 (0FFFFH) ). The value assigned to the XBY([expr]) operator must be between 0 and 255.  If it is not a BAD ARGUMENT ERROR will occur.  Note that the DS5000 contains a total of 32768 (8000H) bytes of physical memory, which is allocated between program and data storage.  Nominally available data memory ranges between 3300H and 5FFFH or MTOP.

EXAMPLES:

XBY(4000H)=DBY(100)
A=XBY(5F00H)

The first example would load external memory location 4000H with the same value that was in internal memory location 100.  The second example would make the variable A equal to the value in external memory location 5F00H.


GET

The GET operator only produces a meaningful result when used in the RUN mode.  It will always return a result of zero in the command mode.  What GET does is read the console input device.  Actually, it takes a "snapshot" of the console input device.  If a character is available from the console device, the value of the character will be assigned to GET.  After GET is read in the program, GET will be assigned the value of zero until another character is sent from the console device.  The following example will print the decimal representation of any character sent from the console:

EXAMPLE:

>10 A=GET
>20 IF A<>0 THEN PRINT A
>30 GOTO 10
>RUN

 65     (TYPE "A" ON CONSOLE)
 49     (TYPE "1" ON CONSOLE)
 24     (TYPE "CONTROL-X" ON CONSOLE)
 50     (TYPE "2" ON CONSOLE)

The reason the GET operator can be read only once before it is assigned a value of zero is that this implementation guarantees that the first character entered will always be read, independent of where the GET operator is placed in the program.

The following operators directly manipulate the DS5000's special function registers.  Specific details of the operation of these registers is in the DS5000 USERS HANDBOOK, available from Dallas Semiconductor

IE

The IE operator is used to retrieve or assign a value to the DS5000's special function register IE.  Since the IE register on the DS5000 is a BYTE register, the value assigned to IE must be between 0 and 255.  The only statements in DS5000-BASIC that write to the IE register are the CLOCK0, CLOCK1, ONEX1, CLEAR, and CLEARI statements.


IP

The IP operator is used to retrieve or assign a value to the DS5000's special function register IP.  Since the IP register on the DS5000 is a BYTE register, the value assigned to IP must be between 0 and 255.


PORT0

The PORT0 operator is used to retrieve or assign a value to the DS5000's P0 I/0 port.  Since P0 on the DS5000 is a BYTE wide register, the value assigned to P0 must be between 0 and 255 inclusive.  PORT0 has open-drain output transistors and requires external 10K ohm pull-up resistors or a current-sinking load to operate as an output.  The CAPTURE command uses PORT0 as the data-bus.  PORT0 inputs and outputs are connected together internally.  To be used as an input, a 1 must be written to the selected PORT0 bit before attempting to read it.  For mixed bit input/outputs, selected outputs may be masked and re-written.


PORT1

The PORT1 operator is used to retrieve or assign a value to the DS5000's P1 I/0 port.  Since P1 on the DS5000 is a BYTE wide register, the value assigned to P1 must be between 0 and 255 inclusive.  Certain bits on P1 have pre-defined functions.  If the user does not implement any of the hardware associated with these pre-defined functions, The PORT1 instruction can be used in any manner appropriate in the application.  EXTENDED DS5000-BASIC uses PORT1.0, PORT1.1, and PORT1.2 when interfacing an A-D converter.  PORT1 inputs and outputs are connected together internally.  To be used as an input, a 1 must be written to the selected PORT1 bit before attempting to read it.  For mixed bit input/outputs, selected outputs may be masked and re-written.


PORT2

The PORT2 operator is used to retrieve or assign a value to the DS5000's P2 1/0 port.  Since P2 on the DS5000 is a BYTE wide register, the value assigned to P2 must be between 0 and 255 inclusive.  PORT2 inputs and outputs are connected together internally.  To be used as an input, a 1 must be written to the selected PORT2 bit before attempting to read it.  For mixed bit input/outputs, selected outputs may be masked and re-written.


PORT3

Most of the bits associated with PORT3 are assigned to special-functions.  The PORT3 operator will function in the same way that PORT1 and PORT2 function so you must avoid conflicts if you try and use PORT3 for other than its assigned special functions.


PCON

The PCON operator is used to retrieve or assign a value to the DS5000's PCON register.


TCON

The TCON operator is used to retrieve and/or assign value to the DS5000's special function register TCON.


TMOD

The TMOD operator is used to retrieve and/or assign a value to the DS5000's special function register TMOD.


TIME

The TIME operator is used to retrieve and/or assign a value to the REAL TIME CLOCK resident in DS5000 BASIC.  After reset, TIME is equal to 0.  The CLOCK1 statement enables the REAL TIME CLOCK.  When the REAL TIME CLOCK is enabled, the SPECIAL FUNCTION OPERATOR, TIME will increment once every 5 milliseconds.  The TIME operator uses TIMER0 and the interrupts associated with TIMER0 on the DS5000.  The unit of TIME is seconds and the appropriate XTAL value must be assigned to insure that the TIME operator is accurate.  CLOCK 0 stops TIME from incrementing.

When TIME is assigned a value with a LET statement (i.e. TIME = 100), only the integer portion of TIME will be changed.

EXAMPLE:

>CLOCK1       (enable REAL TIME CLOCK)
>CLOCK0       (disable REAL TIME CLOCK)
>PRINT TIME   (display TIME)
 3.315

>TIME = 0
>PRINT TIME   (display TIME again)
 .315         (only the integer has changed)

>DBY(47H) = 0 (set decimal portion to zero)
>PRINT TIME
 0

As shown the "fraction" portion of TIME can be changed by manipulating the contents of internal memory location 71 (47H).  This is accomplished by a DBY(71) statement.  Note that each count in internal memory location 71 (47H) represents 5 milliseconds of TIME.

>DBY(71) = 3  (fraction of TIME = 3, 15 ms)

>PRINT TIME
 1.5 E-2

The reason only the integer portion of TIME is changed when assigned a value is that it allows the user to generate accurate time intervals.  For instance, let's say you want to create an accurate 12-hour clock.  There are 43200 seconds in a 12 hour period, so an ONTIME 43200,[ln num] statement is used.  Now, when the TIME interrupt occurs the statement TIME = 0 is executed, but the millisecond counter is not re-assigned a value so if interrupt latency happens to exceed 5 milliseconds, the clock will still remain accurate.


TIMER0

The TIMER0 operator is used to retrieve or assign a value to the DS5000's special function registers TH0 and TL0.  This operator treats the byte registers TH0 and TL0 as a 16-bit register pair.  TH0 is the high byte and TL0 is the low byte.  DS5000-BASIC uses TH0 and TL0 to implement the REAL TIME CLOCK function.  If the user does not implement the REAL TIME CLOCK function (i.e. does not use the statement CLOCK1) in the BASIC program TH0 and TL0 may be used in any manner suitable to the particular application.  Note that TL0 and TH0 are not defined as operators in DS5000-BASIC


TIMER1

The TIMER1 operator is used to retrieve or assign a value to the DS5000's special function registers TH1 and TL1.  This operator treats the byte registers TH1 and TL1 as a 16-bit register pair.  TH1 is the high byte and TL1 is the low byte.  DS5000-BASIC uses TH1 and TL1 to implement the timings baud rate for the serial port and for the PWM statement.  If the user does not use any of these features TH1 and TL1 may be used in any manner suitable to the particular application.  Note that TL1 andTH1 are not defined as operators in DS5000-BASIC.


XTAL

The XTAL operator tells DS5000-BASIC what frequency the system is operating at.  The XTAL operator is used by DS5000-BASIC to calculate the REAL TIME CLOCK reload value, the PROM programming timing, and the software serial port baud rate generation.  The XTAL value is expressed in Hz.  So, XTAL = 9000000 would set the XTAL value to 9 MHz.


7.2 EXAMPLES OF MANIPULATING SPECIAL FUNCTION VALUES

Using the logical operators available in DS5000-BASIC, it is possible to write to or read from any byte of the special function registers that DS5000-BASIC treats as a register pair.

To write USER_BYTE to the high byte of TIMER0, mask the lower byte and add:

>TIMER0= (TIMER0.AND.00FFH)+ INT(256*(USER_BYTE))

Similarly to write to the low byte, mask the high byte:

>TIMER0= (TIMER0.AND. 00FF00H) + (USER BYTE)

To read the high byte right shift 8 bits (divide by 256)

>PH0.  INT(TIMER0/256)

To read the low byte, mask out the high byte.

>PH0.  TIMER0 AND. 00FFH

TIMER1 normally functions as the baud rate generator for DS5000-BASIC.  If TIMER1 is used for another application, such as using the PWM statement, TIMER1 must be restored for serial communication to function.  That sequence of instructions can be executed in either the direct mode or as part of a program.  The LIST#, PRINT# and PWM commands/statements cannot be used when TIMER1 functions as the baud rate generator for the DS5000.  Certain crystals may not be able to use TIMER1 as the baud rate generator, especially at high (above 2400) baud rates.


7.3 SYSTEM CONTROL VALUES

The SYSTEM CONTROL VALUES determine or reveal how memory is allocated by DS5000-BASIC.  Note that the DS5000 contains a total of 32768 bytes (0 to 7FFFH) of battery-backed RAM.  DS5000-BASIC and its extensions are stored from 0 to 3300H (13056).  Memory above 5FFFH (24575) is used as PROM for the PROG statement.  After reset, DS5000 sizes the external memory and assigns the last valid memory address to the SYSTEM CONTROL VALUE, MTOP.  DS5000-BASIC will not use any external RAM memory beyond the value assigned to MTOP.  If the user wishes to allocate some external memory for an assembly language routine the LET statement can be used (e.g. MTOP = USER ADDRESS).  If the user assigns a value to MTOP that is greater than the last valid memory address, a MEMORY ALLOCATION ERROR will be generated.


LEN

The SYSTEM CONTROL VALUE, LEN, tells the user how many bytes of memory the current selected program occupies.  Obviously, LEN cannot be assigned a value, it can only be read.  A NULL program (i.e. no program) will return a LEN of 1.  The 1 represents the end of program file character.


FREE

The SYSTEM CONTROL VALUE, FREE, tells the user how many bytes of RAM memory are available to the user.  When the current selected is in RAM memory, the following relationship will always hold true.  

FREE = MTOP - LEN -12799

NOTE: Unlike some BASICS, DS5000-BASIC does not require any "dummy" arguments for the SYSTEM CONTROL VALUES.