⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boot51.a51

📁 Free 8051 asm compiler for linux new host platforms: Win32 and Linux macro processing dramatica
💻 A51
📖 第 1 页 / 共 2 页
字号:
        ;the UART and returns the binary value in A.        ;The checksum in R1 is updated accordingly.        ;(In case of error the carry flag is set.)        ;NEXTB changes only registers A, B, R1 and R7.        CALL CONIN      ;read first hex digit        CALL NIBBLE     ;convert it to 4-bit binary        JC NEXTBR       ;stop, if error        SWAP A          ;otherwise move it to high order nibble        MOV R7,A        ;and save it        CALL CONIN      ;read second hex digit        CALL NIBBLE     ;convert it to 4-bit binary        JC NEXTBR       ;stop, if error        ORL A,R7        ;join both nibbles        XCH A,R1        ;add the whole byte        ADD A,R1        ;to the checksum        XCH A,R1        CLR C           ;no errorNEXTBR: RET             ;finished, carry set if errorEIN16:  ;starting from the current line position R0, a 16-bit        ;hex number is read from the command line buffer, and        ;converted to a binary number which is returned in R4/R5.        ;If no error was detected A=0 on return, A<>0 otherwise.        MOV R6,#4       ;up to 4 digits        CALL HEX16      ;convert to binary        JNZ EIN16F      ;error, if garbage        CALL NIXMER     ;check for end of lineEIN16F: RET             ;if garbage, error: A<>0HEX16:  ;starting from the current line position R0, a 16-bit        ;hex number with up to R6 digits is read from the line        ;buffer and converted to a binary number which is        ;returned in R4/R5.        ;If no error was detected A=0 on return, A<>0 otherwise.        MOV A,@R0       ;read character        JZ HEX16F       ;error, if 0        CJNE A,#' ',HEX161        INC R0          ;skip leading blanks        JMP HEX16HEX161: MOV R4,#0       ;R4/R5 = 0        MOV R5,#0        CALL NIBBLE     ;convert hex digit        JC HEX16F       ;error, when failed        CALL SHIFT4     ;shift 4 bits into R4/R5 from the right side        INC R0          ;next character        DEC R6HEX162: MOV A,@R0       ;read character        CALL NIBBLE     ;convert to hex digit        JC HEX16R       ;when failed, finished        CALL SHIFT4     ;shift 4 bits into R4/R5 from the right side        INC R0          ;next character        DJNZ R6,HEX162  ;convert up to 4 hex digitsHEX16R: CLR A           ;o.k., number in R4/R5        RETHEX16F: MOV A,#0FFH     ;conversion error        RETNIBBLE: ;converts the hex digit in A into a 4-bit binary number        ;which is returned in A. When the character is no hex        ;digit, the carry flag is set on return.        ;NIBBLE only changes registers A and B.        CALL UPCASE     ;convert character to upper case        MOV B,A         ;and save it        CLR C           ;is character < 0 ?        SUBB A,#'0'        JC NIBBLR       ;then error        MOV A,#'F'      ;is character > F ?        SUBB A,B        JC NIBBLR       ;then error, too        MOV A,B         ;is character <= 9 ?        SUBB A,#('9'+1)        JC NIBBL1       ;then decimal digit        MOV A,B         ;is character >= A ?        SUBB A,#'A'        JC NIBBLR       ;if not, errorNIBBL1: ADD A,#10       ;calculate binary number        CLR C           ;digit converted correctlyNIBBLR: RETSHIFT4: ;shifts a 4-bit binary number in A into register        ;pair R4/R5 (HI/LO) from the right side.        SWAP A          ;transfer nibble 4 bits to the left        MOV R7,#6       ;Please do not ask for explaining THIS!SHIFT0: RLC A           ;                                 ====        XCH A,R5        RLC A        XCH A,R4        DJNZ R7,SHIFT0        RETUPCASE: ;If the character in A is a lower case letter, it        ;is converted to upper case and returned in A again.        ;Otherwise it will be left unchanged.        ;UPCASE only changes registers A and B.        MOV B,A        CLR C        SUBB A,#'a'     ;is character < a ?        JC UPCRET       ;then leave it unchanged        MOV A,B        SUBB A,#('z'+1) ;is character > z ?        JNC UPCRET      ;then leave it unchanged, too        ADDC A,#'Z'     ;otherwise convert it to upper case        MOV B,AUPCRET: MOV A,B        RETNEWLIN: ;outputs a new line.        MOV A,#CR        CALL CONOUT        MOV A,#LF        CALL CONOUT        RETSTRING: ;String output: start address in DPTR, terminated with 0.        ;STRING only changes registers DPTR and A.        CLR A        MOVC A,@A+DPTR        JZ STRRET        CALL CONOUT        CALL WMSEC      ;Slow down output speed to about 9600 Baud!        INC DPTR        JMP STRINGSTRRET: RETCONOUT: ;output character in A.        JNB TI,CONOUT   ;wait for UART output buffer to become clear        CLR TI        MOV SBUF,A      ;output character        RETCONIN:  ;read character and return it in A.        JNB RI,CONIN        MOV A,SBUF        CLR RI        ANL A,#07FH     ;mask parity (if any)        RETCONOST: ;output status: A=FF if ready, A=0 if not ready        CLR A        JNB TI,OSTRET   ;wait for UART output buffer to become clear        DEC AOSTRET: RETCONIST: ;input status: A=FF if character received, A=0 if not        CLR A        JNB RI,ISTRET   ;no character received        DEC AISTRET: RETWMSEC:  ;about 1 ms delay        PUSH AR6        PUSH AR7        MOV R6,#HIGH(TIMEBASE)        MOV R7,#LOW(TIMEBASE)WMSEC1: DJNZ R7,WMSEC1        DJNZ R6,WMSEC1        POP AR7        POP AR6        RETDELAY:  ;wait for CHARTIME ms!        ;CHARTIME is calculated to last for one byte sent by the UART.        ;DELAY changes registers R6 and R7.        MOV R6,#HIGH(CHARTIME)        MOV R7,#LOW(CHARTIME)DELAY1: CALL WMSEC              ;1 ms        DJNZ R7,DELAY1        DJNZ R6,DELAY1        RET        IFDEF INTEL8051        ;baudrate generator timer 1INITBG: ;start baudrate generator timer 1        MOV  TCON,#0        MOV  TMOD,#020H        MOV  TH1,#RELOAD        ANL  PCON,#07FH        ORL  PCON,#SMOD        SETB TR1        RETSTOPBG: ;stop baudrate generator timer 1        CLR  A        MOV  TCON,A        MOV  TMOD,A        MOV  TH1,A        MOV  TL1,A        ANL  PCON,#07FH        RET        ENDIF        IFDEF INTEL8052        ;baudrate generator timer 2        T2CON   DATA 0C8H        RCAP2L  DATA 0CAH        RCAP2H  DATA 0CBH        TR2     BIT 0CAHINITBG: ;start baudrate generator timer 2        MOV  T2CON,#030H        MOV  RCAP2H,#HIGH(RELOAD)        MOV  RCAP2L,#LOW(RELOAD)        SETB TR2        RETSTOPBG: ;stop baudrate generator timer 2        CLR  A        MOV  T2CON,A        MOV  RCAP2H,A        MOV  RCAP2L,A        RET        ENDIF        IFDEF SAB80535        ;internal 80535 baudrate generator        BD   BIT 0DFHINITBG: ;start internal 80535 baudrate generator        ANL  PCON,#07FH        ORL  PCON,#SMOD        SETB BD        RETSTOPBG: ;stop internal 80535 baudrate generator        CLR  BD        ANL  PCON,#07FH        RET        ENDIF        IFDEF SAB80C515A        ;internal 80C535A baudrate generator        SRELH   DATA 0BAH        SRELL   DATA 0AAH        BD      BIT  0DFHINITBG: ;start internal 80C515A baudrate generator        ANL  PCON,#07FH        ORL  PCON,#SMOD        MOV  SRELH,#HIGH(RELOAD)        MOV  SRELL,#LOW(RELOAD)        SETB BD        RETSTOPBG: ;stop internal 80C515A baudrate generator        CLR  BD        MOV  SRELH,#3        MOV  SRELL,#0D9H        ANL  PCON,#07FH        RET        ENDIF        IFDEF DS80C320        ;Dallas 80C320 timer 1 with clock/12 or clock/4 prescaler        CKCON   DATA 08EHINITBG: ;start 80C320 baudrate generator timer 1        MOV  CKCON,#PRESCALE        MOV  TCON,#0        MOV  TMOD,#020H        MOV  TH1,#RELOAD        ANL  PCON,#07FH        ORL  PCON,#SMOD        SETB TR1        RETSTOPBG: ;stop 80C320 baudrate generator timer 1        CLR  A        MOV  TCON,A        MOV  TMOD,A        MOV  TH1,A        MOV  TL1,A        ANL  PCON,#07FH        MOV  CKCON,#1        RET        ENDIF        END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -