;-------------------------------------------------
; read DS2430 one byte
; input
; Addr = starting address to read
; output
; RxB = data to read
;--------------------------------------------------
RdDS2430
call REE2ScratchPAD
call HostRdScratchPAD
return
;;--------- host read scratch pad ----------------------------
;; save desired data into RxB
;;
;;--------------------------------------------------------------
HostRdScratchPAD
call DS2430AInitState
banksel TxB
movlw SkipROM
movwf TxB
call TxBYTE ; SkipROM
movlw RScratch ; read scratch PAD Command
movwf TxB
call TxBYTE
movf Addr,W ; starting address to read
movwf TxB
call TxBYTE
call R2430A ; read desired scratch pad into RxB
call RstPulse
return
;-------------- write memory scratch scratch pad ------------------------
; write one byte into scratch PAD
; input
; Addr = starting address to write
; TxBuffer = data to save
; output
; ErrCode = 0 -> write ok
; = 1 -> write fail
;---------------------------------------------------------------------------
WrScratchPAD
call DS2430AInitState
movlw SkipROM ; 0xCC
movwf TxB
call TxBYTE ; SkipROM
movlw WScratch ; write memory scratch pad, 0x0f
movwf TxB
call TxBYTE
movf Addr,W ; starting address of memory scratch pad
movwf TxB ; TxBYTE use TxB
call TxBYTE
movf TxBuffer,W ;
movwf TxB
call TxBYTE
call RstPulse ; reset pulse
call delay500us ; wait presence pulse
return
;---------- CP2EE ---copy whole scratch pad to EE ----------------------
; write memory scratch
; verify memory scratch
; copy memory scratch to EE
;----------------------------------------------------------------------
CP2EE
call DS2430AInitState ; 0x55 + 0xa5 + hi 10ms // [ScratchPad -> EEPROM ]
banksel TxB
movlw SkipROM
movwf TxB
call TxBYTE ; SkipROM
movlw CPScratch ; 0x55
movwf TxB
call TxBYTE
movlw H'a5'
movwf TxB
call TxBYTE
call ForceHi ; min 10ms refter to datasheet
return
;--------- REE2ScratchPAD --- copy whole EE to ScrathPAD ----------------
; copy EE to whole memory scatch
; read memory scratch
;format I: 0xf0 + Addr +R +R + reset pulse, copy byte by byte
;format II: 0xf0 + Addr + reset pulse, copy whole
;------------------------------------------------------------------------
REE2ScratchPAD
call DS2430AInitState
banksel TxB
movlw SkipROM
movwf TxB
call TxBYTE ; SkipROM
movlw REEROM ;; Read from EE into ScratchPAD
movwf TxB
call TxBYTE ;;
call RstPulse ;; copy all
return
;----------R2430A ---- Host read the scratch PAD ------------------------
; Read 2430A Scratch PAD
; LSB first
; save the result in RxB
;------------------------------------------------------------------------
R2430A ; returns byte in RxB
movlw .8
movwf LoopCounter
clrf RxB
RLoop
call SetLo ;
nop
call SetHi ; it will pull up by resistor
nop ; delay to sample reliable bit
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
banksel PORTB
movf PORTB,W
movwf Temp
btfss Temp,Bit2
goto gLo
bsf CARRY
goto rol
gLo
bcf CARRY
rol
banksel RxB
rrf RxB,F
call delay60us ; tdrv + trelease
banksel LoopCounter
decfsz LoopCounter,F
goto RLoop
movf RxB,W ; save the result in W
return
;----------------------------------------------------------
; strong pull up
;
;----------------------------------------------------------
ForceHi
bsf PBDir,Bit2
movf PBDir,W ;; input
banksel TRISB
movwf TRISB ;; set input, pull by external resistor
call delay100ms
bcf PBDir,Bit2 ;; output
movf PBDir,W
movwf TRISB
return
本文关键字:暂无联系方式源码-程序,单片机-工控设备 - 源码-程序