微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 使用PIC读写1-wire EEPROM DS2430的实例程序

使用PIC读写1-wire EEPROM DS2430的实例程序

时间:08-12 来源:互联网 点击:

movlw H'21'
movwf FSR
movlw H'3c'
movwf INDF ;
;-----------------------------------------------
;--------- read test --------------------------
;-----------------------------------------------
; movlw H'00'
; banksel Addr
; movwf Addr
; call RdDS2430

; movlw H'01'
; banksel Addr
; movwf Addr
; call RdDS2430
;
; movlw H'02'
; banksel Addr
; movwf Addr
; call RdDS2430
;------------------------------------------------
; banksel Offset
; clrf Offset
; pagesel VendorTable
; call VendorTable
; movwf Temp
;
;

movlw H'00'
banksel Addr
movwf Addr
movlw H'34'
banksel TxBuffer
movwf TxBuffer
call WrDS2430

movlw H'01'
banksel Addr
movwf Addr
movlw H'35'
banksel TxBuffer
movwf TxBuffer
call WrDS2430

movlw H'02'
banksel Addr
movwf Addr
movlw H'36'
banksel TxBuffer
movwf TxBuffer
call WrDS2430

;-------- read address 0 --------------------------
movlw H'00'
movwf Addr
call RdDS2430

goto $
;----------------------------------------------
; template to init before write
; to DS2430
;-----------------------------------------------
; movlw H'00'
; movwf Addr
; movlw H'3C'
; movwf TxBuffer

;---------------------------------------------
; write DS2430 one byte
; input
; Addr = starting address to write
; TxB = data to save
; output =
; ErrCode = 0 -> write ok
; = 1 -> write fail
;-----------------------------------------------
WrDS2430
call WrScratchPAD
call CP2EE
return
;------------------------------------------------
; template to init before read
; to DS2430
;-------------------------------------------------
; movlw H'00'
; movwf Addr

;-------------------------------------------------
; 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
;------------------------------------------------------------------------

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top