使用PIC读写1-wire EEPROM DS2430的实例程序
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
;------------------------------------------------------------------------
DS2430 实例 程序 EEPROM 1-wire PIC 读写 使用 相关文章:
- 使用PIC读写1-wire EEPROM DS2430的实例(05-17)
- 国外现场总线应用实例两则(12-21)
- 三菱PLC编程技巧及实例图解(12-19)
- 单片机的七个创意设计实例(从易到难),附电路图、源代码、演示视频(06-11)
- PCI驱动程序开发实例(02-21)
- 51单片机做信号发生器实例编程(01-16)