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

📄 tr8086.asm

📁 DALLAS 1 Wire 总线 SDK 支持多种高级语言
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;
;   The following 8086 code demonstrates reading and writing 92's, 93's, 94's
; using universal data packets. The string written to the touch memory is
; defined at offset tmessage at the end of this code.
;
; Program TchWrite                                            { 8/29/92 }
;
         extrn     touchreset: near;
         extrn     touchbyte: near;
         extrn     touchbit: near;
;
CR       EQU       13
LF       EQU       10
;
CODE     segment byte public 'CODE'
         assume    cs:CODE
;
         jmp       start
;
CRC16    dw        1        dup (0)         ; Define CRC16 variable.
PNUM     db        1        dup (0)         ; Page number variable.
CB       db        1        dup (0)         ; Command byte variable.
;
start:
         mov       ax,      cs              ; Get cs in ax.
         mov       ds,      ax              ; Get cs in ds.
         mov       dx,      offset promptem ; Get offset of message in dx.
         mov       ah,      9               ; Function code for print.
         int       21H                      ; Print the string.
main:
         mov       ah,      0BH             ; Function code to look for key.
         int       21H                      ; Look for a key press.
         cmp       al,      0FFH            ; Was a key pressed.
         je        term                     ; If so terminate.
         call      writetm                  ; Try to write data packet.
         or        al,      al              ; Was the write successful?
         jz        main                     ; If not try again.
         call      readtm                   ; Try to read contents.
         or        al,      al              ; Was the read successful?
         jnz       success                  ; If so tell tell the user
         jmp       main                     ;    and terminate. 
success:
         mov       dx,      offset stext    ; Get offset of message in dx.
         mov       ah,      9               ; Function code for print.
         int       21H                      ; Print the string.
term:
         mov       ah,      4CH             ; Function code for termination.
         int       21H                      ; Request termination from DOS.
;
writetm  proc      near
         mov       PNUM,    0               ; Starting page in secure memory.
         mov       CB,      0FH             ; Write scratchpad command.
         call      scrcomm                  ; Send 4 byte command to bus.
         or        al,      al              ; Was there a part out there.
         jnz       contin                   ; Continue if there was.
         jmp       exfail                   ; Abort if there wasn't.
contin:
         mov       ah,      0               ; Initialize cumulative CRC16
         mov       al,      PNUM            ;    variable with the page
         mov       CRC16,   ax              ;       number in the ls byte.
         mov       ax,      strlen          ; Get string length in ax.
         call      docrc16                  ; Calculate CRC16 of length byte.
         push      ax                       ; Push length byte on stack.
         push      cs                       ; Prepare for a far call.
         call      touchbyte                ; Send byte to 1-wire bus.
         mov       bx,      offset tmessage ; bx = pointer to 1st data byte.
         mov       cx,      31              ; 31 bytes left after length sent.
nextbyte:
         mov       al,      [bx]            ; Get data byte in al.
         cmp       al,      0               ; Check for null terminator.
         je        sendcrc                  ; Send CRC16 if finished.
         push      cx                       ; Save byte counter.
         push      bx                       ; Save offset of current data byte.
         call      docrc16                  ; Do cummulative CRC16 calc.
         push      ax                       ; Push data byte on stack.
         push      cs                       ; Prepare for far call.
         call      touchbyte                ; Send data byte to 1-wire bus.
         pop       bx                       ; Restore offset of data byte.
         pop       cx                       ; Restore byte counter.
         inc       bx                       ; Point to next data byte.
         loop      nextbyte                 ; Continue if scratchpad not full.
         mov       CB,     55H              ; Copy scratchpad command byte.
         call      scrcomm                  ; Copy the scratchpad to smem.
         inc       PNUM                     ; Indicate next page for copy.
         mov       CB,     0FH              ; Write scratchpad command.
         call      scrcomm                  ; Send write scratchpad command.
         mov       cx,     32               ; Reset byte counter.
         jmp       nextbyte                 ; Fill scratchpad again.
sendcrc:
         mov       ax,     CRC16            ; Get CRC value in ax.
         xor       ax,     0FFFFH           ; Get ones complement in ax.
         push      ax                       ; Save a copy on the stack.
         push      cx                       ; Save byte counter.
         push      ax                       ; Push copy to send to touchbyte.
         push      cs                       ; Prepare for far call.
         call      touchbyte                ; Send low byte of CRC16.
         pop       cx                       ; Restore byte counter.
         dec       cx                       ; Increment byte counter.
         cmp       cx,     0                ; Have we filled up the scratchpad.
         jne       sncrcb                   ; If not, send next CRC16 byte.
         mov       CB,     055H             ; Copy scratchpad command byte.
         call      scrcomm                  ; Copy the scratchpad.
         inc       PNUM                     ; Indicate next page to copy to.
         mov       CB,     0FH              ; Write scratchpad command byte.
         call      scrcomm                  ; Send write scratchpad command.
         mov       cx,     32               ; Set byte counter.
sncrcb:
         pop       ax                       ; Restore copy of CRC16.
         xchg      al,     ah               ; Get high byte in al.
         push      cx                       ; Save byte counter.
         push      ax                       ; Put it on stack for touchbyte.
         push      cs                       ; Prepare for far call.
         call      touchbyte                ; Send high byte of CRC16.
         pop       cx                       ; Restore byte counter.
         dec       cx                       ; Dec for last byte of CRC16.
         cmp       cx,     0                ; Is the scratchpad full yet?
         jz        dofincp                  ; Do the final copy scratch.
         mov       ax,     32               ; Move ascii space into ax.
morefill:
         push      cx                       ; Save loop counter.
         push      ax                       ; Push byte to send on stack.
         push      cs                       ; Prepare for far call.
         call      touchbyte                ; Send byte to 1-wire bus.
         pop       cx                       ; Restore loop counter.
         loop      morefill                 ; Continue until page filled.
dofincp:
         mov       CB,     055H             ; Copy scratchpad command byte.
         call      scrcomm                  ; Copy into secure memory.
         mov       al,     1                ; Indicate success.
exfail:
         ret                                ; Return to caller.
writetm  endp
;
readtm   proc      near
         mov       bx,     offset RSM       ; Get offset of read smem in bx.
         call      sendcomm                 ; Send command bytes.
         or        al,     al               ; Was there a part out there?
         jz        npd                      ; Abort if not.
         mov       CRC16,  0                ; Initialize CRC for page 0.
         mov       al,     0FFH             ; Prepare to read byte from bus.
         push      ax                       ; Send byte on stack.
         push      cs                       ; Prepare for a far call.
         call      touchbyte                ; Read byte of data from 1-wire. 
         call      docrc16                  ; Calculate cumm. CRC of same.
         cmp       al,     0FFH             ; See if this is extended length. 
         jne       doread                   ; Continue if it isn't.
         push      ax                       ; Send 0FFH on stack to read byte.
         push      cs                       ; Prepare for far call.
         call      touchbyte                ; Read byte of data from 1-wire. 
         call      docrc16                  ; Calculate cummulative CRC. 

⌨️ 快捷键说明

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