MCS BASIC-52 V1.1 provides a simple, but yet effective way for the user to add COMMANDS and/or STATEMENTS to the ones that are provided on the chip. All the user must do is write a few simple programs that will reside in external code memory. The step by step approach is as follows:
The user must first inform the MCS BASIC-52 device that the expansion options are available. This is done by putting the character 5AH in CODE memory location 2002H. When MCS BASIC-52 enters the command mode it will examine CODE memory location 2002H. If a 5AH is in this location, MCS BASIC- 52 will CALL external CODE memory location 2048H. The user must then write a short routine to SET BIT 45 (2DH), which is bit 5 of internal memory location 37 (decimal) and place this routine at code memory location 2048H. Setting BIT 45 tells MCS BASIC-52 that the expansion option is available. The following simple code will accomplish all that is stated above:
ORG 2002H DB 5AH ; ORG 2048H SETB 45 RET
With BIT 45 SET, MCS BASIC-52 will CALL external CODE memory location 2078H everytime it attempts to tokenize a line that has been entered. At location 2078H, the user must load the DPTR (Data Pointer) with the address of the user supplied lookup table, complete with tokens.
The user needs the following information to generate a user token table:
1) THE USER TOKENS ARE THE NUMBRES 10H THROUGH 1FH (16 TOKENS AVAILABLE)
2) THE USER TOKEN TABLE BEGINS WITH THE TOKEN, FOLLOWED BY THE ASCII TEXT THAT IS TO BE REPRESENTED BY THAT TOKEN, FOLLOWED BY A ZERO (00H) INDICATING THE END OF THE ASCII, FOLLOWED BY THE NEXT TOKEN.
3) THE TABLE IS TERMINATED WITH THE CHARACTER 0FFH.
ORG 2078H ; MOV DPTR,#USER_TABLE RET ; ORG 2200H ; THIS DOES NOT NEED TO BE ; ; IN THIS LOCATION USER_TABLE: ; DB 10H ; FIRST TOKEN DB 'DISPLAY' ; USER KEYWORD DB 00H ; KEYWORD TERMINATOR DB 11H ; SECOND TOKEN DB 'TRANSFER' ; SECOND USER KEYWORD DB 00H ; KEYWORD TERMINATOR DB 12H ; THIRD TOKEN (UP TO 16) DB 'ROTATE' ; THIRD USER KEYWORD DB 0FFH ; END OF USER TABLE
This same user table is used when MCS BASIC-52 "de-tokenizes" a line during a LIST.
Step 3 tokenizes the user keyword, this means that MCS BASIC-52 translates the user keyword into the user token. So, in the preceding example, the keyword TRANSFER would be replaced with the token 11H. When MCS BASIC-52 attempts to execute the user token, it first makes sure that the user expansion option BIT is set (BIT 45), then CALLS location 2070H to get the address of the user vector table. This address is placed in the DPTR. The user vector table consist of series of Data Words that define the address of the user assembly language routines.
ORG 2070H ; LOCATION BASIC CALLS TO ; GET USER LOOKUP ; MOV DPTR,#VECTOR_TABLE ; VECTOR_TABLE: ; DW RUN_DISPLAY ; ADDRESS OF DISPLAY ; ROUTINE, TOKEN (10H) DW RUN_TRANSFER ; ADDRESS OF TRANSFER ; ROUTINE, TOKEN (11H) DW RUN_ROTATE ; ADDRESS OF ROTATE ; ROUTINE, TOKEN (12H) ; ORG 2300H ; AGAIN, THESE ROUTINES ; MAY BE PLACED ANYWHERE ; RUN DISPLAY: ; ; USER ASM CODE FOR DISPLAY GOES HERE ; RUN TRANSFER: ; ; USER ASM CODE FOR TRANSFER GOES HERE ; RUN_ROTATE: ; ;USER ASM CODE FOR ROTATE GOES HERE ;
Note that the ordinal position of the DATA WORDS in the user vector table must correspond to the token, so the user statement with the token 10H must be the first DW entry in the vector table, 11H, the second, 12H, the third, and so on. The order of the tokens in the user table is not important!! The following user lookup table would function properly with the previous example:
; USER_TABLE: ; DB 13H ; THE TOKENS DO NOT HAVE DB 'ROTATE' ; TO BE IN ORDER IN THE DB 00H ; USER LOOKUP TABLE DB 10H DB 'DISPLAY' DB 00H DB 12H DB 'TRANSFER' DB 0FFH ; END OF TA8LE
The user may also use the command/statement extension option to re-define the syntax of MCS BASIC- 52. This is done simply by placing your own syntax in the user table and placing the appropriate BASIC token in front of your re-defined keyword. A complete listing of all MCS BASIC-52 tokens and keywords are provided in the back of this chapter. MCS BASIC-52 will always list out the program using the user defined systax, but it will still accept the standard keyword as a valid instruction. As an example, suppose that the user would like to substitute the keyword HEXOUT for PH1., then the user would generate the following entry in the user table:
; USER_TABLE: DB 8FH ; TOKEN FOR PH1. DB 'HEXOUT' ; TO BE IN ORDER IN THE DB 00H ; USER LOOKUP TABLE ; DB 10H D8 'DISPLAY' D8 00H ; REST OF USER_TABLE ; DB 0FFH ; END OF TABLE
MCS BASIC-52 will now accept the keyword HEXOUT and it will function in a manner identical to PH1 . PH1 will still function correctly, however HEXOUT will be displayed when the user LIST a program.
TOKEN KEYWORD TOKEN KEYWORD TOKEN KEYWORD 80H LET 080H ABS 0ECH <= 81H CLEAR 081H INT 0EDH <> 82H PUSH 0B2H SGN 0EEH < 83H GOTO 083H NOT 0EFH > 84H PWM 084H COS 0FOH RUN 85H PH0. 085H TAN 0FlH LIST 86H UI 0B6H SIN 0F2H NULL 87H UO 087H SOR 0F3H NEW 88H POP 088H CBY 0F4H CONT 89H PRINT 089H EXP 0F3H PROG 89H P. 08AH ATN 0F6H XFER 89H ? (V1.1 ONLY) 088H LOG 0F7H RAM 8AH CALL 08CH DBY 0F8H ROM 88H DIM 08DH XBY 0F9H FPROG 8CH STRING 08EH PI 0FAH-0FFH NOT USED 8DH BAUD 08FH RND 8EH CLOCK 0C0H GET 8FH PH1. 0C1H FREE 90H STOP 0C2H LEN 91H ONTIME 0C3H XTAL 92H ONEX1 0C4H MTOP 93H RETI 0C5H TIME 94H DO 0C6H IE 95H RESTORE 0C7H IP 96H REM 0C8H TIMER0 97H NEXT 0C9H TIMER1 98H ONERR 0CAH TIMER2 99H ON 0C8H T2CON 9AH INPUT 0CCH TCON 98H READ 0CDH TMOD 9CH DATA 0CEH RCAP2 9DH RETURN 0CFH PORT1 9EH IF 0D0H PCON 9FH GOSUB 0D1H ASC( 0A0H FOR 0D2H USING( 0A1H WHILE 0D2H U.( 0A2H UNTIL 0D3H CHR( 0A3H END 0D4H-0DFH NOT USED 0A4H TAB 0E0H ( 0A5H THEN 0E1H ** 0A6H TO 0E2H * 0A7H STEP 0E3H + 0A8H ELSE 0E4H / 0A9H SPC 0E5H - 0AAH CR 0E6H .XOR. 0A8H IDLE 0E7H .AND. 0ACH ST@ (V1.1 ONLY) 0E8H .OR. 0ADH LD@ (V1.1 ONLY) 0E9H - (NEGATE) 0AEH PGM (V1.1 ONLY) 0EAH = 0AFH RROM(V1.1 ONLY) 0EBH >=
Copyright © Madis Kaal 2000-