Accessing the R31 Analogue-to-Digital Converter and the 
Clock/Calendar from BASIC

Application Notes A94Z601



Rigel Corporation
P.O. Box 90040 
Gainesville, FL 32607
(904) 373-4629

This document is available on the Rigel Bulletin Board.  BBS: (904) 377-4435



Using the Intel 8052-BASIC Controller

The R31 board has facilities to accommodate the 8052-BASIC controller, including EPROM 
burning.  This document explains how the analogue-to-digital converter (ADC) and the 
clock/calendar (CC) may be accessed from the BASIC interpreter.

The BASIC interpreter includes a CALL instruction which branches to a user routine in program 
memory.  By placing appropriate subroutines to access the ADC and the CC, these chips may be 
run from a BASIC program.

Use of Registers
Only register bank 3 is left for the general purpose use.  Data may be transferred to and from 
user routines through registers in bank 3.  These registers are the internal data RAM locations 
18h to 1Fh.  The BASIC instruction 

	DBY(18h)=X

for example, sets register 0 of bank 3 equal to X.  Similarly, the instruction

	print DBY(1Fh)

prints the contents of register 7 of bank 3.  User routines should leave register bank 0 active 
before returning to BASIC.

R31 Use of Port 3
The R31 has headers that may be used to connect Port3 bits to the control lines of the ADC.  
P3.2, P3.3, P3.4, and P3.5 are used to access the lines SARS, CS, DI/DO, and CLK.  Strictly 
speaking SARS is not needed if the user is willing to simply wait a bit for the conversion to 
complete.  These bits are typically defined as below.

   SARS    equ P3.2    ; SAR status - not used
   CS      equ P3.3    ; chip select
   DI_DO   equ P3.4    ; data in / data out
   CLK     equ P3.5    ; clock

Port 3 is not accessible from BASIC, which makes writing a BASIC program to run the ADC 
impossible if Port 3 bits are to be used.  A user routine written in assembly language has no 
trouble accessing Port3 bits.  Such a routine is then called from BASIC.

Programming Considerations
The R31 monitor EPROM contains routines to run the CC when U7 holds a RAM chip.  These 
routines are placed starting at 4000h.  When BASIC is used, the EPROM is placed at high 
memory, while the RAM chip occupies the lower half of memory.  The routines in the EPROM 
are then decoded to be starting at C000h.  The BASIC callable routines are written without the 
use of LJMP and LCALL instructions, making them relocatable to any 2K block.

A few new routines are appended to the R31 monitor EPROM at 4000h.  A jump table is placed 
at the beginning of the block starting at 4000h (C000h when BASIC is used).  The routines and 
their addresses are listed below.
					

PutTByte
4000h
write a byte to the CC

GetTByte
4004h
read a byte from the CC

activateT
4008h
activate the CC

PutTime
400Ch
write the time to the CC

GetTime
4010h
read the time from the CC

BPutTime
4014h (C014h)
BASIC callable version of 
putTime

BGetTime
4016h (C016h)
BASIC callable version of 
getTime

Sconvert
4018h (C018h)
BASIC callable ADC 
conversion routine for 
single-ended conversions

Dconvert
401Ah (C01Ah)
BASIC callable ADC 
conversion routine for 
differential conversions



Clock/Calendar Routines
These routines use register bank 3 to transfer data between the CC and the controller.  The 
following assignment is used.

  register address         value
  -------- -------  --------------------
     r0      18h    fraction of seconds
     r1      19h    second
     r2      1Ah    BCD (binary coded decimal) minute
     r3      1Bh    BCD hour
     r4      1Ch    BCD day of week
     r5      1Dh    BCD date
     r6      1Eh    BCD month
     r7      1Fh    BCD year

The CC is set by first placing the data into the registers and then calling the routine BSetTime.  
Thereafter, the time data may be obtained by calling the routine BGetTime and inspecting the 
register set. 

Analogue-to-Digital Converter Routines
The ADC routines only use register 0 of bank 3 (internal data RAM 18h).  Separate routines, 
SConvert and DConvert, are responsible for single-ended or differential conversions.  Before 
these routines are called, the channel number (or pair number) is placed in register 0 of bank 3.  
Upon execution, the routines place the conversion result back in register 0.

Programs
The BASIC callable assembly language code is given in BAS31UT.ASM.  Note that the routines 
previously in DS1215UT are kept for compatibility purposes.

The two BASIC programs, ADC31BAS.BAS and TIMERBAS.BAS illustrate the use of the 
routines.  The RLOAD.EXE is a convenient way to download the BASIC programs to the R31 
board running the BASIC chip.



