Electronics
Btrieve
Motorcycling
Software

APPENDIX A

1.1 MEMORY USAGE (Version 1.0)

The following list specifies what locations in internal and external memory MCS BASIC-52 uses, and what these locations are used for. This information can largely be regarded as "for your information," but it can be used to do things like alter the pulse width of a EPROM programming pulse, etc.

INTERNAL MEMORY ALLOCATION:

LOCATION(S) IN HEX   MCS BASIC-52 USAGE

00H THRU 07H         "WORKING REGISTER BANK"
08H                  BASIC TEXT POINTER--LOW BYTE
09H                  ARGUMENT STACK POINTER
0AH                  BASIC TEXT POINTER--HIGH BYTE
0BH THRU 0FH         TEMPORARY BASIC STORAGE
10H                  READ TEXT POINTER--LOW BYTE
11H                  CONTROL STACK POINTER
12H                  READ TEXT POINTER--HIGH BYTE
13H                  START ADDRESS OF BASIC PROGRAM--HIGH BYTE
14H                  START ADDRESS OF BASIC PROGRAM--LOW BYTE
15H                  NULL COUNT
16H                  PRINT HEAD POSITION FOR OUTPUT
17H                  FLOATING POINT OUTPUT FORMAT TYPE
18H THRU 21H         NOT USED--RESERVED FOR USER

22H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 22.0H            SET WHEN "ONTIME" STATEMENT IS EXECUTED
BIT 22.1H            SET WHEN BASIC INTERRUPT IN PROGRESS
BIT 22.2H            SET WHEN "ONEX1" STATEMENT IS EXECUTED
BIT 22.3H            SET WHEN "ONERR" STATEMENT IS EXECUTED
BIT 22.4H            SET WHEN "ONTIME" INTERRUPT IS IN PROGRESS
BIT 22.5H            SET WHEN A LINE IS EDITED
BIT 22.6H            SET WHEN EXTERNAL INTERRUPT IS PENDING
BIT 22.7H            WHEN SET, CONT COMMAND WILL WORK

23H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 23.0H            USED AS FLAG FOR "GET" OPERATOR
BIT 23.1H            SET WHEN INVALID INTEGER FOUND IN TEXT
BIT 23.2H            TEMPORARY BIT LOCATION
BIT 23.3H            CONSOLE OUTPUT CONTROL, 1 = LINE PRINTER
BIT 23.4H            CONSOLE OUTPUT CONTROL, 1 = USER DEFINED
BIT 23.5H            BASIC ARRAY INITIALIZATION BIT
BIT 23.6H            CONSOLE INPUT CONTROL, 1 = USER DEFINED
BIT 23.7H            RESERVED

24H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 24.0H            STOP STATEMENT OR CONTROL-C ENCOUNTERED
BIT 24.1H            0 = HEX INPUT, 1 = FP INPUT
BIT 24.2H            0 = RAM MODE, 1 = ROM MODE
BIT 24.3H            ZERO FLAG FOR DOUBLE BYTE COMPARE
BIT 24.4H            SET WHEN ARGUMENT STACK HAS A VALUE
BIT 24.5H            RETI INSTRUCTION EXECUTED
BIT 24.6H            RESERVED
BIT 24.7H            RESERVED

25H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 25.0H            RESERVED, SOFTWARE TRAP TEST
BIT 25.1H            FIND THE END OF PROGRAM, IF SET
BIT 25.2H            RESERVED
BIT 25.3H            INTERRUPT STATUS SAVE BIT
BIT 25.4H            SET WHEN PROGRAM EXECUTION IS COMPLETE
BIT 25.5H            RESERVED, EXTERNAL TRAP TEST
BIT 25.6H            SET WHEN CLOCK1 EXECUTED, ELSE CLEARED
BIT 25.7H            SET WHEN BASIC IS IN THE COMMAND MODE

26H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 26.0H            SET TO DISABLE CONTROL-C
BIT 26.1H            SET TO ENABLE "FAKE" DMA
BIT 26.2H            RESERVED
BIT 26.3H            SET TO EVOKE "INTELLIGENT" PROM PROGRAMMING
BIT 26.4H            SET TO PRINT TEXT STRING FROM ROM
BIT 26.5H            RESERVED
BIT 26.6H            SET TO SUPPRESS ZEROS IN HEX MODE PRINT
BIT 26.7H            SET TO EVOKE HEX MODE PRINT

27H                  "BIT" ADDRESSABLE BYTE COUNTER
28H THRU 3DH         BIT AND BYTE FLOATING POINT WORKING SPACE
3EH                  INTERNAL STACK POINTER HOLDING REGISTER
3FH                  LENGTH OF USER DEFINED STRING--$
40H                  TIMER 1 RELOAD LOCATION--HIGH BYTE
41H                  TIMER 1 RELOAD LOCATION--LOW BYTE
42H                  BASIC TEXT POINTER SAVE LOCATION--HIGH BYTE
43H                  BASIC TEXT POINTER SAVE LOCATION--LOW BYTE
44H                  RESERVED
45H                  TRANSCENDENTAL FUNCTION TEMP STORAGE
46H                  TRANSCENDENTAL FUNCTION TEMP STORAGE
47H                  MILLI-SECOND COUNTER FOR REAL TIME CLOCK
48H                  SECOND COUNTER FOR REAL TIME CLOCK--HIGH BYTE
49H                  SECOND COUNTER FOR REAL TIME CLOCK--LOW BYTE
4AH                  TIMER 0 RELOAD FOR REAL TIME CLOCK
4BH                  SOFTWARE SERIAL PORT BAUD RATE--HIGH BYTE
4CH                  SOFTWARE SERIAL PORT BAUD RATE--LOW BYTE
4DH THRU 0FFH        8052AH STACK SPACE AND USER WORKING SPACE

EXTERNAL MEMORY ALLOCATION

LOCATION(S) IN HEX   MCS BASIC-52 USAGE

00H AND 01H          "LAST" END OF FILE ADDRESS FOR RAM FILE (H-L)
02H AND 03H          CURRENT END OR FILE ADDRESS FOR RAM FILE (H-L)
04H                  LENGTH OF THE CURRENT EDITED LINE
05H AND 06H          LN NUM IN BINARY OF CURRENT EDITED LINE (H-L)
07H THRU 49H         BASIC INPUT BUFFER
50H THRU 5FH         FLOATING POINT OUTPUT TEMP
60H THRU 0FEH        CONTROL STACK
0FFH                 CONTROL STACK OVERFLOW
100H                 LOCATION TO SAVE "GET" CHARACTER
101H                 LOCATION TO SAVE ERROR CHARACTER CODE
102H AND 103H        LOCATION TO GO TO ON USER "ONERR" (H-L)
104H AND 105H        TOP OF VARIABLE STORAGE (H-L)
106H AND 107H        FP STORAGE ALLOCATION (H-L)
108H AND 109H        MEMORY ALLOCATED FOR MATRICES (H-L)
10AH AND 10BH        TOP OF MEMORY ASSIGNED TO BASIC (H-L)
10CH AND 10DH        RANDOM NUMBER SEED (H-L)
10EH THRU 113H       CRYSTAL VALUE
114H THRU 11FH       FLOATING POINT TEMPS
120H AND 121H        LOCATION TO GO TO ON ONEX1 INTERRUPT (H-L)
122H AND 123H        NUMBER OF BYTES ALLOCATED FOR STRINGS (H-L)
124H THRU 127H       ONTIME INTERRUPT AND LINE NUMBER (H-L)
128H AND 129H        "NORMAL" PROM PROGRAMMER TIME OUT (H-L)
12AH AND 12BH        "INTELLIGENT" PROM PROGRAMMER TIME OUT (H-L)
12CH                 RESERVED
12DH THRU 1FEH       ARGUMENT STACK

NOTE: (H-L) means HIGH BYTE--LOW BYTE. in external memory all 16 bit binary numbers are stored with the HIGH BYTE in the first (lower order) address and the LOW BYTE in the next sequential address.

The following list specifies what locations in internal and external memory locations are used by Version 1.1 of MCS BASIC-52. Any differences between V1.0 and V1.1 are in bold face type. (In the scanned ASCII version I have marked them with an exclamation mark '!')

INTERNAL MEMORY ALLOCATION: (VERSION 1.1)

LOCATION(S) IN HEX   MCS BASIC-52 USAGE

00H THRU 07H         "WORKING REGISTER BANK"
08H                  BASIC TEXT POINTER--LOW BYTE
09H                  ARGUMENT STACK POINTER
0AH                  BASIC TEXT POINTER--HIGH BYTE
0BH THRU 0FH         TEMPORARY BASIC STORAGE (Available to user in BASIC
                     CALLS to ASM routines)
10H                  READ TEXT POINTER--LOW BYTE
11H                  CONTROL STACK POINTER
12H                  READ TEXT POINTER--HIGH BYTE
13H                  START ADDRESS OF BASIC PROGRAM--HIGH BYTE
14H                  START ADDRESS OF BASIC PROGRAM--LOW BYTE
15H                  NULL COUNT
16H                  PRINT HEAD POSITION FOR OUTPUT
17H                  FLOATING POINT OUTPUT FORMAT TYPE
18H THRU 21H         NOT USED--RESERVED FOR USER

22H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 22.0H            SET WHEN "ONTIME" STATEMENT IS EXECUTED
BIT 22.1H            SET WHEN BASIC INTERRUPT IN PROGRESS
BIT 22.2H            SET WHEN "ONEX1" STATEMENT IS EXECUTED
BIT 22.3H            SET WHEN "ONERR" STATEMENT IS EXECUTED
BIT 22.4H            SET WHEN "ONTIME" INTERRUPT IS IN PROGRESS
BIT 22.5H            SET WHEN A LINE IS EDITED
BIT 22.6H            SET WHEN EXTERNAL INTERRUPT IS PENDING
BIT 22.7H            WHEN SET, CONT COMMAND WILL WORK

23H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 23.0H            USED AS FLAG FOR "GET" OPERATOR
BIT 23.1H   !        SET WHEN PRINT@ OR LIST@ IS EVOKED
BIT 23.2H   !        RESERVED, TRAPS TIMER 1 INTERRUPT
BIT 23.3H            CONSOLE OUTPUT CONTROL, 1 = LINE PRINTER
BIT 23.4H            CONSOLE OUTPUT CONTROL, 1 = USER DEFINED
BIT 23.5H            BASIC ARRAY INITIALIZATION BIT
BIT 23.6H            CONSOLE INPUT CONTROL, 1 = USER DEFINED
BIT 23.7H   !        RESERVED, USED TO TRAP SERIAL PORT INTERRUPT

24H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 24.0H            STOP STATEMENT OR CONTROL-C ENCOUNTERED
BIT 24.1H   !        USER IDLE BREAK BIT
BIT 24.2H   !        SET DURING AN INPUT INSTRUCTION
BIT 24.3H   !        RESERVED
BIT 24.4H            SET WHEN ARGUMENT STACK HAS A VALUE
BIT 24.5H            RETI INSTRUCTION EXECUTED
BIT 24.6H   !        RESERVED, TRAPS EXTERNAL INTERRUPT 0
BIT 24.7H   !        SET BY USER TO SIGNIFY THAT A VALID LIST@ OR
                     PRINT@ DRIVER IS PRESENT

25H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 25.0H            RESERVED, SOFTWARE TRAP TEST
BIT 25.1H            FIND THE END OF PROGRAM, IF SET
BIT 25.2H   !        SET DURING A DIM STATEMENT
BIT 25.3H            INTERRUPT STATUS SAVE BIT
BIT 25.4H   !        RESERVED, INPUT TRAP
BIT 25.5H   !        SET TO SIGNIFY EXPANSION IS PRESENT
BIT 25.6H            SET WHEN CLOCK1 EXECUTED, ELSE CLEARED
BIT 25.7H            SET WHEN BASIC IS IN THE COMMAND MODE

26H                  BITS USED SPECIFICALLY AS FOLLOWS

BIT 26.0H            SET TO DISABLE CONTROL-C
BIT 26.1H            SET TO ENABLE "FAKE" DMA
BIT 26.2H   !        RESERVED, OUTPUT TRAP
BIT 26.3H            SET TO EVOKE "INTELLIGENT" PROM PROGRAMMING
BIT 26.4H            SET TO PRINT TEXT STRING FROM ROM
BIT 26.5H   !        SET WHEN CONTROL-S ENCOUNTERED
BIT 26.6H            SET TO SUPPRESS ZEROS IN HEX MODE PRINT
BIT 26.7H            SET EVOKE HEX MODE PRINT

27H                  "BIT" ADDRESSABLE BYTE COUNTER
28H THRU 3DH         BIT AND BYTE FLOATING POINT WORKING SPACE
3EH                  INTERNAL STACK POINTER HOLDING REGISTER
3FH                  LENGTH OF USER DEFINED STRING--$
40H                  TIMER 1 RELOAD LOCATION--HIGH BYTE
41H                  TIMER 1 RELOAD LOCATION--LOW BYTE
42H                  BASIC TEXT POINTER SAVE LOCATION--HIGH BYTE
43H                  BASIC TEXT POINTER SAVE LOCATION--LOW BYTE
44H                  RESERVED
45H                  TRANCENDENTAL FUNCTION TEMP STORAGE
46H                  TRANCENDENTAL FUNCTION TEMP STORAGE
47H                  MILLI-SECOND COUNTER FOR REAL TIME CLOCK
48H                  SECOND COUNTER FOR REAL TIME CLOCK--HIGH
                     BYTE
49H                  SECOND COUNTER FOR REAL TIME CLOCK--LOW
                     BYTE
4AH                  TIMER 0 RELOAD FOR REAL TIME CLOCK
4BH         !        USER ARGUMENT FOR ONTIME--HIGH BYTE
4CH         !        USER ARGUMENT FOR ONTIME--LOW BYTE
4DH THRU 0FFH        8052AH STACK SPACE AND USER WORKING SPACE

EXTERNAL MEMORY ALLOCATION: (VERSION 1.1)

LOCATION(S) IN HEX   MCS BASIC-52 USAGE

00H THRU 03H   !     NOT USED, RESERVED
04H                  LENGTH OF THE CURRENT EDITED LINE
05H AND 06H          LN NUM IN BINARY OF CURRENT EDITED LINE (H-L)
07H THRU 56H   !     BASIC INPUT BUFFER
56H THRU 5DH   !     BINARY TO INTEGER TEMP
5EH            !     USED FOR RUN TRAP MODE (= 34H)
5FH            !     USED FOR POWER-UP TRAP (= 0A5H)
60H THRU 0FEH        CONTROL STACK
00FH                 CONTROL STACK OVERFLOW
100H                 LOCATION TO SAVE "GET" CHARACTER
101H                 LOCATION TO SAVE ERROR CHARACTER CODE
102H AND 103H        LOCATION TO GO TO ON USER "ONERR" (H-L)
104H AND 105H        TOP OF VARIABLE STORAGE (H-L)
106H AND 107H        FP STORAGE ALLOCATION (H-L)
108H AND 109H        MEMORY ALLOCATED FOR MATRICIES (H-L)
10AH AND 10BH        TOP OF MEMORY ASSIGNED TO BASIC (H-L)
10CH AND 10DH        RANDOM NUMBER SEED (H-L)
1OEH THRU 113H       CRYSTAL VALUE
114H THRU 11FH       FLOATING POINT TEMPS
120H AND 121H        LOCATION TO GO TO ON ONEX1 INTERRUPT (H-L)
122H AND 123H        NUMBER OF BYTES ALLOCATED FOR STRINGS (H-L)
124H AND 125H  !     SOFTWARE SERIAL PORT BAUD RATE (H-L)
126H AND 127H  !     LINE NUMBER FOR ONTIME INTERRUPT (H-L)
128H AND 129H        "NORMAL" PROM PROGRAMMER TIME OUT (H-L)
12AH AND 12BH        "INTELLIGENT" PROM PROGRAMMER TIME OUT (H-L)
12CH                 RESERVED
12DH THRU 1FEH       ARGUMENT STACK

NOTE: (H-L) still means HIGH BYTE--LOW BYTE, in external memory all 16 bit binary numbers are stored with the HIGH BYTE in the first (lower order) address and the LOW BYTE in the next sequential address.

1.2 USING THE PWM STATEMENT

The PWM statement can be used to generate quite accurate frequencies. The following table lists the reload values 8 octaves of an equal tempered chromatic scale. The reload values are for the first two arguments of the PWM statement, so it is assumed that a square wave is being generated. The reload values assume a 11.0592 MHz crystal.

                   IDEAL       ACTUAL                 HEX
NOTE   OCTAVE    FREQUENCY    FREQUENCY    RELOAD   RELOAD

 C        1       32.703       32.704      14090     370AH
 C#       1       34.648       34.649      13299     33F3H
 D        1       36.708       36.708      12553     3109H
 D#       1       38.891       38.889      11849     2E49H
 E        1       41.203       41.202      11184     2BBOH
 F        1       43.654       43.653      10556     293CH
 F#       1       46.246       46.215       9963     26EBH
 G        1       48.999       49.000       9404     24BCH
 G#       1       51.913       51.915       8876     22ACH
 A        1       55.000       55.001       8378     20BAH
 A#       1       58.270       58.270       7908     1EE4H
 B        1       61.735       61.736       7464     1D28H
 C        2       65.406       65.408       7045     1B85H
 C#       2       69.296       69.293       6650     19FAH
 D        2       73.416       73.411       6277     1885H
 D#       2       77.782       77.785       5924     1724H
 E        2       82.406       82.403       5592     15D8H
 F        2       87.308       87.306       5278     149EH
 F#       2       92.498       92.493       4982     1376H
 G        2       97.998       98.000       4702     125EH
 G#       2       103.826      103.830      4438     1156H
 A        2       110.000      110.002      4189     105DH
 A#       2       116.540      116.540      3954     0F72H
 B        2       123.470      123.472      3732     0E94H
 C        3       130.812      130.798      3523     0DC3H
 C#       3       138.592      138.586      3325     0CFDH
 D        3       146.832      146.845      3138     0C42H
 D#       3       155.564      155.570      2962     0B92H
 E        3       164.812      164.807      2796     0AECH
 F        3       174.616      174.612      2639     0A4FH
 F#       3       184.996      184.986      2491     09BBH
 G        3       195.996      196.001      2351     092FH
 G#       3       207.652      207.661      2219     08ABH
 A        3       220.000      219.952      2095     082FH
 A#       3       233.080      233.080      1977     07B9H
 B        3       246.940      246.946      1866     074AH
 C        4       261.624      261.669      1761     06E1H
 C#       4       277.184      277.256      1662     067EH
 D        4       293.664      293.690      1569     0621H
 D#       4       311.128      311.141      1481     05C9H
 E        4       329.624      329.614      1398     0576H
 F        4       349.232      349.355      1319     0527H
 F#       4       369.992      370.120      1245     04DDH
 G        4       391.992      391.836      1176     0498H
 G#       4       415.304      415.135      1110     0456H
 A        4       440.000      440.114      1047     0417H
 A#       4       466.160      465.925      989      03DDH
 B        4       493.880      493.890      933      03A5H
 C        5       523.248      523.042      881      0371H
 C#       5       554.368      554.512      831      033FH
 D        5       587.238      587.006      785      0311H
 D#       5       622.256      621.862      741      02E5H
 E        5       659.248      659.228      699      02BBH
 F        5       698.464      698.182      660      0294H
 F#       5       739.984      739.647      623      026FH
 G        5       783.984      783.674      588      024CH
 G#       5       830.608      830.270      555      022BH
 A        5       880.000      879.389      524      020CH
 A#       5       932.320      932.793      494      01EEH
 B        5       987.760      986.724      467      01D3H
 C        6      1046.496     1047.272      440      01B8H
 C#       6      1108.736     1107.692      416      01A0H
 D        6      1174.656     1175.510      392      0188H
 D#       6      1244.512     1245.405      370      0172H
 E        6      1318.496     1320.343      349      015DH
 F        6      1396.928     1396.364      330      014AH
 F#       6      1479.968     1481.672      311      0137H
 G        6      1567.968     1567.347      294      0126H
 G#       6      1661.216     1663.538      277      0115H
 A        6      1760.000     1758.779      262      0106H
 A#       6      1864.640     1865.587      247      00F7H
 B        6      1975.520     1977.682      233      00E9H
 C        7      2092.992     2094.545      220      00DCH
 C#       7      2217.472     2215.385      208      00DOH
 D        7      2349.312     2351.020      196      00C4H
 D#       7      2489.024     2490.811      185      00B9H
 E        7      2636.992     2633.143      175      00AFH
 F        7      2793.856     2792.727      165      00A5H
 F#       7      2959.936     2953.846      156      009CH
 G        7      3135.936     3134.694      147      0093H
 G#       7      3322.432     3315.108      139      008BH
 A        7      3520.000     3517.557      131      0083H
 A#       7      3729.280     3716.129      124      007CH
 B        7      3951.040     3938.362      117      0075H
 C        8      4185.984     4189.091      110      006EH
 C#       8      4434.944     4430.770      104      0068H
 D        8      4698.624     4702.041       98      0062H
 D#       8      4987.048     5008.695       92      005CH
 E        8      5273.984     5296.552       87      0057H
 F        8      5587.712     5619.512       82      0052H
 F#       8      5919.872     5907.692       78      004EH
 G        8      6217.872     6227.027       74      004AH
 G#       8      6644.864     6678.261       69      0045H
 A        8      7040.000     7089.231       65      0041H
 A#       8      7458.560     7432.258       62      003EH
 B        8      7902.080     7944.827       58      003AH

The following program generates the appropriate reload values for the PWM statement, using any crystal. The user enters the desired frequency and the crystal and the program determined the reload values and errors.

>1O INPUT "ENTER CRYSTAL FREQUENCY - ",X
>20 T-12/X
>30 INPUT "ENTER DESIRED FREQUENCY FOR PWM - ",F
>40 F1=1/F
>50 C=(F1/T)/2 : REM CALCULATE RELOAD VALUE
>60 IF C<20 THEN 30
>70 C1=C-INT(C) : REM CALCULATE FRACTION
>80 IF C1<.5 THEN 90 : C=C+1
>90 PRINT : PRINT "THE DESIRED FREQUENCY IS - ",X,"HZ"
>100 C=INT(C) : PRINT
>110 PRINT "THE ACTUAL FREQUENCY IS - ",1/(2*C*T),"HZ"
>120 PRINT
>130 PRINT "THE RELOAD VALUE FOR PWM IS - ",C," IN HEX - ",: PH1.C
>140 INPUT "ANOTHER FREQUENCY, 1=YES. 0=N0 - ",Q
>150 1F Q=1 THEN 20

1.3 BAUD RATES AND CRYSTALS

The 16 bit auto-reload timer/counter (TIMER2) that is used to generate baud rates for the MCS BASIC-52 device is capable of generating accurate baud rates with a number of crystals. The following is a list of crystals that will accurately generate 9600 baud on the MCS BASIC-52 device. Additionally, the crystal values on the left hand side of the table will accurately generate 19200 baud.

    XTAL         RCAP2 RELOAD         XTAL      RCAP2 RELOAD

   3680400           65524          3993600        65523
   4300800           65522          4608000        65521
   4915200           65520          5222400        65519
   5529600           65518          5836800        65517
   6144000           65516          6451200        65515
   6758400           65514          7065600        65513
   7372800           65512          7680000        65511
   7987200           65510          8294400        65509
   8601600           65508          8908800        65507
   9216000           65506          9523200        65505
   9830400           65504          10137600       65503
  10444800           65502          10752000       65501
  11059200           65500          11366400       65499
  11673600           65498          11980800       65497

With the crystals listed above. the accuracy of the baud rate generator and the REAL TIME CLOCK will depend ONLY on the absolute accuracy of the crystal. Note that the baud rate generator for the 8052AH is so accurate that any crystal above 10 MHz will generate 9600 baud to within 1.5% accuracy.

The following program generates the appropriate TIMER2 reload values for a given baud rate. The user supplies the system clock frequency and the desired baud rate and the program calculates the proper TIMER2 reload value. Additionally, percent error, for both the baud rate generator and MCS BASlC-52's REAL TIME CLOCK are calculated and displayed.

>1O INPUT"ENTER CRYSTAL - ",X
>20 INPUT"ENTER BAUD RATE - ",B
>30 R=X/(32*B) : T=X/76800
>40 R1=R-INT(R) : T1=T-INT(T)
>50 IF R1<.5 THEN 80
>60 R1=1-R1
>70 R=R+1
>80 IF T1<.5 THEN 110
>90 T1=1-T1
>100 T=T+1
>110 PRINT "TIMER2 RELOAD VALUE IS - ",USING(######),INT(65536-R)
>120 PRINT "BAUD RATE ERROR IS - ",USING(## ###),(R1/R)*100,"%"
>130 PRINT "REAL TIME CLOCK ERROR IS - "(T1/T)*100,"/."

1.4 QUICK REFERENCE

COMMANDS:

COMMAND         FUNCTION                                  EXAMPLE(S)

RUN             Execute a program                         RUN

CONT            CONTinue after a STOP or control-C        CONT

LIST            LIST program to the console device        LIST
                                                          LIST 10-50

LIST#           LIST program to serial printer            LIST#
                                                          LIST# 50

LIST@           LIST program to user driver (version 1.1  LIST@
                only)                                     LIST@ 50

NEW             erase the program stored in RAM           NEW

NULL            set NULL count after carriage return-     NULL
                line feed                                 NULL 4

RAM             evoke RAM mode, current program in        RAM
                READ/WRITE memory

ROM             evoke ROM mode, current program in        ROM
                ROM/EPROM memory                          ROM 3

XFER            transfer a program from ROM/EPROM to      XFER
                RAM

PROG            save the current program in EPROM         PROG

PROG1           save baud rate information in EPROM       PROG1

PROG2           save baud rate information in EPROM       PROG2
                and execute program after RESET

PROG3           save baud rate and MTOP information in    PROG3
                EPROM (version 1.1 only)

PROG4           save baud rate and MTOP information in    PROG4
                EPROM and execute program after
                RESET (version 1.1 only)

PROG5           same as PROG4 except that external        PROG5
                RAM is not cleared on RESET or power
                up if external RAM contains a 0A5H in
                location 5EH (version 1.1 only)

PROG6           same as PROG6 except that external        PROG6
                code location 4039H is CALLED after
                RESET (version 1.1 only)

FPROG           save the current program in EPROM         FPROG
                using the INTELligent algorithm

FPROG1          save baud rate information in EPROM       FPROG1
                using the INTELligent algorithm

FPROG2          save baud rate information in EPROM       FPROG2
                and execute program after RESET, use
                INTELligent algorithm

FPROG3          same as PROG3, except INTELligent         FPROG3
                programming algorithm is used (version
                1.1 only)

FPROG4          same as PROG4, except INTELligent         FPROG4
                programming algorithm is used (version
                1.1 only)

FPROG5          same as PROG5, except INTELligent         FPROG5
                programming algorithm is used (version
                1.1 only)

FPROG6          same as PROG6, except INTELligent         FPROG6
                programming algorithm is used (version
                1.1 only)

BAUD            set baud rate for line printer port       BAUD 1200

CALL            CALL assembly language program            CALL 9000H

CLEAR           CLEAR variables, interrupts and Strings   CLEAR

CLEARS          CLEAR Stacks                              CLEARS

CLEARI          CLEAR Interrupts                          CLEARI

CLOCK1          enable REAL TIME CLOCK                    CLOCK1

CLOCK0          disable REAL TIME CLOCK                   CLOCK0

DATA            DATA to be read by READ statement         DATA 100

READ            READ data in DATA statement               READ A

RESTORE         RESTORE READ pointer                      RESTORE

DIM             allocate memory for arrayed variables     DIM A(20)

DO              set up loop for WHILE or UNTIL            DO

UNTIL           test DO loop condition (loop if false)    UNTIL A= 10

WHILE           test DO loop condition (loop if true)     WHILE A= B

END             terminate program execution               END

FOR-TO-{STEP}   set up FOR-NEXT loop                      FOR A= 1 TO 5

NEXT            test FOR-NEXT loop condition              NEXT A

GOSUB           execute subroutine                        GOSUB 1000

RETURN          RETURN from subroutine                    RETURN

GOTO            GOTO program line number                  GOTO 500

ON GOTO         conditional GOTO                          ON A GOTO 5,20

ON GOSUB        conditional GOSUB                         ON A GOSUB 2,6

IF-THEN-{ELSE}  conditional test                          IF A<B THEN A=0

INPUT           INPUT a string or variable                INPUT A

LET             assign a variable or string a value       LET A= 10
                (LET is optional)

ONERR           ONERRor GOTO line number                  ONERR 1000

ONTIME          generate an interrupt when TIME is equal  ONTIME 10, 1000
                to or greater than ONTIME argument-line
                number is after comma

ONEX1           GOSUB to line number following ONEX1      ONEX1 1000
                when INT1 pin is pulled low

PRINT           PRINT variables, strings or literals      PRINT A
                P. is shorthand for PRINT

PRINT#          PRINT to software serial port             PRINT# A

PH0.            PRINT HEX mode with zero suppression      PH0. A

PH1.            PRINT HEX mode with no zero               PH1. A
                suppression

PH0.#           PH0. to line printer                      PH0.# A

PH1.#           PH1.# to line printer                     PH1.# A

PRINT@          PRINT to user defined driver (version 1.1 PRINT@ 5*5
                only)

PH0.@           PH0. to user defined driver (version 1.1  PH0. @
                only)                                     XBY(5EH)

PH1.@           PH1. to user defined driver (version 1.1  PH1.@ A
                only)

PGM             Program an EPROM (version 1.1 only)       PGM

PUSH            PUSH expressions on argument stack        PUSH 10, A

POP             POP argument stack to variables           POP A, B, C

PWM             PULSE WIDTH MODULATION                    PWM 50, 50, 100

REM             REMark                                    REM DONE

RETI            RETurn from Interrupt                     RETI

STOP            break program execution                   STOP

STRING          allocate memory for STRlNGs               STRING 50, 10

UI1             evoke User console Input routine          UI1

UI0             evoke BASIC console Input routine         UI0

UO1             evoke User console Output routine         UO1

UO0             evoke BASIC console Output routine        UO0

ST@             store top of stack at user specified      ST@ 1000H
                location (version 1.1 only)               ST@ A

LD@             load top of stack from user specified     LD@ 1000H
                location (version 1.1 only)               LD@ A

IDLE            wait for interrupt (version 1.1 only)     IDLE

RROM            run a program in EP(ROM) (version 1.1     RROM 3
                only)

OPERATORS--DUAL OPERAND:

OPERATOR        FUNCTION                          EXAMPLE(S)

+               ADDITION                          1 + 1

/               DIVISION                          10/2

**              EXPONENTATION                     2**4

*               MULTIPLICATION                    4*4

-               SUBTRACTION                       8 - 4

.AND.           LOGICAL AND                       10.AND.5

.OR.            LOGICAL OR                        2.0R.1

.XOR.           LOGICAL EXCLUSIVE OR              3.XOR.2

OPERATORS--SINGLE OPERAND:

ABS( )          ABSOLUTE VALUE                    ABS(-3)

NOT( )          ONES COMPLEMENT                   NOT(0)

INT( )          INTEGER                           INT(3.2)

SGN( )          SIGN                              SGN( - 5)

SQR( )          SQUARE ROOT                       SQR(100)

RND             RANDOM NUMBER                     RND

LOG( )          NATURAL LOG                       LOG(10)

EXP( )          "e" (2.7182818) TO THE X          EXP(10)

SIN( )          RETURNS THE SINE OF ARGUMENT      SIN(3.14)

COS( )          RETURNS THE COSINE OF             COS(0)
                ARGUMENT

TAN( )          RETURNS THE TANGENT OF            TAN(.707)
                ARGUMENT

ATN( )          RETURNS ARCTANGENT OF             ATN(1)
                ARGUMENT

OPERATORS--SPECIAL FUNCTION:

CBY( )           READ PROGRAM MEMORY              P. CBY(4000)

DBY( )           READ/ASSIGN INTERNAL DATA        DBY(99)=10
                 MEMORY

XBY( )           READ/ASSIGN EXTERNAL DATA        P. XBY(10)
                 MEMORY

GET              READ CONSOLE                     P. GET

IE               READ/ASSIGN IE REGISTER          IE=82H

IP               READ/ASSIGN IP REGISTER          IP=0

PORT1            READ/ASSIGN l/O PORT 1 (P1)      PORT1=0FFH

PCON             READ/ASSIGN PCON REGISTER        PCON=0

RCAP2            READ/ASSIGN RCAP2                RCAP2=100
                 (RCAP2H:RCAP2L)

T2CON            READ/ASSIGN T2CON REGISTER       P. T2CON

TCON             READ/ASSIGN TCON REGISTER        TCON=10H

TMOD             READ/ASSIGN TMOD REGISTER        P. TMOD

TIME             READ/ASSIGN THE REAL TIME CLOCK  P. TIME

TIMER0           READ/ASSIGN TIMER0 (TH0: TL0)    TIMER0=0

TIMER1           READ/ASSIGN TIMER1 (TH1: TL1)    P. TIMER1

TIMER2           READ/ASSIGN TIMER2 (TH2: TL2)    TIMER2=0FFH

STORED CONSTANT:

PI               PI -- 3.1415926                   PI

1.5 INSTRUCTION SET SUMMARY

COMMANDS             STATEMENTS           OPERATORS
RUN                  BAUD                 ADD (+)
CONT                 CALL                 DIVIDE (/)
LIST                 CLEAR                EXPONENTIATION (**)
LIST#                CLEAR(S&I)           MULTIPLY (*)
LIST@ (V1.1)         CLOCK(1&0)           SUBTRACT (-)
NEW                  DATA                 LOGICAL AND (.AND.)
NULL                 READ                 LOGICAL OR (.OR.)
RAM                  RESTORE              LOGICAL X-OR (.XOR.)
ROM                  DIM                  LOGICAL NOT (.OR.)
XFER                 DO-WHILE             ABS( )
PROG                 DO-UNTIL             INT( )
PROG1                END                  SGN( )
PROG2                FOR-TO-STEP          SQR( )
PROG3 (V1.1)         NEXT                 RND
PROG4 (V1.1)         GOSUB                LOG( )
PROG5 (V1.1)         RETURN               EXP( )
PROG6 (V1.1)         GOTO                 SIN( )
FPROG                ON-GOTO              COS( )
FPROG1               ON-GOSUB             TAN( )
FPROG2               IF-THEN-ELSE         ATN( )
FPROG3 (V1.1)        INPUT                =, >, >=, <, <=, <>
FPROG4 (V1.1)        LET                  ASC( )
FPROG5 (V1.1)        ONERR                CHR( )
FPROG6 (V1.1)        ONEX1                CBY( )
                     ONTIME               DBY( )
                     PRINT                XBY( )
                     PRINT#               GET
                     PRINT@ (V1.1)        IE
                     PH0.                 IP
                     PH0.#                PORT1
                     PH0.@ (V1.1)         PCON
                     PH1.                 RCAP2
                     PH1.#                T2CON
                     PH1.(@ (V1.1)        TCON
                     PGM (V1. 1 )         TMOD
                     PUSH                 TIME
                     POP                  TIMER0
                     PWM                  TIMER1
                     REM                  TIMER2
                     RETI                 XTAL
                     STOP                 MTOP
                     STRING               LEN
                     UI(1&0)              FREE
                     U0(1&0)              PI
                     LD@ (V1. 1 )
                     ST@ (V1. 1 )
                     IDLE (V1.1)
                     RROM (V1. 1 )

1.6 FLOATING POINT FORMAT

MCS BASIC-52 stores all floating point numbers in a normalized packed BCD format with an offset binary exponent. The simplest way to demonstrate the floating point format is to use an example. If the number PI (3.1415926) was stored in location X, the following would appear in memory.

LOCATION VALUE DESCRIPTION

  X    81H   EXPONENT--81H = 10**1, 82H = 10**2,
                       80H = 10**0, 7FH = 10**-1 etc.
                       THE NUMBER ZERO IS REPRESENTED WITH A
                       ZERO EXPONENT

 X-1   00H   SIGN BIT--00H = POSITIVE, 01 H = NEGATIVE OTHER BITS ARE
                     USED AS TEMPS ONLY DURING A CALCULATION

 X-2   26H   LEAST SIGNIFICANT TWO DIGITS

 X-3   59H   NEXT LEAST SIGNIFICANT TWO DIGITS

 X-4   41H   NEXT MOST SIGNIFICANT TWO DIGITS

 X-5   31H   MOST SIGNIFICANT TWO DIGITS

Because MCS BASIC-52 normalizes all numbers, the most significant digit is never a zero unless the number is zero.

1.7 STORAGE ALLOCATION

This section is intended to answer the question--where does MCS BASIC-52 store its variables and strings?

Two 16 bit pointers stored in external memory control the allocation of strings and variables and an additional two pointers control the allocation of scalar variables and dimensioned variables. These pointers are located and defined as follows:

LOCATION (H-L) NAME DESCRIPTION

10AH-10BH     MTOP   THE TOP OF RAM THAT IS ASSIGNED TO BASIC

104H-105H    VARTOP  VARTOP = MTOP - (THE NUMBER OF BYTES OF MEM-
                     ORY THAT THE USER HAS ALLOCATED FOR STRINGS).
                     IF STRINGS ARE NOT USED, VARTOP = MTOP

106H-107H    VARUSE  AFTER A NEW, CLEAR, OR RUN IS EXECUTED, VARUSE =
                     VARTOP, EVERYTIME THE USER ASSIGNS OR USES A
                     VARIABLE VARUSE IS DECREMENTED BY A COUNT OF 8.

108H-109H    DIMUSE  AFTER A NEW, CLEAR, OR RUN IS EXECUTED, DIMUSE =
                     [LENGTH OF THE USER PROGRAM THAT IS IN RAM MEM-
                     ORY + STARTING ADDRESS OF THE USER PROGRAM IN
                     RAM (512) + THE LENGTH OF ONE FLOATING POINT
                     NUMBER (6)]. IF NO PROGRAM IS IN RAM MEMORY,
                     DIMUSE = 518 AFTER A CLEAR IS EXECUTED

MCS BASIC-52 stores string variables between VARTOP and MTOP. $(0) is stored from VARTOP to VARTOP + (user defined string length + I ), $(1 ) is stored from VARTOP + (user defined string length + I) + I to VARTOP + 2 * (user defined string length + 1) etc. If MCS BASIC-52 attempts to access a string that is outside the bounds established by MTOP, a MEMORY ALLOCATION ERROR is generated.

Now, Scalar variables are stored from VARTOP "down" and Dimensioned variables are stored from DIMUSE "up." When the user dimensions a variable either implicity or explicity the value of DIMUSE increases by the number of bytes required to store that dimensioned variable. For example, if the user ex- ecutes a DIM A(10) statement, DIMUSE would increase by 66. This is because the user is requesting storage for 11 numbers (A(0) through A(10)) and each number requires 6 bytes for storage and 6 * 11 = 66.

As mentioned in the previous example, everytime the user defines a new variable the VARUSE pointer decrements by a count of 8. Six of the eight counts are due to the memory required to store a floating point number and the other two counts are the storage required for the variable name (i.e. A1, B7, etc). The variable B7 would be stored as follows:

LOCATION VALUE DESCRIPTION

  X     37H  THE ASCII VALUE--7, IF B7 WAS A DIMENSIONED VARIABLE THE
             MOST SIGNIFICANT BIT OF THIS LOCATION WOULD BE SET. IN
             VERSION 1.1 THIS LOCATION ALWAYS CONTAINS THE ASCII
             VALUE FOR THE LAST CHARACTER USED TO DEFINE A
             VARIABLE

 X-1    42H  THE ASCII VALUE--B, IN VERSION 1.1 OF MCS BASIC-52 THIS
             LOCATION CONTAINS THE ASCII VALUE OF THE FIRST CHARAC-
             TER USED TO DEFINE A VARIABLE PLUS 26 * THE NUMBER OF
             CHARACTERS USED TO DEFINE A VARIABLE, IF THE VARIABLE
             CONTAINS MORE THAN 2 CHARACTERS.

 X-2    ??   THE NEXT SIX LOCATIONS WOULD CONTAIN THE FLOATING
 THRU        POINT NUMBER THAT THE VARIABLE IS ASSIGNED TO, IF THE
 X-7         VARIABLE WAS A SCALAR VARIABLE. IF THE VARIABLE WAS Dl-
             MENSIONED, X-2 WOULD CONTAIN THE LIMIT OF THE DIMENSION
             (I.E. THE MAX. NUMBER OF ELEMENTS IN THE ARRAY) AND
             X-3: X-4 WOULD CONTAIN THE BASE ADDRESS OF THE ARRAY.
             THIS ADDRESS IS EQUAL TO THE OLD VALUE OF THE DIMUSE
             POINTER BEFORE THE ARRAY WAS CREATED

Whenever a new scalar or dimensioned variable is used in a program, MCS BASIC-52 checks both the DIMUSE nd VARUSE pointers to make sure that VARUSE > DIMUSE. If the relationship is not true, a MEMORY ALLOCATION ERROR is generated.

To Summarize:

Strings are stored from VARTOP to MTOP.

Scalar variables are stored from VARTOP "down" and VARUSE points to the next available scalar location.

Dimensioned variables are stored from the end of the user program in RAM "up." If no program is in RAM this location is 518 . DIMUSE keeps track of the number of bytes the user has allocated for dimensioned variables.

If DIMUSE >= VARUSE a MEMORY ALLOCATION ERROR is generated

1.8 FORMAT OF AN MCS BASIC-52 PROGRAM

This section answers the question "How does MCS BASIC-52 store a program?"

LINE FORMAT

Each line of MCS BASIC-52 text consists of tokens and ASCII characters, plus 4 bytes of overhead. Three of these four bytes are stored at the beginning of every line. The first byte contains the length of a line in binary and the second two bytes are the line number in binary. The fourth byte is stored at the end of the line and this byte is always a 0DH or a carriage return in ASCII. An example of a typical line is shown below, assume that this is the first line of a program in RAM.

10 FOR I = I TO 10: PRINT 1: NEXT I

LOCATION BYTE DESCRIPTION

512    11H  THE LENGTH OF THE LINE IN BINARY (17D BYTES)
513    00H  HIGH BYTE OF THE LINE NUMBER
514    0AH  LOW BYTE OF THE LINE NUMBER
515   0A0H  THE TOKEN FOR "FOR"
516    49H  THE ASCII CHARACTER "I"
517   0EAH  THE TOKEN FOR "="
518    31H  THE ASCII FOR "1"
519   0A6H  THE TOKEN FOR "TO"
520    31H  THE ASCII FOR "1"
521    30H  THE ASCII FOR "0"
522    3AH  THE ASCII FOR ":"
523    89H  THE TOKEN FOR "PRINT"
524    49H  THE ASCII FOR "I"
525    3AH  THE ASCII FOR ":"
526    97H  THE TOKEN FOR "NEXT"
527    49H  THE ASCII FOR "I"
528    0DH  END OF LINE (CARRIAGE RETURN)

TO FIND THE LOCATION OF THE NEXT LINE, THE LENGTH OF THE LINE IS ADDED TO THE
LOCATION WHERE THE LENGTH OF THE LINE IS STORED. IN THIS EXAMPLE,
512 + 17D = 529, WHICH IS WHERE THE NEXT LINE IS STORED.

The END of a program is designated by the value 01H. So, in the previous example if line 10 was the only line in the program, location 529 would contain the value 01H. A program simply consists of a number of lines packed together in one continuous block with the last line ending in a 0DH, 01H sequence.

EPROM FILE FORMAT

The EPROM FILE format consists of the same line and program format, previously described except that each program in the EPROM file begins with the value 55H. The value 55H is only used by MCS BASIC- 52 to determine if a valid program is present. If the user types ROM 6, MCS BASIC-52 actually goes through the first program stored in EPROM line by line until the END of PROGRAM (01H) is found, then it examines the next location to see if a 55H is stored in that location. It then goes through that program line by line. This process is repeated 6 times. If the character 55H is not found after the end of a program, MCS BASIC-52 will return with the PROM MODE error message. This would mean that less than six programs were stored in that EPROM.

The first program stored in EPROM (ROM 1) always begins at location 8010H and this location will always contain a 55H. The actual user program will begin at location 8011H.

EPROM locations 8000H through 800FH are reserved by MCS BASIC-52. These locations contain ini- tialization information when the PROGX options are used. Version 1.0 of MCS BASIC-52 only used the first three bytes of this reserved EPROM area. The information stored in these bytes is as follows:

LOCATION DESCRIPTION

8000H  CONTAINED A 31H IF PROG 1 WAS USED, CONTAINED A 32H IF PROG 2
       WAS USED

8001H  BAUD RATE (RCAP2H)

8002H  BAUD RATE (RCAP2L)

Version 1.1 of MCS BASIC-52 uses the same locations as Version 1.0, but additionally locations 8003H and 8004H (high byte, low byte) are used to store the MTOP information for the PROG 3, 4, 5, 6 options.

IMPORTANT NOTE--

The PROG X options simply store ASCII character following the PROG command in loction 8000H. That is why PROG 1 stores a 31H in location 8000H, PROG 2 a 32H, PROG 3 (Version 1.1 only) a 33H etc. If the user employs the user defined reset option defined in Chapter 11 of this manual, it would be possible for the user to create unique PROG options. For example, PROG A would store a 41H in location 8000H and upon RESET the user could examine this location with an assembly language routine and generate a unique PROG A reset routine for that particular application.

1.9 ANSWERS TO A FEW QUESTIONS

QUESTION

Why can't MCS BASIC-52 access the 8052's SPECIAL FUNCTION REGISTER SCON?

ANSWER

The only time the user would likely change the contents of SCON is if the user is writing custom I/O drivers in assembly language. If the user is writing assembly language I/O drivers, then the user can change the contents of SCON in assembly language. Changing the contents of SCON can cause MCS BASIC- 52's console routines to crash.

QUESTION

I have written an upload/download routine using my computer, but when I download a program, MCS BASIC-52 misses characters, why?

ANSWER

MCS BASIC-52 is actually capable of accepting characters at 38,400 baud. The problem is that after MCS BASIC-52 receives a carriage return (cr), it tokenizes the line of text that was just entered. Depending on how complicated and how long the line is, MCS BASIC-52 can take up to a couple of hundred milliseconds to tokenize the line. If the user keeps stuffing characters into the serial port while MCS BASIC-52 is tokenizing the line, the characters will be lost. What the user must do in the download routine is wait until MCS BASIC-52 responds with the prompt character (>) after a carriage return is sent to the MCS BASIC- 52 device. The prompt (>) informs the user that MCS BASIC-52 is ready to receive characters from the console device.

QUESTION

I am writing in assernbly language and I notice that the 8052AH has no decrement DPTR instruction. What is the easiest. shonest or simplest way to decrement the DPTR?

ANSWER

The shortest one we know is:

         XCH    A,DPL     ; SWAPA<>DPL
         JNZ    DECDP     ; DPH = DPH-1 IF DPL = O
         DEC    DPH
DECDP:   DEC    A         ; DPL = DPL-1
         XCH    A,DPL

This routine affects no flags or registers (except the DPTR) either!

QUESTION

After RESET or power-up, MCS BASIC-52 does not return the proper value for MTOP, what's the problem?

ANSWER

Virtually everytime this problem occurs it is because something is wrong with the decoding circuitry in the system or one or more of the address lines to the RAM are open or shorted. The user should make sure that all of the address lines to the system RAM are connected properly!

A simple memory test can be implemented in the COMMAND MODE to verify the addressing to the RAM. First set XBY(1000H) = 55, then walk ones across the address (i.e. P. XBY(1001H) - P. XBY(1002H) - P. XBY(1004H) -- P. XBY(1008H) P. XBY(1010H)) until all locations are tested. If for instance, P. XBY(1008H) returns a result of 55, then address line 3 (A3) would probably be open or shorted.

1.11 8052AH SPECIAL FUNCTION REGISTERS

The following details the operation of the special function registers on the 8052AH:

SYMBOL
NAME                          NAME             ADDRESS     MCS BASIC-52

ACC     Accumulator                                0E0H  NOT ADDRESSABLE

B       B Register                                 0F0H  NOT ADDRESSABLE

PSW     Program Status Word                        0D0H  NOT ADDRESSABLE

SP      Stack Pointer                               81H  NOT ADDRESSABLE

DPTR    Data Pointer 2 Bytes:
DPH     Low Byte                                    82H  NOT ADDRESSABLE
DPL     High Byte                                   83H  NOT ADDRESSABLE

P0      Port 0                                      80H  NOT ADDRESSABLE

P1      Port 1                                      90H  PORT1

P2      Port 2                                     0A0H  NOT ADDRESSABLE

P3      Port 3                                     0B0H  NOT ADDRESSABLE

IP      Interrupt Priority Control                 0B8H  IP

IE      Interrupt Enable Control                   0A8H  IE

TMOD    Timer/Counter Mode Control                  89H  TMOD

TCON    Timer/Counter Control                       88H  TCON

T2CON   Timer/Counter 2 Control                    0C8H  T2CON

TH0     Timer/Counter 0 High Byte                   8CH \
                                                           TIMER0
TL0     Timer/Counter 0 Low Byte                    8AH /

TH1     Timer/Counter 1 High Byte                   8DH \
                                                           TIMER1
TL1     Timer/Counter 1 Low Byte                    8BH /

TH2     Timer/Counter 2 High Byte                  0CDH \
                                                           TIMER2
TL2     Timer/Counter 2 Low Byte                   0CCH /

RCAP2H  T/C 2 Capture Reg. High Byte               0CBH \
                                                           RCAP2
RCAP2L  T/C 2 Capture Reg. Low Byte                0CAH /

SCON    Serial Control                              98H  NOT ADDRESSABLE

SBUF    Serial Data Buffer                          99H  NOT ADDRESSABLE

PCON    Power Control                               87H  NOT ADDRESSABLE

PSW:    PROGRAM STATUS WORD. ADDRESS 0D0H

           -----------------------------------------
           | CY | AC | F0 | RS1 | RS0 | OV | - | P |
           -----------------------------------------

           CY   PSW.7   Carry Flag.
           AC   PSW.6   Auxiliary Carry Flag.
           F0   PSW.5   Flag 0 available to the user for general purpose.
           RS1  PSW.4   Register Bank selector bit 1.
           RS0  PSW.3   Register Bank selector bit 0.
           OV   PSW.2   Overflow Flag.
           --   PSW.1   RESERVED FOR FUTURE USE.
           P    PSW.0   PARITY FLAG.

PCON:   POWER CONTROL REGISTER. NOT BIT ADDRESSABLE.

SMOD

SMOD Doubles the baud rate when TIMER 1 is used to generate the baud rate for the serial port.
The remaining bits of PCON are not implemented on the MCS BASIC-52 device.

TMOD: Timer/Counter Mode Controlregister

 
                          (MSB)                               (LSB)
 
                         -------------------------------------------
                         |GATE| C/T | M1 | M0 |GATE| C/T | M1 | M0 |
                         -------------------------------------------
                               TIMER 1        |     TIMER 0


GATE Gating control When set. Timer/Counter "x"  M1 M0   Operating Mode
is enabled only while "INTx" pin is high and     0  0    MCS-48 Timer "TLx" serves as five-bit
"TRx" control pin is set. When cleared Timer             prescaler.
"x" is enabled whenever "TRx" control bit is     0  1    16 bit Timer/Counter "THx" and "TLX"
set                                                      are cascaded; there is no prescaler

C/T Timer or Counter Selector Cleared for Timer  1  0    8-bit auto-reload timer-counter "THx"
operation (input from internal system clock).            holds a value which is to be reloaded into
Set for Counter operation (input from "Tx"               "TLx" each time it overflows.
input pin).

                                                         (Timer 0) TL0 is an eight-bit timer
                                                         counter-controlled by the
                                                         standard Timer 0 control bits
                                                         TH0 is an eight-bit timer only
                                                         controlled by Timer 1 control
                                                         blts.

                                                         (Timer 1) Timer-counter 1 stopped.

Timer/Counter2 Control Register


       (MSB)                                               (LSB)

      -----------------------------------------------------------
      | TF2 | EXF2 T RCLK | TCLK T EXEN2 | TR2 | C/T2 | CP/RLS2 |
      -----------------------------------------------------------

Symbol  Position             Name and Significance


TF2 T2CON.7     Timer 2 overflow flag set by a Timer 2 overflow and must be cleared by software. TF2
                will not be set when either RCLK = 1 or TCLK = 1.

EXF2 T2CON.6    Timer 2 external flag set when either a capture or reload is caused by a negative
                transition on T2EX and EXEN2 = 1. When Timer 2 interrupt is enabled, EXF2 = 1
                will cause the CPU to vector to the Timer 2 interrupt routine. EXF2 must be cleared by
                software.

RCLK T2CON.5    Receive clock flag. When set, causes the serial port to use Timer 2 overflow pulses
                for its receive clock in modes 1 and 3. RCLK = 0 causes Timer 1 overflow to be used
                for the receive clock.

TCLK T2CON.4    Transmit clock flag. When set, causes the serial port to use Timer 2 overflow pulses
                for its transmit clock in modes 1 and 3. TCLK = 0 causes Timer 1 overflows to be
                used for the transmit clock.

EXEN2 T2CON.3   Timer 2 external enable flag. When set, allows a capture or reload to occur as a result
                of a negative transition on T2EX if Timer 2 is not being used to clock the serial port.
                EXEN2 = 0 causes Timer 2 to ignore events at T2EX.

TR2 T2CON.2     Start/stop control for Timer 2. A logic 1 starts the timer.

C/T2 T2CON.1    Timer or counter select. (Timer 2)
                0 = Internal timer (OSC/12)
                1 = External event counter (falling edge triggered).

CP/RL2 T2CON.0  Capture/Reload flag. When set, captures will occur on negative transitions at T2EX if
                EXEN2 = 1. When cleared, auto reloads will occur either with Timer 2 overflows or
                negative transitions at T2EX when EXEN 2 = 1. When either RCLK = 1 or TCLK = 1,
                this bit is ignored and the timer is forced to auto-reload on Timer 2 overflow.

SCON: Serial Port Control Register

        (MSB)                                   (LSB)

       -----------------------------------------------
       | SM0 | SM1 | SM2 | REN | TB8 | RB8 | TI | RI |
       -----------------------------------------------

where SM0, SM1 specify the serial port mode, as follows:


  SM0 SM1 Mode  Description    Baud
                               Rate

                                                          TB8  is the 9th data bit that will be transmitted in
   0   0   0    shift       fosc /12                           modes 2 and 3. Set or clear by software as
   0   1   1    register    variable                           desired.
   1   0   2    8-bit UART  fosc./64
                9-bit UART  or                            RB8  In modes 2 and 3, is the 9th data bit that
                            fosc /32                           was received. In mode 1, if SM2 = 0, RB8
                                                               is the stop bit that was received. In mode 0,
   1   1   3    9-bit UART variable                            RB8 is not used.

 SM2  enables the multiprocessor communication            TI   is transmit interrupt flag. Set by hardware at
      feature in modes 2 and 3. In mode 2 or 3,                the end of the 8th bit time in mode 0, or at
      if SM2 issetto 1 then RI will not be activated           the beginning of the stop bit in the other
      if the received 9th data bit (RB8) is 0. In              modes, in any serial transmission. Must be
      mode 1, if SM2 = 1 then RI will not be                   cleared by software.
      activated if a valid stop bit was not received.
      In mode 0, SM2 should be 0.                         RI   is receive interrupt flag. Set by hardware at
                                                               the end of the 8th bit time in mode 0, or
 REN  enables serial reception. Set by software to             halfway through the stop bit time in the other
      enable reception. Clear by software to dis-              modes, in any serial reception (except see
      able reception.                                          SM2). Must be cleared by software.



TCON: Timer/Counter Control Register


       (MSB)                                     (LSB)

      -------------------------------------------------
      | TF1 | TR1 | TF0 | TR0 | IE1 | IT1 | IE0 | IT0 |
      -------------------------------------------------

Symbol Position                  Name and Significance               Symbol Position  Name and Significance

  TF1  TCON.7  Timer 1 overflow Flag. Set by        IE1  TCON.3     Interrupt 1 Edge flag. Set by
               hardware on timer/counter ov-                        hardware when external inter-
               erflow. Cleared by hardware                          rupt edge detected. Cleared
               when processor vectors to inter-                     when interrupt processed.
               rupt routine.                        IT1  TCON.2     Interrupt 1 Type control bit. Set
  TR1  TCON.6  Timer 1 Run control bit. Set                         cleared by software to specify
               cleared by software to turn timer/                   falling edge/low level triggered
               counter on/off.                                      external interrupts.
  TF0  TCON.5  Timer 0 overflow Flag. Set by        IE0  TCON.1     Interrupt 0 Edge flag. Set by
               hardware on timer/counter ov-                        hardware whan external inter-
               erflow. Cleared by hardware                          rupt edge detected. Cleared
               when processor vectors to inter-                     when interrupt processed.
               rupt routine.                        IT0  TCON.0     Interrupt 0 Type control bit. SeV
  TR0  TCON.4  Timer 0 Run control bit. Set                         cleared by software to specify
               cleared by software to turn timer/                   falling edge/low level triggered
               counter on/off.                                      external interrupts.

           Interrupt Priority Register                                  Interrupt Enable Register


        (MSB)                      (LSB)                             (MSB)                       (LSB)

       ----------------------------------                           -----------------------------------
       | X | X |PT2| PS |PT1|PX1|PT0|PX0|                           | EA | X |ET2| ES |ET1|EX1|ET0|EX0|
       ----------------------------------                           -----------------------------------

Symbol  Position Function                                     Symbol  Position Function

 --     IP.7              reserved                            EA      IE.7  disables all interrupts. If EA = 0,
                                                                            no interrupt will be acknowl-
 --     IP.6              reserved                                          edged. If EA = 1, each interrupt
                                                                            source is individually enabled or
 PT2    IP.5              defines the Timer 2 interrupt                     disabledbysettingorclearingits
                          priority level. PT2 = 1 programs                  enable bit.
                          it to the higher priority level.
                                                               --     IE.6  reserved
 PS     IP.4              defines the Serial Port interrupt
                          priority level. PS = 1 programs     ET2     IE.5  enables or disables the Timer 2
                          it to the higher priority level.                  overflow or capture interrupt. If
                                                                            ET2 = 0, the Timer 2 interrupt
 PT1    IP.3              defines the Timer 1 interrupt                     is disabled.
                          priority level. PT1 = 1 programs
                          it to the higher priority level.    ES      IE.4  enables or disables the Serial
                                                                            Port interrupt. If ES = 0, the Se-
 PX1    IP.2              defines the External Interrupt 1                  rial Port interrupt is disabled.
                          priority level. PX1 = 1 programs
                          it to the higher priority level.    ET1     IE.3  enables or disables the Timer 1
                                                                            Overflow interrupt. If ET1 = 0,
 PT0    IP.1              defines the Timer 0 interrupt                     theTimer 1 interruptisdisabled.
                          priority level. PT0 = 1 programs
                          it to the higher priority level.    EX1     IE.2  enables or disables External In-
                                                                            terrupt 1. If EX1 = 0, External
 PX0    IP.0              defines the External Interrupt 0                  Interrupt 1 is disabled.
                          priority level. PX0 = 1 programs
                          it to the higher priority level.    ET0     IE.1  enables or disables the Timer 0
                                                                            Overflow interrupt. If ET0 = 0.
                                                                            the Timer 0 Interrupt is disabled.

                                                              EX0     IE.0  enables or disables External In-
                                                                            terrupt 0. If EX0 = 0, External
                                                                            Interrupt 0 is disabled.

1.12 REFERENCES

J. Sack and J: Meadows, Entering BASIC, Science Research Associates, 1973.
C. Pegels, BASIC: A Computer Programming Language, Holden-Day, Inc., 1973.
J. Kemeny and T. Kurtz, BASIC Programming, People Computer Company, 1967.
Albrecht, Finkle, and Brown, BASIC, People Computer Company, 1973.
T. Dwyer, A Guided Tour of Computer Programming in BASIC, Houghton Mifflin Co., 1973.
Eugene H. Barnett, Programming Time Shared Computers in BASIC, Wiley-Interscience, L/C 72-175789.
Programming Language #2, Digital Equipment Corp., Maynard, Mass. 01754.
101 BASIC Computer Games, Digital Equipment Corp., Maynard, Mass. 01754.
What to do After You Hit Return. People Computer Company.
BASIC-80 REFERENCE MANUAL, Intel Corp., Santa Clara, Calif

 

Copyright © Madis Kaal 2000-