Version 1.1 of MCS BASIC-52 contains numerous RESET options that were not available in Version 1.0. They are discussed in detail in chapters 3.2 through 3.5 of this manual. Briefly, they are as follows:
Saves only the serial port baud rate for a power-up or RESET condition.
Saves the serial port baud rate and automatically runs the first program that is saved in EPROM on a power-up or RESET condition.
Saves the serial port baud rate plus the assigned MTOP value. If RAM is available beyond the assigned MTOP value, it will not be cleared during a power-up or RESET condition.
Saves the serial port baud rate plus the assigned MTOP value, just like PROG3, but also automatically runs the first program that is saved in EPROM on a power-up or RESET condition.
Does the same thing as PROG4, however, if external memory location 5FH contains the character 0A5H on a power-up or RESET condition, external memory will not be cleared. This mode assumes that the user has employed some type of memory back-up.
Does the same thing as PROG5, but CALLS external program memory location 4039H during a RESET or power-up sequence. This option also requires the user to put the character 0A5H in external memory location 5FH to insure that external RAM will not be cleared during RESET or power-up. The user must put an assembly language RESET routine in external memory location 4039H or else this RESET mode will crash. When the user returns from the customized assembly language RESET routine, three options exist:
OPTION 1 FOR PROG6
If the CARRY BIT is CLEARED (CARRY = 0) upon return from the user RESET routine MCS BASIC- 52 will enter the auto-baud rate determining routine. The user must then type a space character (20H) on the terminal to compiete the RESET routine and produce a RESET message on the terminal.
OPTION 2 FOR PROG6
If the CARRY BIT is SET (CARRY = 1) and BIT 0 of the ACCUMULATOR is CLEARED (ACC. 0 = 0) MCS BASIC-52 will produce the standard sign-on message upon return from the user supplied RESET routine. The baud rate will be the one that was saved when the PROG6 option was used.
OPTION 3 FOR PROG6
If the CARRY BIT is SET (CARRY = 1) and BIT 0 of the ACCUMULATOR is SET (ACC. 0 = 1), MCS BASIC-52 will execute the first program stored by the user in EPROM (starting address of the program is 8010H) upon return from the user supplied RESET routine.
If these options are still not sufficient to address the needs of a specific application, one other option exists and it functions as follows:
After RESET, MCS BASIC-52 initializes the SPECIAL FUNCTION REGISTERS SCON, TMOD, TCON, and T2CON with the following respective values, 5AH, 10H, 54H, and 34H. If the user places the character 0AAH in external CODE MEMORY location 2001H (remember CODE MEMORY is enabled by /PSEN), MCS BASIC-52 will CALL external CODE MEMORY location 2090H immediately after these special function registers are initialized. No other registers or memory locations will be altered except that the ACCUMULATOR will contain a 0AAH and the DPTR will contain a 2001H.
Since MCS BASIC-52 does not write to the above mentioned Special Function Registers at any time except during the RESET or power-up sequence the user has the option of modifying any of the Special Function Registers with this RESET option. Upon returning from this RESET mode, the MCS BASIC-52 software package will clear the internal memory of the 8052AH and proceed with the RESET routine. The PROG1 through PROG6 options will function as usual.
Now, suppose the user does not want to enter the normal RESET routines, or the user wants to implement some type of "warm" start-up routine. This can be accomplished simple by initializing the necessary Special Function Registers and then jumping back into either MCS BASIC-52's COMMAND mode or RUN MODE. For a warm start-up or RESET (warm means that the MCS BASIC-52 device was RESET, but power was not removed--i.e. the user hit the RESET button) the following must be initialized:
SCON, TMOD, TCON, T2CON, if the user does not want to use the values that MCS BASIC-52 supplies.
RCAP2H and RCAP2L must be loaded with the proper baud rate values. If the user has programmed an EPROM with one of the PROG1 through PROG6 options, the proper baud rate value will be stored in external DATA MEMORY locations 8001H (RCAP2H) and 8002H (RCAP2L).
The STACK POINTER (Special Function Reglster SP) must be initialized with the contents of the STACK POINTER SAVE location, which is in internal DATA MEMORY location 3EH. A MOV SP, 3EH assembly language instruction will accomplish the STACK POINTER initialization.
After the above are initialized by the user supplied RESET routine, the user may enter MCS BASIC-52's command mode by executing the following:
CLR A LJMP 30H
Now, it is important to remember that the previous description applies only to a "warm" RESET with power remaining to the MCS BASIC-52 system. This means that the user must also provide some way of detecting the difference between a warm RESET and a power-on RESET. This usually involves some type of flip-flop getting set with a power-on-clear signal from the users power supply. The details of imple- mentating this RESET detection mechanism will not be discussed here as the possible hardware options vary depending upon the design.
The user may also implement a "cold start" reset option with the previously described reset mode. The following code details what is necessary to implement a cold start option.
ORG 2001H ; DB 0AAH ; TELL BASIC THAT RESET IS EXTERNAL ; ORG 2090H ; LOCATION BASIC WILL CALL FOR RESET ; ; AT THIS POINT BASIC HAS PLACED A 5AH IN ; SCON, A 10H IN TMOD, A 54H IN TCON AND ; A 34H IN T2CON ; ; FIRST CLEAR THE INTERNAL MEMORY MOV R0,#0FFH ; LOAD R0 WITH THE TOP OF INTERNAL MEMORY CLR A ; SET ACCUMULATOR = 0 RESET1: MOV @R0.A ; LOOP UNTIL ALL THE INTERNAL RAM IS CLEARED DJNZ R0.RESET1 ; ; NOW SET UP THE STACK POINTER AND THE STACK ; POINTER HOLDING REGISTER MOV SP,#4DH ; 4DH IS THE INITIALIZED VALUE OF THE STACK MOV 3EH,#4DH ; THIS IS THE SP HOLDING REGISTER ; NOW CLEAR THE EXTERNAL RAM, IN THIS ; EXAMPLE ASSUME THAT 1FFFH BYTES OF RAM ; ARE AVAILABLE ; THE USER MUST CLEAR AT LEAST THE FIRST 512 ; BYTES OF RAM FOR A COLD START RESET ; MOV R3,#HIGH 1FFFH MOV R1,#LOW 1FFFH MOV DPTR,#0FFFFH
RESET2: INC DPTR ; DPTR = 0 THE FIRST TIME THRU CLR A MOVX @DPTR,A ; CLEAR THE RAM. A MEMORY TEST PROGRAM COULD ; BE IN THIS LOOP MOV A,R3 ; NOW TEST FOR THE MEMORY LIMITS CJNE A,DPH-RESET2 MOV A,R1 CJNE A,DPL.RESET2 ; ; WHEN YOU GET HERE, YOU ARE DONE ; ; NOW SET UP THE MEMORY POINTERS- FIRST MTOP ; MOV DPTR.#10AH ; LOCATION OF MTOP IN EXTERNAL RAM MOV A,#HIGH 1FFFH ; SAVE MTOP MOVX @DPTR,A INC DPTR ; NOW, SAVE THE LOW BYTE MOV A,#LOW 1FFFH MOVX @DPTR,A ; ; NOW SET UP THE VARTOP POINTER, WITH NO STRINGS. ; VARTOP = MEMTOP ; MOV DPTR,#104H ; LOCATION OF VARTOP IN EXTERNAL RAM MOV A,#HIGH 1FFFH MOVX @DPTR,A INC DPTR MOV A,#LOW 1FFFH MOVX @DPTR,A ; ; ; NOW SAVE THE MATRIX POINTER "DIMUSE". THIS POINTER IS ; DESCRIBED IN THE APPENDIX, WITH NO PROGRAM IN RAM. ; DIMUSE = 525 AFTER RESET ; MOV DPTR,#108H ; LOCATION OF DIMUSE IN EXTERNAL RAM MOV A,#HIGH 528 MOVX @DPTR,A INC DPTR MOV A,#LOW 528 MOVX @DPTR,A ; ; NOW SAVE THE VARIABLE POINTER "VARUSE" THIS POINTER IS ; ALSO DESCRIBED IN THE APPENDIX. AFTER RESET VARUSE = VARTOP ; MOV DPTR,#106H ; LOCATION OF VARUSE IN EXTERNAL RAM MOV A,#HIGH 1FFFH MOVX @DPTR,A INC DPTR MOV A,#LOW 1FFFH MOVX @DPTR,A ; ; NOW SETUP BASICS CONTROL STACK AND ARGUMENT STACK ; MOV 9H,#0FEH ; THIS INITIALIZES THE ARGUMENT STACK MOV 11H,#0FEH ; THIS INITIALIZES THE CONTROL STACK ; ; NOW TELL BASIC THAT NO PROGRAM IS IN RAM. THIS IS NOT NEEDED ; IF THE USER HAS A PROGRAM IN RAM ; MOV DPTR,#512 ; LOCATION OF THE START OF A USER PROGRAM MOV A,#01H ; END OF FILE CHARACTER MOVX @DPTR,A
; NOW PUSH THE CRYSTAL VALUE ON TO THE STACK AND LET BASIC ; CALCULATE ALL CRYSTAL DEPENDENT PARAMETERS ; SJMP RESET3 ; XTAL: DB 88H ; THIS IS THE FLOATING POINT VALUE DB 00H ; FOR AN 11.0592 MHZ CRYSTAL DB 00H DB 92H DB 05H DB 11H ; RESET3: MOV DPTR,#XTAL ; SET UP TO PUSH CRYSTAL VALUE MOV A,9 ; GET THE ARG STACK CLR C SUBB A,#6 ; DECREMENT ARG STACK BY ONE FP NUMBER Mov 9,A MOV R0,A ; SAVE THE CALCULATED ADDRESS IN R0 MOV P2,#1 ; THIS IS THE ARG STACK PAGE ADDRESS MOV R1,#6 ; NUMBER OF BYTES TO TRANSFER ; RESET4: CLR A ; TRANSFER ROM CRYSTAL VALUE TO THE MOVC A,@A+DPTR ; ARGUMENT STACK OF BASIC MOVX @R0,A INC DPTR ; BUMP THE POINTERS DEC R0 DJNZ R1,RESET4 ; LOOP UNTIL THE TRANSFER IS COMPLETE ; ; NOW CALL BASIC TO DO ALL THE CRYSTAL CACULATIONS ; MOV A,#58 ; OPBYTE FOR CRYSTAL CALCULATION LCALL 30H ; DO THE CALCULATION ; ; NOW TELL BASIC WHERE START OF THE USER BASIC PROGRAM IS ; BY LOADING THE START ADDRESS. IF THE PROGRAM IS IN EPROM ; 13H WOULD = HIGH 8011H AND 14H = LOW 8011H. ANYWAY ; ADDRESS 13H:14H MUST POINT TO THE START OF THE BASIC ; PROGRAM ; MOV 13H,#HIGH 512 ; THIS TELLS BASIC THAT THE START OF MOV 14H.#LOW 51Z ; THE PROGRAM IS IN LOCATION 512 ; ; NOW THE SERIAL PORT MUST BE INITIALIZED. THE USER ; CAN SET UP THE SERIAL PORT TO ANY DESIRED CONFIGURATION ; HOWEVER, THIS DEMO CODE WILL SHOW THE AUTO BAUD ; ROUTINE MOV R3,#00H ; INITIALIZE THE AUTO BAUD COUNTERS MOV R1,#00H MOV R0,#04H JB RXD,$ ; LOOP UNTIL A START BIT IS RECEIVED ;
; RESET5: DJNZ R0,$ ; WASTE 8 CLOCKS INITIALLY. SIX CLOCKS ; IN THE LOOP (16) TOTAL CLR C ; 1 CLOCK (1) MOV A,R1 ; 1 CLOCK (2) SUBB A,#1 ; 1 CLOCK (3) MOV R1,A ; 1 CLOCK (4) MOV A,R3 ; 1 CLOCK (5) SUBB A,#00H ; 1 CLOCK -- R3:R1 = R3:R1 - 1 (6) MOV R3,A ; 1 CLOCK (7) MOV R0,#3 ; 1 CLOCK (8) JNB RXD,RESET5 ; 2 CLOCKS (10), WAIT FOR END OF SPACE JB RXD,$ ; WAIT FOR THE SPACE TO END (20H) JNB RXD,$ ; WAIT FOR THE STOP BIT MOV RCAP2H.R3 ; LOAD THE TIMER 2 HOLDING REGISTERS MOV RCAP2L.R1 ; ; NOW YOU CAN ADD A CUSTOM SIGN ON MESSAGE ; MOV R3,#HIHH MSG ; PUT ADDRESS OF MESSAGE lN R3:R1 MOV R1,#LOW MSG SETB 52 ; PRINT FROM ROM MOV A,#6 ; OP BYTE TO PRINT TEXT STRING LCALL 30H ; ; NOW OUTPUT A CR LF ; MOV A,#7 ; OP 8YTE FOR CRLF LCALL 30H ; ; G0 TO THE COMMAND MODE ; CLR A JMP 30H ; MSG: DB 'CUSTOM SIGN ON MESSAGE' DB 22H ; TERMINATES MESSAGE ; END
To Summarize what the user must do to successfully implement a "COLD START" RESET:
1) The user must clear the internal RAM of the MCS BASIC-52 device and at least the first 512 bytes of external RAM memory.
2) The user must initialize the stack pointer (special function register--SP) and the stack pointer holding register (internal RAM location 3EH) with a value that is between 4DH and 0E0H. 4DH gives MCS BASIC-52 the maximum stack size.
3) The user must initialize the following pointers in external RAM. MTOP at location 10AH (high byte) and 10BH (low byte). VARTOP at locations 104H (high byte) and 105H (low byte). DIMUSE at locations 108H (high byte) and 109H (low byte). VARUSE at locations 106H (high byte) and 107H (low byte). Details of what needs to be in these locations are presented in appendix 1.7 of this manual.
4) The Control stack pointer (location 11H in internal memory) and the Argument stack pointer (location 09H in internal memory) must also be initialized with the value 0FEH. If the user is not going to assign the XTAL (crystal) value in BASIC, then the XTAL value must be pushed onto the argument stack and the user must Do an OPBYTE 58 call to MCS BASIC-52.
5) The User must also initialize the start address of a program. The start address is in locations 13H (high byte) and 14H (low byte) of internal data memory. If the user BASIC program is in RAM, then 13H: 14H = 512, if the user program is the the first program in EPROM, then 13H: 14H = 8011H.
6) The user must finally initialize the serial port. Any scheme can be used (as long as it works!!)
The added reset options should go a long way toward making MCS BASIC-52 configurable to any custom application.
Copyright © Madis Kaal 2000-